-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
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

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

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.