Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

perf(db): drop entity_access indexes superseded by the plain source-first index (#4866)

gbirmane17a6d702d40
diff --git a/crates/macro_db_client/migrations/20260715154215_drop_entity_access_source_id_index.sql b/crates/macro_db_client/migrations/20260715154215_drop_entity_access_source_id_index.sql
new file mode 100644
index 0000000000..932816d44e
--- /dev/null
+++ b/crates/macro_db_client/migrations/20260715154215_drop_entity_access_source_id_index.sql
@@ -0,0 +1,10 @@
+-- no-transaction
+-- entity_access_source_id_idx is a strict prefix of
+-- idx_entity_access_source_type_entity_plain (source_id, entity_type,
+-- entity_id); every source_id equality predicate is served by the plain
+-- index. Deploy only after confirming the plain index is valid:
+-- SELECT indexrelid::regclass FROM pg_index WHERE NOT indisvalid;
+--
+-- Single statement on purpose: see the note in
+-- 20260715154137_add_entity_access_source_type_entity_plain_index.sql.
+DROP INDEX CONCURRENTLY IF EXISTS entity_access_source_id_idx;
diff --git a/crates/macro_db_client/migrations/20260715154216_drop_entity_access_source_type_entity_expression_index.sql b/crates/macro_db_client/migrations/20260715154216_drop_entity_access_source_type_entity_expression_index.sql
new file mode 100644
index 0000000000..8113e73f78
--- /dev/null
+++ b/crates/macro_db_client/migrations/20260715154216_drop_entity_access_source_type_entity_expression_index.sql
@@ -0,0 +1,12 @@
+-- no-transaction
+-- idx_entity_access_source_type_entity keyed its third column on the
+-- expression (entity_id::text), which Postgres never uses to satisfy a
+-- reference to entity_id, so it could not serve index-only scans and its
+-- (source_id, entity_type) index conditions are covered by
+-- idx_entity_access_source_type_entity_plain. Deploy only after confirming
+-- the plain index is valid:
+-- SELECT indexrelid::regclass FROM pg_index WHERE NOT indisvalid;
+--
+-- Single statement on purpose: see the note in
+-- 20260715154137_add_entity_access_source_type_entity_plain_index.sql.
+DROP INDEX CONCURRENTLY IF EXISTS idx_entity_access_source_type_entity;