Is there a way to use pg_trgm like operator with btree indexes on PostgreSQL?
Is there a way to use pg_trgm like operator with btree indexes on PostgreSQL? I have two tables: ref_id_t1 is filled with id_t1 values , however they are not linked by a foreign key as table_2 doesn't know about table_1. I need to do a request on both table like the following: SELECT * FROM table_1 t1 WHERE t1.c1_t1= 'A' AND t1.id_t1 IN (SELECT t2.ref_id_t1 FROM table_2 t2 WHERE t2.c1_t2 LIKE '%abc%'); Without any change or with basic indexes the request takes about a minute to complete as a sequencial scan is peformed on table_2. To prevent this I created a GIN idex with gin_trgm_ops option: CREATE EXTENSION pg_trgm; CREATE INDEX c1_t2_gin_index ON table_2 USING gin (c1_t2, gin_trgm_ops); However this does not solve the problem as the inner request still takes a very long time. EXPLAIN ANALYSE SELECT t2.ref_id_t1 FROM table_2 t2 WHERE t2.c1_t2 LIKE '%abc%' Gives the following Bitmap Heap Scan on table_2 t2 (cost=664.20..189671.00 rows=65058 width=4) (actual...