Skip to content

Commit 8e04445

Browse files
committed
improvement(db): drop unused tag slot and redundant prefix indexes
1 parent a0c93d6 commit 8e04445

4 files changed

Lines changed: 29093 additions & 34 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- Generated by drizzle-kit, then converted to CONCURRENTLY per scripts/migrate.ts (plain
2+
-- DROP INDEX takes ACCESS EXCLUSIVE for the whole op, write-locking the table).
3+
--
4+
-- DROP typed tag-slot indexes on embedding and document that queries never or barely use, each
5+
-- still maintained on every chunk insert and every non-HOT document update:
6+
-- number2..5, boolean2..3 slots that are rarely or never filtered on
7+
-- date1..2 tag filters compare `col::date`, which a plain timestamp btree never matches
8+
-- boolean1 two distinct values; any scan reads a large fraction of the table
9+
-- number1 and the lower(tagN) text indexes are kept.
10+
--
11+
-- DROP six redundant indexes, each a left-prefix of an existing non-partial superset, so the
12+
-- superset still serves equality lookups and foreign-key cascades on the leading column:
13+
-- emb_kb_id_idx ⊂ emb_kb_enabled_idx, emb_kb_model_idx
14+
-- emb_doc_id_idx ⊂ emb_doc_chunk_idx, emb_doc_enabled_idx
15+
-- usage_log_workspace_id_idx ⊂ usage_log_workspace_created_at_idx
16+
-- copilot_runs_execution_id_idx ⊂ copilot_runs_execution_started_at_idx
17+
-- copilot_runs_chat_id_idx ⊂ copilot_runs_chat_started_at_idx, copilot_runs_chat_execution_idx
18+
-- copilot_runs_workspace_id_idx ⊂ copilot_runs_workspace_completed_at_id_idx
19+
--
20+
-- The embedded COMMIT drops out of drizzle's batch transaction; everything below runs in
21+
-- autocommit (CONCURRENTLY cannot run in a transaction) and is idempotent for safe replay.
22+
COMMIT;--> statement-breakpoint
23+
SET lock_timeout = 0;--> statement-breakpoint
24+
DROP INDEX CONCURRENTLY IF EXISTS "emb_number2_idx";--> statement-breakpoint
25+
DROP INDEX CONCURRENTLY IF EXISTS "emb_number3_idx";--> statement-breakpoint
26+
DROP INDEX CONCURRENTLY IF EXISTS "emb_number4_idx";--> statement-breakpoint
27+
DROP INDEX CONCURRENTLY IF EXISTS "emb_number5_idx";--> statement-breakpoint
28+
DROP INDEX CONCURRENTLY IF EXISTS "emb_date1_idx";--> statement-breakpoint
29+
DROP INDEX CONCURRENTLY IF EXISTS "emb_date2_idx";--> statement-breakpoint
30+
DROP INDEX CONCURRENTLY IF EXISTS "emb_boolean1_idx";--> statement-breakpoint
31+
DROP INDEX CONCURRENTLY IF EXISTS "emb_boolean2_idx";--> statement-breakpoint
32+
DROP INDEX CONCURRENTLY IF EXISTS "emb_boolean3_idx";--> statement-breakpoint
33+
DROP INDEX CONCURRENTLY IF EXISTS "doc_number2_idx";--> statement-breakpoint
34+
DROP INDEX CONCURRENTLY IF EXISTS "doc_number3_idx";--> statement-breakpoint
35+
DROP INDEX CONCURRENTLY IF EXISTS "doc_number4_idx";--> statement-breakpoint
36+
DROP INDEX CONCURRENTLY IF EXISTS "doc_number5_idx";--> statement-breakpoint
37+
DROP INDEX CONCURRENTLY IF EXISTS "doc_date1_idx";--> statement-breakpoint
38+
DROP INDEX CONCURRENTLY IF EXISTS "doc_date2_idx";--> statement-breakpoint
39+
DROP INDEX CONCURRENTLY IF EXISTS "doc_boolean1_idx";--> statement-breakpoint
40+
DROP INDEX CONCURRENTLY IF EXISTS "doc_boolean2_idx";--> statement-breakpoint
41+
DROP INDEX CONCURRENTLY IF EXISTS "doc_boolean3_idx";--> statement-breakpoint
42+
DROP INDEX CONCURRENTLY IF EXISTS "emb_kb_id_idx";--> statement-breakpoint
43+
DROP INDEX CONCURRENTLY IF EXISTS "emb_doc_id_idx";--> statement-breakpoint
44+
DROP INDEX CONCURRENTLY IF EXISTS "usage_log_workspace_id_idx";--> statement-breakpoint
45+
DROP INDEX CONCURRENTLY IF EXISTS "copilot_runs_execution_id_idx";--> statement-breakpoint
46+
DROP INDEX CONCURRENTLY IF EXISTS "copilot_runs_chat_id_idx";--> statement-breakpoint
47+
DROP INDEX CONCURRENTLY IF EXISTS "copilot_runs_workspace_id_idx";--> statement-breakpoint
48+
SET lock_timeout = '5s';

0 commit comments

Comments
 (0)