From 49a39c195c25b1c977a84f782914b7a98ffeed62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Primo=C5=BE=20Delopst?= Date: Tue, 4 Apr 2023 20:30:28 +0200 Subject: [PATCH] Improve performance of ResourceSearchView (use hfj_resource res_id instead of hfj_res_ver res_id when querying by resource pids) (#4716) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Improve performance of ResourceSearchView (use hfj_resource res_id instead of hfj_res_ver res_id when querying by resource pids) * Add changelog and credit --------- Co-authored-by: Primož Delopst Co-authored-by: James Agnew --- .../fhir/changelog/6_6_0/4716-search-view-performance.yaml | 6 ++++++ .../java/ca/uhn/fhir/jpa/entity/ResourceSearchView.java | 2 +- pom.xml | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4716-search-view-performance.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4716-search-view-performance.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4716-search-view-performance.yaml new file mode 100644 index 00000000000..e6d9a38dc63 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4716-search-view-performance.yaml @@ -0,0 +1,6 @@ +--- +type: perf +issue: 4716 +title: "The SQL query used to fetch pages of search results resulted in an inefficient use + of the database in cases where resources have many different versions stored. Thanks to + Primož Delopst for the pull request!" diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceSearchView.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceSearchView.java index f3d6e6f1a73..a9b4281b4cd 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceSearchView.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceSearchView.java @@ -46,7 +46,7 @@ import java.util.Date; @Entity @Immutable @Subselect("SELECT h.pid as pid, " + - " h.res_id as res_id, " + + " r.res_id as res_id, " + " h.res_type as res_type, " + " h.res_version as res_version, " + // FHIR version " h.res_ver as res_ver, " + // resource version diff --git a/pom.xml b/pom.xml index d78fe01bc24..7f13ca7ea0d 100644 --- a/pom.xml +++ b/pom.xml @@ -859,6 +859,10 @@ JorisHeadease + + delopst + Primož Delopst +