cuddly-jelly-27016
03/03/2025, 5:22 PMSELECT * FROM "executions" WHERE executions.execution_project = $1 AND executions.execution_domain = $2 AND executions.phase in ($3) AND executions.execution_created_at >= $4 AND executions.execution_created_at <= $5 AND executions.state = $6 LIMIT $7
It takes 95% of the db load. In our setup it is roughly called ~800k times per hour. The average execution time for the query is 13ms. It sometimes hits the pkey index but some other times it has to do a scan taking around 150ms.
We added a composite index on execution_project, execution_domain, phase, execution_created_at and state and the avg execution time went down to 0.01ms.
That query was also taking most of our memory as most shared cache hits were done by it. After adding the change the query went from ~180k/s shared block accessed to ~200/s (roughly a factor of 1000). This is also helping to use the memory for other queries.
What changes were proposed in this pull request?
This change adds a composite index in executions table to avoid doing scans.
How was this patch tested?
The index was manually created in the db.
Setup process
Screenshots
image
Load by time (first row is the mentioned query)
image
Check all the applicable boxes
• I updated the documentation accordingly.
• All new and existing tests passed.
• All commits are signed-off.
Related PRs
Docs link
flyteorg/flytecuddly-jelly-27016
03/03/2025, 5:22 PM