Skip to content

Commit 657e05b

Browse files
authored
fix: added missing index (#3950)
Signed-off-by: Uroš Marolt <uros@marolt.me>
1 parent 2352f05 commit 657e05b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP INDEX CONCURRENTLY IF EXISTS "idx_memberIdentities_verified_email_lower_value";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- The existing idx_memberIdentities_email_verified_trgm covers the right partial
2+
-- conditions (verified = true, type = 'email', deletedAt IS NULL) but is a GIN
3+
-- trigram index -- PostgreSQL will not use it for equality joins on
4+
-- lower(mi.value) against input emails, for example:
5+
--
6+
-- JOIN ON lower(mi.value) = input_email
7+
-- WHERE mi.verified = true AND mi.type = 'email' AND mi."deletedAt" IS NULL
8+
--
9+
-- The only usable B-tree index (idx_memberIdentities_lower_value) only carries
10+
-- the partial condition deletedAt IS NULL, so PG must heap-fetch every matched
11+
-- row to re-check verified and type, which degrades as the table grows.
12+
--
13+
-- This B-tree partial index lets the planner do a direct nested-loop index scan
14+
-- (one lookup per input email) with no extra heap fetches for verified/type.
15+
16+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "idx_memberIdentities_verified_email_lower_value"
17+
ON "memberIdentities" (lower(value))
18+
WHERE verified = true
19+
AND type = 'email'
20+
AND "deletedAt" IS NULL;

0 commit comments

Comments
 (0)