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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Loles <lolesft@xxxxxxxxx> writes:
> 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.

Presumably, that works well because you have a btree index on UPPER(name).
But btree can't optimize a pattern with a leading '%' --- see

https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-BTREE

You could possibly use a pg_trgm index instead, see

https://www.postgresql.org/docs/current/pgtrgm.html

The performance properties will be somewhat different from btree,
but it might get the job done.

			regards, tom lane





[Index of Archives]     [Postgresql Home]     [Postgresql General]     [Postgresql Performance]     [Postgresql PHP]     [Postgresql Jobs]     [PHP Users]     [PHP Databases]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Forum]

  Powered by Linux