I'm doing a pattern matching search with ILIKE in our system, but it gets too slow with some tables due to the amount of records in the table. So I'm implementing trigram index following instructions in this post https://www.depesz.com/2011/02/19/waiting-for-9-1-faster-likeilike/. I'm not using full text search because I need searchs like '%xxx%' and full text search does not work well with that. The test table has 16000 records and I have created a new column in the table for the search concatenating some other columns.
I've run some test and this are de results:
SELECT * FROM "table" WHERE "searchField" ILIKE '%ose%'
NO INDEX 1639 rows 30.3 sec. avg.
GIN INDEX 1639 rows 26.4 sec. avg.
SELECT * FROM "table" WHERE "searchField" ILIKE '%ose%' OR "searchField" ILIKE '%ria%'
NO INDEX 1639 rows 3:02 min. avg.
GIN INDEX 1639 rows 2.56 min. avg.
As you can see it's not a great inprovement, the post said that query time reduce to miliseconds. The explain analyze shows this:
Bitmap Heap Scan on "table" (cost=22.31..1827.93 rows=1331 width=511)
(actual time=0.354..4.644 rows=1639 loops=1)
Recheck Cond: (("searchField")::text ~~* '%ose%'::text)
Heap Blocks: exact=585
-> Bitmap Index Scan on "table_trgm_gin" (cost=0.00..21.98 rows=1331 width=0)
(actual time=0.276..0.276 rows=1639 loops=1)
Index Cond: (("searchField")::text ~~* '%ose%'::text)
The index scan is fast but the condition recheck is too slow. I have read that rechecking is unavoidable due to false positives posibilities. But then I don´t know how to get better results.
Can anyone explain why the index does not make much of a difference and how to get better query times?