Re: LIKE pattern

From: Robert Klemme <shortcutter(at)googlemail(dot)com>
To: pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: LIKE pattern
Date: 2016-05-12 15:13:18
Message-ID: CAM9pMnNXnF_uEiW76eLu6yEzizpjHvuMS3sxsxNKjXLbf0CDJg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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?

Kind regards

robert

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Jeff Janes 2016-05-12 17:02:04 Re: LIKE pattern
Previous Message SoDupuDupu 2016-05-09 21:41:06 Re: LIKE pattern