[ING-123] fix(events-processor): Add organization_id in fetch flat filters query#738
Merged
Merged
Conversation
groyoh
approved these changes
May 15, 2026
50d44a4 to
44f1b8c
Compare
vincent-pochet
added a commit
to getlago/lago-api
that referenced
this pull request
May 18, 2026
…ormances (#5499) ## Context Related to getlago/lago#738 After some analysis, it appears that the queries used in the events-processor to fetch the flat_filters (aggregated filter keys/values) is not performant enough under heavy write load on the database. ## Description This PR improves the query by: - moving the `where deleted_at is null` filtering on left join itself rather than in the condition - removing the `properties` select as it is not used by the events-processor
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.
Context
After some analysis, it appears that the queries used in the events-processor to fetch the flat_filters (aggregated filter keys/values) is not performant enough under heavy write load on the database.
After some analysis, it appears that the queries made on the
flat_filtersview does not uses the correct index on the billable metric table (organization_id, code) when performing the lookup because theorganization_idfilter is not used in the query, leading to a Seq Scan instead of an Index Scan on the billable metric relationDescription
This PR updates the query and the processing logic to use the organization_id value in conjunction with the actual
plan_idand billable metriccode