diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1963-avoid-unnecessary-type-predicate.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1963-avoid-unnecessary-type-predicate.yaml new file mode 100644 index 00000000000..1a924dc3575 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1963-avoid-unnecessary-type-predicate.yaml @@ -0,0 +1,5 @@ +--- +type: perf +issue: 1963 +title: "When performing a search in the JPA server using a chained search parameter, an unnecessary resource type predicate + was previously added to the generated SQL and has now been removed. This should improve performance on some queries." diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderReference.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderReference.java index be9c9d5314a..f12e535b707 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderReference.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderReference.java @@ -354,7 +354,7 @@ class PredicateBuilderReference extends BasePredicateBuilder { } Predicate predicate = myCriteriaBuilder.or(toArray(theCodePredicates)); - myQueryStack.addPredicate(predicate); + myQueryStack.addPredicateWithImplicitTypeSelection(predicate); return predicate; } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java index 22ac73284ed..42ce8e0a9a1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java @@ -403,13 +403,16 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { List ids; SearchParameterMap map; IBundleProvider results; + String searchSql; map = new SearchParameterMap(); map.setLoadSynchronous(true); map.add(Encounter.SP_SUBJECT, new ReferenceParam("subject", "foo|bar").setChain("identifier")); myCaptureQueriesListener.clear(); results = myEncounterDao.search(map); - myCaptureQueriesListener.logSelectQueriesForCurrentThread(0); + searchSql = myCaptureQueriesListener.logSelectQueriesForCurrentThread(0); + assertEquals(0, StringUtils.countMatches(searchSql, "RES_DELETED_AT")); + assertEquals(0, StringUtils.countMatches(searchSql, "RES_TYPE")); ids = toUnqualifiedVersionlessIdValues(results); assertThat(ids, hasItems(enc1Id, enc2Id));