Skip to content

Commit 476e1ba

Browse files
authored
Merge pull request #43963 from FroMage/42064
Use original query case for fast count queries
2 parents 5e4a69e + 9257b63 commit 476e1ba

File tree

2 files changed

+6
-3
lines changed
  • extensions/panache/panache-hibernate-common/runtime/src

2 files changed

+6
-3
lines changed

extensions/panache/panache-hibernate-common/runtime/src/main/java/io/quarkus/panache/hibernate/common/runtime/PanacheJpaUtil.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ public static String getFastCountQuery(String query) {
5252
Matcher selectMatcher = SELECT_PATTERN.matcher(query);
5353
if (selectMatcher.matches()) {
5454
// this one cannot be null
55-
String firstSelection = selectMatcher.group(1).trim().toLowerCase(Locale.ROOT);
56-
if (firstSelection.startsWith("distinct")) {
55+
String firstSelection = selectMatcher.group(1).trim();
56+
String firstSelectionForMatching = firstSelection.toLowerCase(Locale.ROOT);
57+
if (firstSelectionForMatching.startsWith("distinct")) {
5758
// if firstSelection matched distinct only, we have something wrong in our selection list, probably functions/parens
5859
// so bail out
59-
if (firstSelection.length() == 8) {
60+
if (firstSelectionForMatching.length() == 8) {
6061
return getCountQueryUsingParser(query);
6162
}
6263
// this one can be null

extensions/panache/panache-hibernate-common/runtime/src/test/java/io/quarkus/panache/hibernate/common/runtime/CountTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public void testFastVersion() {
4747
assertFastCountQuery("SELECT COUNT(*) from bar", "select foo,gee from bar");
4848
// one column distinct
4949
assertFastCountQuery("SELECT COUNT(distinct foo) from bar", "select distinct foo from bar");
50+
// with case preserved
51+
assertFastCountQuery("SELECT COUNT(distinct fOO) from bar", "select distinct fOO from bar");
5052
// two columns distinct
5153
Assertions.assertThrows(RuntimeException.class, () -> assertFastCountQuery("XX", "select distinct foo,gee from bar"));
5254
// nested order by not touched

0 commit comments

Comments
 (0)