Skip to content

Commit ec362bd

Browse files
committed
database: Add index to optimize background job queue processing
This commit creates a composite index on `(priority DESC, id ASC)` to improve performance of job selection queries that order by priority and id for queue processing. This improved the job selection query performance from roughly 800ms to 0.07ms after enqueuing all of the `analyze-crate-file` backfill background jobs.
1 parent 8cae1a9 commit ec362bd

File tree

2 files changed

+6
-0
lines changed
  • migrations/2025-09-22-090805_add_background_jobs_priority_id_index

2 files changed

+6
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP INDEX CONCURRENTLY background_jobs_priority_id_index;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE INDEX CONCURRENTLY background_jobs_priority_id_index
2+
ON background_jobs (priority DESC, id ASC);
3+
4+
COMMENT ON INDEX background_jobs_priority_id_index IS
5+
'Optimizes job queue processing by allowing efficient ordering by priority (desc) and id (asc) for job selection queries';

0 commit comments

Comments
 (0)