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

jobs: invert status predicate to improve query plan #57587

Conversation

ajwerner
Copy link
Contributor

@ajwerner ajwerner commented Dec 4, 2020

The jobs code regularly scans the set of adoptable jobs (generally small) to
find if there are abandoned jobs in need of adoption. In #56864 we added a
predicate to improve these loops to stop touching already terminal jobs. This
was a big improvement in what data is written but not as big of an improvement
in what data was read. When the jobs table is large, the queries, prior to this
patch, performed expensive full table scans. With this patch the query plan is
improved to utilize the index. Were there a check constraint indicating the
allowable values of status, then the optimizer could have created the same
plan. However, there isn't.

Release note (bug fix): Remove system.jobs full table scan which is
expensive in the face of many completed jobs.

@ajwerner ajwerner requested review from dt and spaskob December 4, 2020 21:06
@cockroach-teamcity
Copy link
Member

This change is Reviewable

The jobs code regularly scans the set of adoptable jobs (generally small) to
find if there are abandoned jobs in need of adoption. In cockroachdb#56864 we added a
predicate to improve these loops to stop touching already terminal jobs. This
was a big improvement in what data is written but not as big of an improvement
in what data was read. When the jobs table is large, the queries, prior to this
patch, performed expensive full table scans. With this patch the query plan is
improved to utilize the index. Were there a check constraint indicating the
allowable values of status, then the optimizer could have created the same
plan. However, there isn't.

Release note (bug fix): Remove system.jobs full table scan which is
expensive in the face of many completed jobs.
@ajwerner ajwerner force-pushed the ajwerner/flip-predicates-for-adoption-loop branch from c0c735c to e1c79f2 Compare December 4, 2020 21:18
@ajwerner
Copy link
Contributor Author

ajwerner commented Dec 5, 2020

TFTR!

bors r=spaskob

@craig
Copy link
Contributor

craig bot commented Dec 5, 2020

Build failed:

@ajwerner
Copy link
Contributor Author

ajwerner commented Dec 7, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented Dec 7, 2020

Build succeeded:

@craig craig bot merged commit 1ed669d into cockroachdb:master Dec 7, 2020
@rafiss rafiss added this to the 20.2 milestone Apr 22, 2021
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.

4 participants