For eg:
If lower function is removed, the query performance is better than using lower. Using lower skips the index. Is
SELECT X.article_number, X.online_description
FROM articles X
WHERE LOWER(X.online_description) % usp_get_search_terms ('coke');
For eg:
If lower function is removed, the query performance is better than using lower. Using lower skips the index. Is
SELECT X.article_number, X.online_description
FROM articles X
WHERE LOWER(X.online_description) % usp_get_search_terms ('coke');
An index can only be used to speed up a WHERE condition if the condition is of the following form:
<indexed expression> <operator> <constant>
Here <operator> must be an operator in the operator class of the index, and <constant> need not really be a constant, but fixed for the duration of the index scan.
I assume that % is the similarity operator from the pg_trgm extension. Then you need either a GIN index with the gin_trgm_ops operator class or a GiST index with the gist_trgm_ops operator class.
Since trigram operations are case insensitive anyway, you should remover the lower() from the query. Otherwise, you'd have to create the index on lower(online_description), which would be a waste of CPU.