0

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');
1
  • Unrelated to your problem, but: Postgres 9.3 is no longer supported you should plan an upgrade as soon as possible. Commented Jun 3, 2020 at 7:06

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

lower(online_description) = <constant> , any alternative to use this without indexing the lower(online_description)
No way. It cannot be done. Fix your query or fix the index.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.