Re: [GENERAL] tgrm index for word_similarity
От | Igal @ Lucee.org |
---|---|
Тема | Re: [GENERAL] tgrm index for word_similarity |
Дата | |
Msg-id | 899e0c6c-6560-adcc-db72-59c5d068eb6c@lucee.org обсуждение исходный текст |
Ответ на | Re: [GENERAL] tgrm index for word_similarity (Arthur Zakirov <a.zakirov@postgrespro.ru>) |
Ответы |
Re: [GENERAL] tgrm index for word_similarity
|
Список | pgsql-general |
PostgreSQL doesn't use index scan with functions within WHERE clause. So you always need to use operators instead. You can try <% operator and pg_trgm.word_similarity_threshold variable: =# SET pg_trgm.word_similarity_threshold TO 0.1; =# SELECT name, popularityFROM temp.items3_v ,(values ('some phrase'::text)) consts(input)WHERE input <% nameORDER BY 2, input <<-> name;
Thank you, your solution does show that the index is used when I do `explain analyze`, and makes the query finish in about 20ms so it's about 1.5 - 2 times faster than without the index, but that raises a few questions for me:
1) I thought that the whole idea behind indexes on expressions is that the index would be used in a WHERE clause? See https://www.postgresql.org/docs/10/static/indexes-expressional.html - Am I missing something?
2) A query with `WHERE input <% name` utilizes the index, but a query without a WHERE clause at all does not?
3) What happens if I do not create an index at all? Does the query that I run in 30 - 40ms, the one that does not utilize an index, creates all of the tri-grams on the fly each time that it runs? Would it be possible for me to create a TABLE or a VIEW with the tri-grams so that there is no need to create them each time the query runs?
Thanks,
Igal Sapir
Lucee Core Developer
Lucee.org
В списке pgsql-general по дате отправления: