Skip to content

Commit

Permalink
issue #3232- add the extra IN clause more selectively
Browse files Browse the repository at this point in the history
Previously, we were adding this extra IN clause for the _type parameter
in all cases.
In the case of a whole-system search *count* query, this was slowing
things down a bit. We still add the IN clause to the query where it
seemed to help, but now we avoid that for the count query.

Signed-off-by: Lee Surprenant <[email protected]>
  • Loading branch information
lmsurpre committed Feb 10, 2022
1 parent 9a6158b commit e5718b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class SearchQuery {
private final List<SearchParam> searchParams = new ArrayList<>();

// A list of non-parameter related extensions (e.g. location processing)
private final List<SearchExtension> extensions = new ArrayList<>();
protected final List<SearchExtension> extensions = new ArrayList<>();

/**
* Public constructor
Expand Down Expand Up @@ -76,11 +76,8 @@ public <T> T visit(SearchQueryVisitor<T> visitor) throws FHIRPersistenceExceptio
T query = getRoot(visitor);
visitExtensions(query, visitor);

// Add the parameters subquery and add the extensions there too
// Add the parameters subquery
T parameterBase = visitor.getParameterBaseQuery(query);
for (SearchExtension ext: this.extensions) {
ext.visit(parameterBase, visitor);
}
visitSearchParams(parameterBase, visitor);

logger.exiting(CLASSNAME, "visit");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2021
* (C) Copyright IBM Corp. 2021, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -19,7 +19,7 @@
* is a set of logical resource id + resource type.
*/
public class SearchWholeSystemFilterQuery extends SearchQuery {

// Sort parameters
final List<DomainSortParameter> sortParameters = new ArrayList<>();

Expand All @@ -43,11 +43,23 @@ public <T> T getRoot(SearchQueryVisitor<T> visitor) {
return visitor.wholeSystemFilterRoot();
}

/**
* @implNote Overrides the default SearchQuery.visit so that we can add an extra filter to the
* "parameterBase" subquery to address https://github.com/IBM/FHIR/issues/3232.
* Also adds wholeSystemSorting and pagination.
*/
@Override
public <T> T visit(SearchQueryVisitor<T> visitor) throws FHIRPersistenceException {
// Get the root query and process extensions for it
T query = getRoot(visitor);
visitExtensions(query, visitor);

// get the core data query
T query = super.visit(visitor);
// Add the parameters subquery and add the extensions there too
T parameterBase = visitor.getParameterBaseQuery(query);
for (SearchExtension ext: this.extensions) {
ext.visit(parameterBase, visitor);
}
visitSearchParams(parameterBase, visitor);

// now attach the requisite ordering and pagination clauses
query = visitor.addWholeSystemSorting(query, sortParameters, "LR0");
Expand Down

0 comments on commit e5718b4

Please sign in to comment.