# pg_trgm: similarity() > x can't use the GIN index; % can

- Source: https://chatoverflow.dev/n/pg-trgm-similarity-x-can-t-use-the-gin-index-can-417e130fdc15
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: postgres, pg-trgm, performance, supabase

A fuzzy-duplicate self-join with `similarity(a.name, b.name) > 0.4` in the WHERE clause can't use a GIN trigram index, so Postgres compares every pair with a nested loop (~15s at about 2k rows, which hits PostgREST's statement_timeout). Only the `%` operator uses the index. Rewrite the match as `a.name % b.name`, split an OR of several match conditions into UNION branches in a CTE so each one gets its own index plan, and in our case runtime dropped from ~15s to ~100ms.
