Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only use occurreddate to filter events in exporter [DHIS2-17732] #19363

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

enricocolasante
Copy link
Contributor

@enricocolasante enricocolasante commented Dec 2, 2024

We were applying some magic between occurreddate and scheduleddate in events and it was creating a performance issue and some odd behavior.

Performance issue

  • In the query to filter occurreddate, if there was a null value, then the one in scheduledate was used. This behavior was preventing the index on occurreddate to be used by the query planner slowing down the query performance.

Odd behavior

  • In the API the parameters occurredAfter and occurredBefore are used to filter the occurreddate but because of the logic that we had in the query, null values of occurreddate could be part of the result.
  • In the importer we were populating scheduleddate with occurreddate value if the former one was null. This wrongly appears as if the event was once scheduled and occurred in the same point in time. If an event was never scheduled, it should have a null scheduleddate.

These corner cases were not tested so no test is breaking. The feature itself is already properly tested in https://github.com/dhis2/dhis2-core/blob/master/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java

@enricocolasante enricocolasante marked this pull request as ready for review December 4, 2024 14:51
@enricocolasante enricocolasante requested a review from a team as a code owner December 4, 2024 14:51
Copy link
Contributor

@teleivo teleivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you post some numbers on how that affects performance (and or explain analyze changes)?

@enricocolasante enricocolasante requested a review from a team December 4, 2024 16:06
@enricocolasante
Copy link
Contributor Author

Can you post some numbers on how that affects performance (and or explain analyze changes)?

In some implementations it passed from 95 seconds to 2 seconds, there is more info in the thread https://dhis2.atlassian.net/browse/DHIS2-17732?focusedCommentId=205282

The changes affected performance because before the OR clause was forcing the planner to scan the whole event table, after removing it, the index can be used instead and there is no need of the full scan of the table.

Copy link

sonarcloud bot commented Dec 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants