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

Replace jobs_user_guid_index with jobs_user_guid_state_index #3934

Merged

Conversation

svkrieger
Copy link
Contributor

Thanks for contributing to cloud_controller_ng. To speed up the process of reviewing your pull request please provide us with:

A short explanation of the proposed change:

Replacing jobs_user_guid_index with partial index jobs_user_guid_state_index for Postgres.

An explanation of the use cases your change solves

When the jobs table is large and single users have also a large amount of jobs, which are mostly in state COMPLETED, postgres might decide to not use the index on user_guid column and scan the table with other methods, which are much slower. This commit removes the index on user_guid column and adds a new partial index on user_guid and state where state is either POLLING or PROCESSING. This keeps the index much smaller and improves the query performance drastically.

MySQL does not support partial indexes.

Links to any other associated PRs

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

When the jobs table is large and single users have also a large amount of jobs, which are mostly in state `COMPLETED`,
postgres might decide to not use the index on `user_guid` column and scan the table with other methods, which are much slower.
This commit removes the index on user_guid column and adds a new partial index on user_guid and state where state is either
`POLLING` or `PROCESSING`. This keeps the index much smaller and improves the query performance drastically.

MySQL does not support partial indexes.
@svkrieger svkrieger force-pushed the replace_jobs_user_guid_index_with_jobs_user_guid_state_index branch from d474230 to 6c7c13a Compare August 20, 2024 14:50
Copy link
Contributor

@johha johha left a comment

Choose a reason for hiding this comment

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

LGTM

@svkrieger svkrieger merged commit 5d29711 into main Aug 22, 2024
14 checks passed
@svkrieger svkrieger deleted the replace_jobs_user_guid_index_with_jobs_user_guid_state_index branch August 22, 2024 05:35
ari-wg-gitbot added a commit to cloudfoundry/capi-release that referenced this pull request Aug 22, 2024
Changes in cloud_controller_ng:

- Replace `jobs_user_guid_index` with `jobs_user_guid_state_index`
    PR: cloudfoundry/cloud_controller_ng#3934
    Author: Sven Krieger <37476281+svkrieger@users.noreply.github.com>
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