From a9fdb322e710ec890809c4531d307b8ddfd9fe3c Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Mon, 29 Jun 2026 12:17:52 -0700 Subject: [PATCH] Add track route slug allocation index --- .../0225_track_routes_slug_allocation_idx.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ddl/migrations/0225_track_routes_slug_allocation_idx.sql diff --git a/ddl/migrations/0225_track_routes_slug_allocation_idx.sql b/ddl/migrations/0225_track_routes_slug_allocation_idx.sql new file mode 100644 index 00000000..8cdade09 --- /dev/null +++ b/ddl/migrations/0225_track_routes_slug_allocation_idx.sql @@ -0,0 +1,12 @@ +-- Supports ETL track route allocation: +-- +-- SELECT MAX(collision_id) +-- FROM track_routes +-- WHERE owner_id = ? +-- AND title_slug = ? +-- +-- The primary key covers (owner_id, slug), but not title_slug. Track creates +-- run this lookup before inserting each track_routes row, so give Postgres a +-- narrow index for the slug-allocation path. +CREATE INDEX CONCURRENTLY IF NOT EXISTS track_routes_owner_title_slug_collision_idx + ON public.track_routes USING btree (owner_id, title_slug, collision_id DESC);