Skip to content

[ING-123] fix(events-processor): Add organization_id in fetch flat filters query#738

Merged
vincent-pochet merged 1 commit into
mainfrom
fix-speedup-flat-filters-lookup
May 18, 2026
Merged

[ING-123] fix(events-processor): Add organization_id in fetch flat filters query#738
vincent-pochet merged 1 commit into
mainfrom
fix-speedup-flat-filters-lookup

Conversation

@vincent-pochet
Copy link
Copy Markdown
Contributor

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_filters view does not uses the correct index on the billable metric table (organization_id, code) when performing the lookup because the organization_id filter is not used in the query, leading to a Seq Scan instead of an Index Scan on the billable metric relation

Description

This PR updates the query and the processing logic to use the organization_id value in conjunction with the actual plan_id and billable metric code

@vincent-pochet vincent-pochet force-pushed the fix-speedup-flat-filters-lookup branch from 50d44a4 to 44f1b8c Compare May 18, 2026 10:05
@vincent-pochet vincent-pochet merged commit 9ef876a into main May 18, 2026
1 check passed
@vincent-pochet vincent-pochet deleted the fix-speedup-flat-filters-lookup branch May 18, 2026 12:48
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
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