perf: eliminate program and program stage table joins in tracker event queries DHIS2-20922#23044
Merged
perf: eliminate program and program stage table joins in tracker event queries DHIS2-20922#23044
Conversation
20ff901 to
1185734
Compare
1185734 to
b915387
Compare
When a specific program is given, the program table join is unnecessary. The program's metadata (uid, code, name, type, attributeValues) is already available from the Java Program object and can be populated in the RowMapper instead of fetching from the database. - Skip program join when enrolledInTrackerProgram is set - Use en.programid instead of p.programid in WHERE clause - Use ev.programstageid instead of ps.programstageid in WHERE clause (programstage join kept for SELECT columns only) - Populate program fields from Java object in RowMapper Same approach as the tracked entity store (PR #22920) and the enrollment store (PR #22970).
b915387 to
e987dcf
Compare
|
enricocolasante
approved these changes
Feb 24, 2026
muilpp
approved these changes
Feb 25, 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.



Eliminate
programandprogramstagetable joins from tracker event queries when the respective parameter is known. The columns (uid, code, name, attributeValues) are already available from the Java objects loaded during request validation, so we populate them directly in the row mapper instead of joining the tables.Same approach as #22920 for tracked entities and #22972 for enrollments.
The
programparameter is mandatory for/api/tracker/events, so the program join is always eliminated. Theprogramstagejoin is eliminated when a specific program stage is requested.Before:
After (with program and program stage known):
Performance
Database
Sierra Leone DB with ~10M tracked entities, ~32M events. EXPLAIN ANALYZE (4 warmup runs) and pgbench (1 client, 30s) on the base event query (
program=ur1Edk5Oe2n&pageSize=3).Execution time unchanged (~11ms). The gains are in planning time and sustained throughput. With both joins eliminated, pgbench throughput improves by 25%.