(Postgres 12)
I am implementing a text search that allows for both exact match and fuzzy (ILIKE) match:
attributes->>'ID' = 'some-id'
-- OR
attributes->>'ID' ILIKE '%some-%'
(The user declares whether the search will be exact or not, so only one of the above is ever included in the query)
I am putting indexes on the most commonly searched attributes, ID and Name. When I use a GIN w/ gin_trgm_ops, the fuzzy match is much faster. With a BTREE index, the exact match is much faster.
I can have both BTREE and GIN indexes, but I am wondering if that is strictly necessary. Is there a way to nudge postgres into using the GIN index for the exact match search?