From: | Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> |
---|---|
To: | Dan Graham <graham(at)molbio(dot)uoregon(dot)edu> |
Cc: | PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: [PATCHES] LIKE vs regex queries |
Date: | 2004-04-07 07:26:48 |
Message-ID: | Pine.LNX.4.58.0404070907140.9008@sablons.cri.ensmp.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-patches |
> I have a database with about 250,000 entries in a table, PG 7.5, One
> of the fields is text. LIKE queries on this field execute much faster
> than the equivalent regex queries.
>
> Is this what you would expect? Should I prefer LIKE to regex?
> (I'm a regex fan, but the performance hit seems steep.)
>
> I've pasted sample output in below.
>
> order=# select dnum from item where description LIKE '%Ushio%';
> Time: 855.540 ms
>
> order=# select dnum from item where description ~ 'Ushio';
> Time: 2409.043 ms
From the source code, the computed automaton for ~ seems to be cached, so
this is not an explanation. However the RE engine is quite generic.
The code for LIKE is quite hardwired to the special case, as there is only
_ and % to be taken care of.
So it seems that if a LIKE regular expression is enough, then it is a much
better choice. SIMILAR TO is translated to ~, so it should be slow.
--
Fabien Coelho - coelho(at)cri(dot)ensmp(dot)fr
From | Date | Subject | |
---|---|---|---|
Next Message | Karel Zak | 2004-04-07 07:33:17 | Re: union vs. sort |
Previous Message | Tom Lane | 2004-04-07 05:55:02 | Re: Small suggestion on build script |
From | Date | Subject | |
---|---|---|---|
Next Message | Ludek Finstrle | 2004-04-07 08:31:59 | Re: WIN32 psql Ctrl+C support |
Previous Message | Bruce Momjian | 2004-04-07 05:05:51 | Re: [HACKERS] logging statement levels |