| From: | Jeff Janes <jeff(dot)janes(at)gmail(dot)com> |
|---|---|
| To: | Robert Klemme <shortcutter(at)googlemail(dot)com> |
| Cc: | pgsql-performance <pgsql-performance(at)postgresql(dot)org> |
| Subject: | Re: LIKE pattern |
| Date: | 2016-05-12 17:02:04 |
| Message-ID: | CAMkU=1wTy3fVdn9ZSGm_yJmVFqP4ZNLmrqu_mJK7rSECaHQVyA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-performance |
On Thu, May 12, 2016 at 8:13 AM, Robert Klemme
<shortcutter(at)googlemail(dot)com> wrote:
> On Mon, May 9, 2016 at 11:41 PM, SoDupuDupu wrote:
>> Владимир-3 wrote
>>> It seems my quite complex query runs 10 times faster on "some_column
>>> LIKE '%test_1' " vs "some_column LIKE 'test_1' "
>>> So I just add "%" to the pattern...
>>
>> Keep in mind then LIKE '%test_1' and LIKE 'test_1' are not equivalent, using
>> the % as a prefix to the argument means that the scan only has to confirm
>> that the value ends in 'test_1' where forgoing the % entirely means that you
>> are essentially saying some_column='test_1'.
>
> Yes, but wouldn't the latter test be more efficient usually since it
> tests against a prefix - at least with a regular index?
In theory. But the planner is imperfect, and they will have different
estimated selectivities which could easily tip the planner into making
a poor choice for the more selective case. Without seeing the plans,
it is hard to say much more.
Cheers,
Jeff
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2016-05-12 17:25:25 | Re: LIKE pattern |
| Previous Message | Robert Klemme | 2016-05-12 15:13:18 | Re: LIKE pattern |