RE: Optimized WHERE UPPER(name) LIKE UPPER('%p_name%')

From: HALAT-PRUVOT SYLVIE <sylvie(dot)halat-pruvot(at)region-academique-occitanie(dot)fr>
To: Loles <lolesft(at)gmail(dot)com>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: RE: Optimized WHERE UPPER(name) LIKE UPPER('%p_name%')
Date: 2023-10-30 13:39:50
Message-ID: 1c16db2fbba145dd900f0fe14849bf99@region-academique-occitanie.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi,

You can try with extension pg_tgrm to create gin index to use LIKE with ‘%expression%’

https://www.postgresql.org/docs/current/pgtrgm.html
https://mazeez.dev/posts/pg-trgm-similarity-search-and-fast-like

Sylvie Halat
De : Loles <lolesft(at)gmail(dot)com>
Envoyé : lundi 30 octobre 2023 14:28
À : pgsql-admin(at)postgresql(dot)org
Objet : Optimized WHERE UPPER(name) LIKE UPPER('%p_name%')

Hi!

A question about query optimization.

We have a simple query with several tables joined.

We have seen performance down when we use WHERE UPPER(name) LIKE UPPER('%Alice%') in the condition.

If we compare with WHERE UPPER(name) = UPPER('Alice') it runs very fast.

We have tried an index on the name field, an UPPER(name) expression index, a GIN index, etc. but nothing seems to work.

We need to optimize the condition WHERE UPPER(name) LIKE UPPER('%p_name%)
Any ideas?

Thanks!!

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Ron 2023-10-30 13:42:19 Re: AUTOVACUUM
Previous Message SOzcn 2023-10-30 13:34:07 Re: On Replica - History issue