Skip to content

Commit 3fd4662

Browse files
alismanclaude
andcommitted
Optimize ClinicalAttributeMapper sample ID queries for ClickHouse JDBC performance (#11703)
Apply ArrayTypeHandler optimization strategy to whereSample include, following the same approach used in PatientMapper (commit 2e2ec22). This significantly improves performance with ClickHouse JDBC connections by reducing parameter overhead. Changes: - Replace foreach loops in whereSample with ArrayTypeHandler for both single-study and multi-study queries - Use SqlUtils.combineStudyAndPatientIds() for multi-study scenarios with CONCAT-based unique key matching - Optimize getClinicalAttributeCountsBySampleIds query performance through updated whereSample include This reduces prepared statement parameters from potentially thousands to single array parameters, maintaining security through proper parameter binding. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent c284181 commit 3fd4662

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/resources/org/cbioportal/legacy/persistence/mybatis/ClinicalAttributeMapper.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@
3737
<if test="sampleIds != null">
3838
<if test="@java.util.Arrays@stream(studyIds.toArray()).distinct().count() == 1">
3939
cancer_study.cancer_study_identifier = #{studyIds[0]} AND
40-
sample.stable_id IN
41-
<foreach item="item" collection="sampleIds" open="(" separator="," close=")">#{item}</foreach>
40+
sample.stable_id IN (
41+
#{sampleIds, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
42+
)
4243
</if>
4344
<if test="@java.util.Arrays@stream(studyIds.toArray()).distinct().count() > 1">
44-
(cancer_study.cancer_study_identifier, sample.stable_id) IN
45-
<foreach index="i" collection="sampleIds" open="(" separator="," close=")">(#{studyIds[${i}]},#{sampleIds[${i}]})</foreach>
45+
<bind name="sampleUniqueKeys" value="@org.cbioportal.legacy.persistence.mybatis.util.SqlUtils@combineStudyAndPatientIds(studyIds, sampleIds)" />
46+
CONCAT(cancer_study.cancer_study_identifier, ':', sample.stable_id) IN (
47+
#{sampleUniqueKeys, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
48+
)
4649
</if>
4750
</if>
4851
</where>

0 commit comments

Comments
 (0)