I'm running the following query on a 'companies' table:
SELECT *
FROM companies
WHERE name ILIKE '%foo%'
AND (city ILIKE 'bar%' OR state ILIKE 'bar%')
I'm trying to use gin indexes, and I've added an indidivual index for name, city and state:
CREATE INDEX trgm_idx_companies_name ON companies USING gin (name gin_trgm_ops);
CREATE INDEX trgm_idx_companies_city ON companies USING gin (city gin_trgm_ops);
CREATE INDEX trgm_idx_companies_state ON companies USING gin (state gin_trgm_ops);
However, only the name index is used when running the query. I suspect the answer lies in a multi-column index but I can't get it to work no matter what variation I try.