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

Add composite index for executions #4872

Conversation

pablocasares
Copy link

Why are the changes needed?

We are experiencing high load on query:
SELECT * 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

Copy link

welcome bot commented Feb 9, 2024

Thank you for opening this pull request! 🙌

These tips will help get your PR across the finish line:

  • Most of the repos have a PR template; if not, fill it out to the best of your knowledge.
  • Sign off your commits (Reference: DCO Guide).

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement New feature or request labels Feb 9, 2024
Signed-off-by: Pablo Casares Crespo <[email protected]>
@pablocasares pablocasares force-pushed the add-executions-composite-index branch from 93a0962 to a7d1658 Compare February 9, 2024 10:38
@katrogan
Copy link
Contributor

hi @pablocasares thanks for this change, I'm curious if you're running an out of band process that generates these queries? from inspecting the console I don't see may queries issued to the execution table that filter on phase (but do see that they query on created_at DESC)

Copy link

codecov bot commented Feb 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.76%. Comparing base (1b3a5cc) to head (a7d1658).
Report is 1044 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4872      +/-   ##
==========================================
+ Coverage   58.98%   59.76%   +0.77%     
==========================================
  Files         645      463     -182     
  Lines       55162    37276   -17886     
==========================================
- Hits        32539    22279   -10260     
+ Misses      20048    13325    -6723     
+ Partials     2575     1672     -903     
Flag Coverage Δ
unittests 59.76% <ø> (+0.77%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@eapolinario
Copy link
Contributor

Cleaning stale PRs. Please reopen if you wan to discuss this further.

@eapolinario eapolinario closed this Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants