Skip to content

Commit 58a3f01

Browse files
tttomat19schauder
authored andcommitted
Fix performance bug with large number of unnamed parameters
On some occasions where col in (:args) contain a really lot args, 10k+ for instance, this commit fixes a performance (high CPU) bug by NOT traversing the whole map in basically O(n^2) manner Signed-off-by: Mikhail Fedorov <[email protected]> Squashed by Jens Schauder Original pull request #2050
1 parent 520d6a7 commit 58a3f01

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
* @author Mark Paluch
5454
* @author Jens Schauder
5555
* @author Yan Qiang
56+
* @author Mikhail Fedorov
5657
* @since 3.0
5758
*/
5859
public class QueryMapper {
@@ -632,7 +633,7 @@ private static String getUniqueName(MapSqlParameterSource parameterSource, Strin
632633
return name;
633634
}
634635

635-
int counter = 1;
636+
int counter = values.size();
636637
String uniqueName;
637638

638639
do {

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/QueryMapperUnitTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
*
4747
* @author Mark Paluch
4848
* @author Jens Schauder
49+
* @author Mikhail Fedorov
4950
*/
5051
public class QueryMapperUnitTests {
5152

@@ -121,7 +122,7 @@ public void shouldMapNestedGroup() {
121122
Condition condition = map(criteria);
122123

123124
assertThat(condition).hasToString(
124-
"(person.\"NAME\" = ?[:name]) AND (person.\"NAME\" = ?[:name1] OR person.age < ?[:age] OR (person.\"NAME\" != ?[:name2] AND person.age > ?[:age1]))");
125+
"(person.\"NAME\" = ?[:name]) AND (person.\"NAME\" = ?[:name1] OR person.age < ?[:age] OR (person.\"NAME\" != ?[:name3] AND person.age > ?[:age4]))");
125126
}
126127

127128
@Test // DATAJDBC-318

0 commit comments

Comments
 (0)