From: | Jeff Janes <jeff(dot)janes(at)gmail(dot)com> |
---|---|
To: | Loles <lolesft(at)gmail(dot)com> |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: Optimized WHERE UPPER(name) LIKE UPPER('%p_name%') |
Date: | 2023-10-30 14:11:55 |
Message-ID: | CAMkU=1ykvx7x-ezab-hukCM9EXOa0X9DdaX+GFdU+McKhGAY3w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On Mon, Oct 30, 2023 at 9:28 AM Loles <lolesft(at)gmail(dot)com> wrote:
> 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.
>
A gin_trgm_ops expression index on UPPER(name) should work. We can't tell
if that is one of the things you tried.
But it would probably be better to use ILIKE and omit the UPPER calls, in
which case a gin_trgm_ops index on the column itself should work.
Cheers,
Jeff
>
From | Date | Subject | |
---|---|---|---|
Next Message | Dan Smith | 2023-10-30 14:29:17 | Re: Optimized WHERE UPPER(name) LIKE UPPER('%p_name%') |
Previous Message | Tom Lane | 2023-10-30 14:08:20 | Re: Optimized WHERE UPPER(name) LIKE UPPER('%p_name%') |