Skip to content

findCurrentVersionsByResourcePidsAndFetchResourceTable could be more efficinet #7404

@esecules

Description

@esecules

NOTE: Before filing a ticket, please see the following URL:
https://github.com/hapifhir/hapi-fhir/wiki/Getting-Help

Describe the bug
The SQL query generated in findCurrentVersionsByResourcePidsAndFetchResourceTable could be more efficient. When there are hundreds of versions of a resource this query starts performing poorly. It is iterating over all the hfj_res_ver rows that have the given resource id and filtering them against the current version in the hfj_resource table

To Reproduce
Steps to reproduce the behavior:

1: populate a fhir database with many resources that have relationships with eachother like EnrollmentRequest, Patient, Coverage, Organization and keep updating those resources so that they get a new version.
2: then execute a query like /EnrollmentRequest?patient.identifier:exact=ABC12356789&_include:iterate=EnrollmentRequest:*
3: this search can take a second or 2

Expected behavior
The search should have sub-second performance

Screenshots
(Used SELECT * for conciseness, but in reality, it is verbosely selecting what looks like all columns from each table.)
EXPLAIN ANALYZE from current code
Image

EXPLAIN ANALYZE of proposed solution: hfj_resource.res_id should be in the WHERE IN condition
Image

Environment (please complete the following information):

  • HAPI FHIR Version 8.2.0 JPA Server
  • OS: Linux
  • Browser: Chrome

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions