From 8469dbc045cfd24d9fe1d524ed485f69326a5756 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Thu, 1 Dec 2022 19:29:15 -0600 Subject: [PATCH] fix: add index to `provisioner_jobs.started_at` (#5245) --- coderd/database/dump.sql | 2 ++ coderd/database/migrations/000085_acquire_job_index.down.sql | 1 + coderd/database/migrations/000085_acquire_job_index.up.sql | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 coderd/database/migrations/000085_acquire_job_index.down.sql create mode 100644 coderd/database/migrations/000085_acquire_job_index.up.sql diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 9b87b15661..84307b0f87 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -635,6 +635,8 @@ CREATE UNIQUE INDEX idx_users_username ON users USING btree (username) WHERE (de CREATE INDEX provisioner_job_logs_id_job_id_idx ON provisioner_job_logs USING btree (job_id, id); +CREATE INDEX provisioner_jobs_started_at_idx ON provisioner_jobs USING btree (started_at) WHERE (started_at IS NULL); + CREATE UNIQUE INDEX templates_organization_id_name_idx ON templates USING btree (organization_id, lower((name)::text)) WHERE (deleted = false); CREATE UNIQUE INDEX users_email_lower_idx ON users USING btree (lower(email)) WHERE (deleted = false); diff --git a/coderd/database/migrations/000085_acquire_job_index.down.sql b/coderd/database/migrations/000085_acquire_job_index.down.sql new file mode 100644 index 0000000000..894916c2ce --- /dev/null +++ b/coderd/database/migrations/000085_acquire_job_index.down.sql @@ -0,0 +1 @@ +DROP INDEX provisioner_jobs_started_at_idx; diff --git a/coderd/database/migrations/000085_acquire_job_index.up.sql b/coderd/database/migrations/000085_acquire_job_index.up.sql new file mode 100644 index 0000000000..603bc04854 --- /dev/null +++ b/coderd/database/migrations/000085_acquire_job_index.up.sql @@ -0,0 +1,2 @@ +CREATE INDEX provisioner_jobs_started_at_idx ON provisioner_jobs USING btree (started_at) + WHERE started_at IS NULL;