I want to use pg_trgm for auto-suggest functionality. I created
a Materialized View with the information that I need, with the
relevant columns being (keywords text, rank int). keywords is the
column from which I build the tri-grams, and rank is some
popularity factor so that popular results will show up higher than
less popular results given the same tri-gram distance. I want to return results in the order of [distance],
[distance_word], [rank]. The input comes from the user and is not
known in advance. My query is as follows: SELECT title This gives me pretty good results, but it takes too long and is not likely to scale well. I have created two indexes but neither seem to be used: CREATE INDEX mv_autosuggest_keywords_tgrm_gist ON
staging.mv_autosuggest USING gist (keywords gist_trgm_ops); This is the result of explain analyze: QUERY
PLAN
| How can I improve the performance here? Thank you, Igal Sapir
|