- Notifications
You must be signed in to change notification settings - Fork913
fix: optimize queue position sql query#17974
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
7078fc2
e16598d
5069c1d
eae97c3
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -80,17 +80,21 @@ pending_jobs AS ( | ||
WHERE | ||
job_status = 'pending' | ||
), | ||
online_provisioner_daemons AS ( | ||
SELECT id, tags FROM provisioner_daemons pd | ||
WHERE pd.last_seen_at IS NOT NULL AND pd.last_seen_at >= (NOW() - (@stale_interval_ms::bigint || ' ms')::interval) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This should probably be a more descriptive param like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. We use | ||
), | ||
ranked_jobs AS ( | ||
-- Step 3: Rank only pending jobs based on provisioner availability | ||
SELECT | ||
pj.id, | ||
pj.created_at, | ||
ROW_NUMBER() OVER (PARTITION BYopd.id ORDER BY pj.created_at ASC) AS queue_position, | ||
COUNT(*) OVER (PARTITION BYopd.id) AS queue_size | ||
FROM | ||
pending_jobs pj | ||
INNER JOINonline_provisioner_daemons opd | ||
ON provisioner_tagset_contains(opd.tags, pj.tags) -- Join only on the small pending set | ||
), | ||
final_jobs AS ( | ||
-- Step 4: Compute best queue position and max queue size per job | ||
Uh oh!
There was an error while loading.Please reload this page.