From 4632343ff5d3d52c4f9d2b568e0858c3d332bbc6 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 22 Sep 2025 11:10:56 +0200 Subject: [PATCH] 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. --- .../down.sql | 1 + .../metadata.toml | 1 + .../up.sql | 2 ++ 3 files changed, 4 insertions(+) create mode 100644 migrations/2025-09-22-090805_add_background_jobs_priority_id_index/down.sql create mode 100644 migrations/2025-09-22-090805_add_background_jobs_priority_id_index/metadata.toml create mode 100644 migrations/2025-09-22-090805_add_background_jobs_priority_id_index/up.sql diff --git a/migrations/2025-09-22-090805_add_background_jobs_priority_id_index/down.sql b/migrations/2025-09-22-090805_add_background_jobs_priority_id_index/down.sql new file mode 100644 index 00000000000..5d818fd9c40 --- /dev/null +++ b/migrations/2025-09-22-090805_add_background_jobs_priority_id_index/down.sql @@ -0,0 +1 @@ +DROP INDEX CONCURRENTLY background_jobs_priority_id_index; diff --git a/migrations/2025-09-22-090805_add_background_jobs_priority_id_index/metadata.toml b/migrations/2025-09-22-090805_add_background_jobs_priority_id_index/metadata.toml new file mode 100644 index 00000000000..79e9221c1f2 --- /dev/null +++ b/migrations/2025-09-22-090805_add_background_jobs_priority_id_index/metadata.toml @@ -0,0 +1 @@ +run_in_transaction = false diff --git a/migrations/2025-09-22-090805_add_background_jobs_priority_id_index/up.sql b/migrations/2025-09-22-090805_add_background_jobs_priority_id_index/up.sql new file mode 100644 index 00000000000..728eade89f1 --- /dev/null +++ b/migrations/2025-09-22-090805_add_background_jobs_priority_id_index/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX CONCURRENTLY background_jobs_priority_id_index + ON background_jobs (priority DESC, id ASC);