33 lines
1.4 KiB
MySQL
33 lines
1.4 KiB
MySQL
|
|
-- Convert composite (port_id, archived_at) archived indexes to partial
|
||
|
|
-- indexes WHERE archived_at IS NULL. Every list query in the codebase that
|
||
|
|
-- hits archived_at filters on `archived_at IS NULL` (verified in
|
||
|
|
-- clients.service / interests.service / search.service / residential.service
|
||
|
|
-- / yachts.service). The composite index always carries the archived rows
|
||
|
|
-- as dead weight; the partial index is smaller, has a higher cache hit rate,
|
||
|
|
-- and lets the planner skip the index entirely when the predicate is absent.
|
||
|
|
|
||
|
|
-- clients
|
||
|
|
DROP INDEX IF EXISTS "idx_clients_archived";
|
||
|
|
CREATE INDEX IF NOT EXISTS "idx_clients_archived" ON "clients" ("port_id")
|
||
|
|
WHERE "archived_at" IS NULL;
|
||
|
|
|
||
|
|
-- interests
|
||
|
|
DROP INDEX IF EXISTS "idx_interests_archived";
|
||
|
|
CREATE INDEX IF NOT EXISTS "idx_interests_archived" ON "interests" ("port_id")
|
||
|
|
WHERE "archived_at" IS NULL;
|
||
|
|
|
||
|
|
-- yachts
|
||
|
|
DROP INDEX IF EXISTS "idx_yachts_archived";
|
||
|
|
CREATE INDEX IF NOT EXISTS "idx_yachts_archived" ON "yachts" ("port_id")
|
||
|
|
WHERE "archived_at" IS NULL;
|
||
|
|
|
||
|
|
-- residential clients
|
||
|
|
DROP INDEX IF EXISTS "idx_residential_clients_archived";
|
||
|
|
CREATE INDEX IF NOT EXISTS "idx_residential_clients_archived" ON "residential_clients" ("port_id")
|
||
|
|
WHERE "archived_at" IS NULL;
|
||
|
|
|
||
|
|
-- residential interests
|
||
|
|
DROP INDEX IF EXISTS "idx_residential_interests_archived";
|
||
|
|
CREATE INDEX IF NOT EXISTS "idx_residential_interests_archived" ON "residential_interests" ("port_id")
|
||
|
|
WHERE "archived_at" IS NULL;
|