Conversation
When a specific program is provided, resolve its ID in Java and filter with e.programid = :programId instead of joining the program table and filtering on p.uid/p.type. The program type check is already validated by EnrollmentOperationParamsMapper before reaching the store. This removes one inner join from the count query for the common case (program specified). The data query still joins program for SELECT columns.
…20921 When the program is known and its access level is OPEN, AUDITED, or CLOSED, the trackedentity join is unnecessary in the count query. The join was only needed for the PROTECTED temp owner check in the ownership clause, which references te.trackedentityid. For tracked entity UID filters, uses a subquery instead of a join to avoid hashing all 10M rows.
c09cc45 to
e6a4dae
Compare
…ata query DHIS2-20921 When program is known (which is the common case for all clients), skip the program and trackedentitytype table joins from the data query. The Program entity is already loaded by the mapper, so we reuse it in the RowMapper instead of reconstructing it from the ResultSet. This halves SQL planning time from ~12ms to ~6ms.
e6a4dae to
4e828cd
Compare
|
muilpp
approved these changes
Feb 18, 2026
enricocolasante
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Follow-up to #22972. Eliminates
programandtrackedentitytypejoins from the enrollment data query when a specific program is requested (/enrollments?program=...), which is the standard usage from Capture app, Android SDK, etc. Requests without a program filter are unaffected and keep the original query.The mapper already loads the full
Programentity (including itsTrackedEntityType) during validation. This PR reuses that entity in theRowMapperinstead of reconstructing it from SQL result columns, removing two joins and ~15 SELECT columns from the data query.SQL
Data query (when program is specified) --
programandtrackedentitytypejoins removed:Database Performance
Sierra Leone DB with 10M tracked entities (10.9M enrollments). EXPLAIN ANALYZE on the generated SQL queries, 4 warmup runs.
Planning time halved from ~11ms to ~6ms across all 24 tested data queries. Execution time unchanged. For queries that execute in under 20ms (the majority), the ~5ms planning time saving is 20-35% of total DB time.
The count query is not affected since #22972 already eliminated these joins from it.