From 9247f19cbbe45a9a032b975416105d47be897eac Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Mon, 16 Jun 2025 15:26:38 -0400 Subject: [PATCH] Additional indexes (#321) --- ...32_add_index_to_good_jobs_finished_at_with_error.rb | 10 ++++++++++ ..._to_ahoy_visits_started_at_with_referring_domain.rb | 10 ++++++++++ db/schema.rb | 4 +++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20250616191832_add_index_to_good_jobs_finished_at_with_error.rb create mode 100644 db/migrate/20250616192214_add_index_to_ahoy_visits_started_at_with_referring_domain.rb diff --git a/db/migrate/20250616191832_add_index_to_good_jobs_finished_at_with_error.rb b/db/migrate/20250616191832_add_index_to_good_jobs_finished_at_with_error.rb new file mode 100644 index 0000000..e52b5df --- /dev/null +++ b/db/migrate/20250616191832_add_index_to_good_jobs_finished_at_with_error.rb @@ -0,0 +1,10 @@ +class AddIndexToGoodJobsFinishedAtWithError < ActiveRecord::Migration[8.0] + disable_ddl_transaction! + + def change + add_index :good_jobs, :finished_at, + where: 'error IS NOT NULL', + algorithm: :concurrently, + name: 'index_good_jobs_finished_at_with_error' + end +end diff --git a/db/migrate/20250616192214_add_index_to_ahoy_visits_started_at_with_referring_domain.rb b/db/migrate/20250616192214_add_index_to_ahoy_visits_started_at_with_referring_domain.rb new file mode 100644 index 0000000..bc0462e --- /dev/null +++ b/db/migrate/20250616192214_add_index_to_ahoy_visits_started_at_with_referring_domain.rb @@ -0,0 +1,10 @@ +class AddIndexToAhoyVisitsStartedAtWithReferringDomain < ActiveRecord::Migration[8.0] + disable_ddl_transaction! + + def change + add_index :ahoy_visits, :started_at, + where: 'referring_domain IS NOT NULL', + algorithm: :concurrently, + name: 'index_ahoy_visits_started_at_with_referring_domain' + end +end diff --git a/db/schema.rb b/db/schema.rb index 4439986..443d82c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_06_13_163710) do +ActiveRecord::Schema[8.0].define(version: 2025_06_16_192214) do create_schema "pganalyze" # These are extensions that must be enabled in order to support this database @@ -57,6 +57,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_13_163710) do t.string "platform" t.datetime "started_at" t.index ["started_at"], name: "index_ahoy_visits_on_started_at" + t.index ["started_at"], name: "index_ahoy_visits_started_at_with_referring_domain", where: "(referring_domain IS NOT NULL)" t.index ["user_id"], name: "index_ahoy_visits_on_user_id" t.index ["visit_token"], name: "index_ahoy_visits_on_visit_token", unique: true t.index ["visitor_token", "started_at"], name: "index_ahoy_visits_on_visitor_token_and_started_at" @@ -202,6 +203,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_13_163710) do t.index ["concurrency_key"], name: "index_good_jobs_on_concurrency_key_when_unfinished", where: "(finished_at IS NULL)" t.index ["cron_key", "created_at"], name: "index_good_jobs_on_cron_key_and_created_at_cond", where: "(cron_key IS NOT NULL)" t.index ["cron_key", "cron_at"], name: "index_good_jobs_on_cron_key_and_cron_at_cond", unique: true, where: "(cron_key IS NOT NULL)" + t.index ["finished_at"], name: "index_good_jobs_finished_at_with_error", where: "(error IS NOT NULL)" t.index ["finished_at"], name: "index_good_jobs_jobs_on_finished_at", where: "((retried_good_job_id IS NULL) AND (finished_at IS NOT NULL))" t.index ["labels"], name: "index_good_jobs_on_labels", where: "(labels IS NOT NULL)", using: :gin t.index ["locked_by_id"], name: "index_good_jobs_on_locked_by_id", where: "(locked_by_id IS NOT NULL)"