The postgres trigram documentation states:
The pg_trgm module provides GiST and GIN index operator classes that allow you to create an index over a text column for the purpose of very fast similarity searches. These index types support the above-described similarity operators, and additionally support trigram-based index searches for LIKE, ILIKE, ~ and ~* queries.
and shows the following example:
SELECT t, word_similarity('word', t) AS sml
FROM test_trgm
WHERE 'word' <% t
ORDER BY sml DESC, t;
Awesome!
However, when running the following query:
SELECT *
FROM place
WHERE word_similarity(place.name, '__SOME_STRING__') > 0.5
The index that was created is not being used.
However, when using ILIKE
or the %>
operators, it does seem that the index is being used. Why is the index not used on the word_similarity
function?