Skip to content
Advertisement

Why is GIN trigram index not being used with ILIKE ANY clause?

I have a table with the following definition:

I want to search by partial overlap of any words in a query with any of most of the fields in the table. I have an index which I intent to use to speed up my search:

I fill my table up with realistic fake data, creating more than 100 000 rows. Then I want to see my index being used with a following query, using the exact same expression that I did when creating my index:

However what I see is simple sequential scan (even if I use set enable_seqscan = false):

But if I replace the whole ilike any ... clause of the previous query with something simple like ilike '%george%', the index is getting used and the query gets executed super fast. So why is my index not being used with ilike any clause?

I use PostgreSQL 11.2 on MacOS Mojave.

Advertisement

Answer

I have to admit I don’t understand why this is happening, but I was able to get it working by making the right-hand side of the ANY an array instead of a subquery using the ARRAY(<subselect>) form.

This is with enable_seqscan = off on pg 10.12 (all that I have available right now).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement