From 18fd8ca5e57ca7df65f1b0ee2fc290ee3e1b84aa Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Thu, 1 Dec 2022 19:13:15 -0600 Subject: [PATCH] fix: add index to `provisioner_jobs.started_at` --- 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 c598280397c4d..79dc181deef15 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 0000000000000..894916c2ce89c --- /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 0000000000000..603bc04854b70 --- /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;