diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4424-improve-query-count-accuracy.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4424-improve-query-count-accuracy.yaml new file mode 100644 index 00000000000..a148dd98b1f --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4424-improve-query-count-accuracy.yaml @@ -0,0 +1,6 @@ +--- +type: change +issue: 4424 +title: "The `CircularQueueCaptureQueriesListener` countXXXXQueries() methods have been reworked to improve accuracy. + Query totals previously counted two SQL statement executions with the same SQL but different parameters as one + query, this will now be counted as two queries." diff --git a/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/util/BaseCaptureQueriesListener.java b/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/util/BaseCaptureQueriesListener.java index 1f9e48b15f8..8798db74605 100644 --- a/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/util/BaseCaptureQueriesListener.java +++ b/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/util/BaseCaptureQueriesListener.java @@ -60,10 +60,23 @@ public abstract class BaseCaptureQueriesListener implements ProxyDataSourceBuild return; } + /* + * Note on how this works: + * + * Hibernate batches queries where the SQL is identical other than parameter values. + * + * So for example, if we call "select PID from SOMETABLE where NAME = ?" twice with + * two different name values, this method will be called only once with 2 parameter + * lists. In this case, we say size=2 and we capture the first parameters in case + * we want to log them. We don't capture subsequent parameters currently because + * this is only used for troubleshooting logging anyhow so the values are used + * only as a representative example only. + */ + for (QueryInfo next : theQueryInfoList) { String sql = trim(next.getQuery()); List params; - int size = 0; + int size; if (next.getParametersList().size() > 0 && next.getParametersList().get(0).size() > 0) { size = next.getParametersList().size(); List values = next @@ -75,6 +88,7 @@ public abstract class BaseCaptureQueriesListener implements ProxyDataSourceBuild .collect(Collectors.toList()); } else { params = Collections.emptyList(); + size = next.getParametersList().size(); } StackTraceElement[] stackTraceElements = null; diff --git a/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/util/CircularQueueCaptureQueriesListener.java b/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/util/CircularQueueCaptureQueriesListener.java index 64fee33bed4..bc558009870 100644 --- a/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/util/CircularQueueCaptureQueriesListener.java +++ b/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/util/CircularQueueCaptureQueriesListener.java @@ -326,10 +326,7 @@ public class CircularQueueCaptureQueriesListener extends BaseCaptureQueriesListe .collect(Collectors.toList()); ourLog.info("Insert Queries:\n{}", String.join("\n", queries)); - return insertQueries - .stream() - .map(t -> t.getSize()) - .reduce(0, Integer::sum); + return countQueries(insertQueries); } /** @@ -343,10 +340,7 @@ public class CircularQueueCaptureQueriesListener extends BaseCaptureQueriesListe .collect(Collectors.toList()); ourLog.info("Update Queries:\n{}", String.join("\n", queries)); - return updateQueries - .stream() - .map(t -> t.getSize()) - .reduce(0, Integer::sum); + return countQueries(updateQueries); } /** @@ -374,56 +368,47 @@ public class CircularQueueCaptureQueriesListener extends BaseCaptureQueriesListe .collect(Collectors.toList()); ourLog.info("Delete Queries:\n{}", String.join("\n", queries)); - return deleteQueries - .stream() - .map(t -> t.getSize()) - .reduce(0, Integer::sum); + return countQueries(deleteQueries); } public int countSelectQueries() { - return getSelectQueries().size(); + return countQueries(getSelectQueries()); } public int countInsertQueries() { - return getInsertQueries() - .stream() - .map(t -> t.getSize()) - .reduce(0, Integer::sum); + return countQueries(getInsertQueries()); } public int countUpdateQueries() { - return getUpdateQueries() - .stream() - .map(t -> t.getSize()) - .reduce(0, Integer::sum); + return countQueries(getUpdateQueries()); } public int countDeleteQueries() { - return getDeleteQueries() - .stream() - .map(SqlQuery::getSize) - .reduce(0, Integer::sum); + return countQueries(getDeleteQueries()); } public int countSelectQueriesForCurrentThread() { - return getSelectQueriesForCurrentThread().size(); + return countQueries(getSelectQueriesForCurrentThread()); } - // TODO: JA2 The count "forCurrentThread" methods work differently than the non - // current thread ones - The other ones aggregate multiple instances of the same - // query - In other words if the same query is issued twice with different parameters - // that counts for 2 on the other method but 1 for this one. Need to harmonize this, - // and should do it on this method since the higher number is more accurate. public int countInsertQueriesForCurrentThread() { - return getInsertQueriesForCurrentThread().size(); + return countQueries(getInsertQueriesForCurrentThread()); } public int countUpdateQueriesForCurrentThread() { - return getUpdateQueriesForCurrentThread().size(); + return countQueries(getUpdateQueriesForCurrentThread()); } public int countDeleteQueriesForCurrentThread() { - return getDeleteQueriesForCurrentThread().size(); + return countQueries(getDeleteQueriesForCurrentThread()); + } + + @Nonnull + private static Integer countQueries(List theQueries) { + return theQueries + .stream() + .map(t -> t.getSize()) + .reduce(0, Integer::sum); } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QueryCountTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QueryCountTest.java index 76b741b1885..4f010b1380d 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QueryCountTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QueryCountTest.java @@ -589,8 +589,9 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // select: lookup forced ID assertEquals(1, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); - // insert to: HFJ_RESOURCE, HFJ_RES_VER, HFJ_RES_LINK - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + // insert to: HFJ_RESOURCE, HFJ_RES_VER, HFJ_RES_LINK (subject/patient) + myCaptureQueriesListener.logInsertQueries(); + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); /* @@ -604,8 +605,8 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // select: lookup forced ID assertEquals(1, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); - // insert to: HFJ_RESOURCE, HFJ_RES_VER, HFJ_RES_LINK - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + // insert to: HFJ_RESOURCE, HFJ_RES_VER, HFJ_RES_LINK (subject/patient) + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); } @@ -637,7 +638,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test assertNoPartitionSelectors(); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); // insert to: HFJ_RESOURCE, HFJ_RES_VER, HFJ_RES_LINK - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); /* @@ -652,7 +653,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test assertEquals(0, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); // insert to: HFJ_RESOURCE, HFJ_RES_VER, HFJ_RES_LINK - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); } @@ -1917,7 +1918,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(1, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); myCaptureQueriesListener.logInsertQueriesForCurrentThread(); - assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(7, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2021,9 +2022,9 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(0, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); myCaptureQueriesListener.logInsertQueriesForCurrentThread(); - assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(17, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); - assertEquals(1, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(2, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); } @@ -2076,7 +2077,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // Lookup the two existing IDs to make sure they are legit myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(2, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2114,7 +2115,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // Lookup the two existing IDs to make sure they are legit myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(2, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2165,7 +2166,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test myCaptureQueriesListener.logInsertQueriesForCurrentThread(); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); assertEquals(2, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2203,7 +2204,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // Lookup the two existing IDs to make sure they are legit myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(2, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2256,7 +2257,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // Lookup the two existing IDs to make sure they are legit myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(2, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2293,7 +2294,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // We do not need to resolve the target IDs a second time assertEquals(0, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2344,7 +2345,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // Lookup the two existing IDs to make sure they are legit myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(0, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2382,7 +2383,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // We do not need to resolve the target IDs a second time myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(0, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2457,8 +2458,8 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // Lookup the two existing IDs to make sure they are legit myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(6, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); - assertEquals(1, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(2, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); // Do the same a second time @@ -2516,8 +2517,8 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test // Lookup the two existing IDs to make sure they are legit myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(4, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); - assertEquals(1, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(2, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); } @@ -2547,7 +2548,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test mySystemDao.transaction(mySrd, input); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(3, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(8, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(48, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2571,7 +2572,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test mySystemDao.transaction(mySrd, input); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(0, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(5, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(45, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2750,7 +2751,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test myCaptureQueriesListener.clear(); mySystemDao.transaction(new SystemRequestDetails(), supplier.get()); assertEquals(2, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(9, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(28, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(1, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2758,8 +2759,8 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test mySystemDao.transaction(new SystemRequestDetails(), supplier.get()); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(8, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(2, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(7, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); } @@ -2791,7 +2792,7 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test mySystemDao.transaction(new SystemRequestDetails(), loadResourceFromClasspath(Bundle.class, "r4/transaction-perf-bundle.json")); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(2, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(10, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(123, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); assertEquals(1, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -2801,8 +2802,8 @@ public class FhirResourceDaoR4QueryCountTest extends BaseResourceProviderR4Test mySystemDao.transaction(new SystemRequestDetails(), loadResourceFromClasspath(Bundle.class, "r4/transaction-perf-bundle-smallchanges.json")); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(8, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(1, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(2, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(6, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java index 2b92c2707d7..582af58145a 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java @@ -1125,7 +1125,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { ourLog.info("** Done performing write"); - assertEquals(6, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(26, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); /* @@ -1145,7 +1145,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { ourLog.info("** Done performing write 2"); assertEquals(1, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); - assertEquals(2, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(3, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); } @@ -1177,7 +1177,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { assertEquals(0, myCaptureQueriesListener.countDeleteQueries()); assertEquals(4, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(51, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(1, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -1279,7 +1279,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { myPatientDao.update(pt); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); - assertEquals(2, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); } @@ -1309,7 +1309,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); assertEquals(1, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); // Add an entry to HFJ_RES_VER - assertEquals(2, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); // Update SPIDX_STRING and HFJ_RESOURCE + assertEquals(4, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); // Update SPIDX_STRING and HFJ_RESOURCE assertEquals(0, myPatientDao.search(m1).size().intValue()); assertEquals(1, myPatientDao.search(m2).size().intValue()); @@ -1330,7 +1330,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { assertEquals(0, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); - assertEquals(3, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(1, myPatientDao.search(m1).size().intValue()); assertEquals(0, myPatientDao.search(m2).size().intValue()); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchSqlTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchSqlTest.java index 619642b02e4..55e282ebf17 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchSqlTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchSqlTest.java @@ -28,8 +28,10 @@ public class FhirResourceDaoR4SearchSqlTest extends BaseJpaR4Test { private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoR4SearchSqlTest.class); + @Override @BeforeEach - public void before() { + public void before() throws Exception { + super.before(); myDaoConfig.setAdvancedHSearchIndexing(false); } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/JpaHistoryR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/JpaHistoryR4Test.java index ed6ce57053b..ea605ea5d46 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/JpaHistoryR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/JpaHistoryR4Test.java @@ -207,8 +207,8 @@ public class JpaHistoryR4Test extends BaseJpaR4SystemTest { assertEquals(0, myCaptureQueriesListener.countDeleteQueries()); assertEquals(0, myCaptureQueriesListener.countInsertQueries()); assertEquals(0, myCaptureQueriesListener.countUpdateQueries()); - assertEquals(2, myCaptureQueriesListener.countSelectQueries()); myCaptureQueriesListener.logSelectQueries(false, false); + assertEquals(2, myCaptureQueriesListener.countSelectQueries()); assertThat(myCaptureQueriesListener.getSelectQueries().get(0).getSql(false, false).toLowerCase(Locale.ROOT), startsWith("select count")); assertThat(myCaptureQueriesListener.getSelectQueries().get(1).getSql(false, false).toLowerCase(Locale.ROOT), containsString(" from hfj_res_ver ")); runInTransaction(() -> assertEquals(0, mySearchEntityDao.count())); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/PartitioningSqlR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/PartitioningSqlR4Test.java index 0e8920d0beb..0b2a06c1ed5 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/PartitioningSqlR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/PartitioningSqlR4Test.java @@ -2765,9 +2765,9 @@ public class PartitioningSqlR4Test extends BasePartitioningR4Test { assertEquals(1, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); assertThat(myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(0).getSql(true, false), containsString("resourcein0_.HASH_SYS_AND_VALUE='-4132452001562191669' and (resourcein0_.PARTITION_ID in ('1'))")); myCaptureQueriesListener.logInsertQueriesForCurrentThread(); - assertEquals(6, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(40, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); - assertEquals(1, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(4, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); /* @@ -2780,9 +2780,9 @@ public class PartitioningSqlR4Test extends BasePartitioningR4Test { myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(8, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); myCaptureQueriesListener.logInsertQueriesForCurrentThread(); - assertEquals(1, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); - assertEquals(2, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(8, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); /* @@ -2797,9 +2797,9 @@ public class PartitioningSqlR4Test extends BasePartitioningR4Test { myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(7, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); myCaptureQueriesListener.logInsertQueriesForCurrentThread(); - assertEquals(1, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); - assertEquals(2, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(8, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); /* @@ -2812,9 +2812,9 @@ public class PartitioningSqlR4Test extends BasePartitioningR4Test { myCaptureQueriesListener.logSelectQueriesForCurrentThread(); assertEquals(6, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); myCaptureQueriesListener.logInsertQueriesForCurrentThread(); - assertEquals(1, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(4, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); - assertEquals(2, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); + assertEquals(8, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); }