Skip to content

Update old job biggest id#96

Merged
hladush merged 1 commit intomainfrom
ihladush/update_the_query_for_biggest_finished_job_id
Feb 26, 2026
Merged

Update old job biggest id#96
hladush merged 1 commit intomainfrom
ihladush/update_the_query_for_biggest_finished_job_id

Conversation

@hladush
Copy link
Contributor

@hladush hladush commented Feb 26, 2026

Optimized query, my thought was that DB could find the job ID in mid table <10M of rows during secods, it's not true because it causes a whole table scan.
This update started to utilize the fact that a PK is indexed and it's a system_job_id bigint generated always as identity.
Now query is ~500 times faster
Tested with database

Copilot AI review requested due to automatic review settings February 26, 2026 23:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the janitor’s “biggest old job ID” lookup to avoid an expensive scan/sort on updated_at by leveraging the indexed jobs.system_job_id primary key.

Changes:

  • Change the old_job_biggest_id.sql query to order by system_job_id DESC (instead of updated_at DESC) to fetch the largest old job ID more efficiently.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hladush hladush merged commit 4843514 into main Feb 26, 2026
13 checks passed
@hladush hladush deleted the ihladush/update_the_query_for_biggest_finished_job_id branch February 26, 2026 23:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

WHERE updated_at < $1
ORDER BY updated_at desc
ORDER BY system_job_id desc
LIMIT 1 No newline at end of file
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

For consistency with other janitor SQL queries (e.g. stale_and_canceling_jobs_select.sql, old_jobs_delete.sql), this statement should end with a trailing semicolon. That also avoids accidental issues if the embedded SQL ever gets concatenated with additional statements.

Suggested change
LIMIT 1
LIMIT 1;

Copilot uses AI. Check for mistakes.
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.

3 participants