Re: index usage in not like

From: Thom Brown <thombrown(at)gmail(dot)com>
To: AI Rumman <rummandba(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: index usage in not like
Date: 2010-02-18 12:14:03
Message-ID: bddc86151002180414s2b080e5ar6d1054027fb9e047@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> On Thu, Feb 18, 2010 at 6:00 PM, Thom Brown <thombrown(at)gmail(dot)com> wrote:
>>
>> On 18 February 2010 11:55, AI Rumman <rummandba(at)gmail(dot)com> wrote:
>> > "Not like" operation does not use index.
>> >
>> > select * from vtiger_contactscf where lower(cf_1253) not like
>> > lower('Former%')
>> >
>> > I created index on lower(cf_1253).
>> >
>> > How can I ensure index usage in not like operation?
>> > Anyone please help.
>> >
>>
>> How many rows do you have in your table?  If there are relatively few,
>> it probably guesses it to be cheaper to do a sequential scan and
>> calculate lower values on-the-fly rather than bother with the index.
>>
>> Thom
>
On 18 February 2010 12:06, AI Rumman <rummandba(at)gmail(dot)com> wrote:
> vtigercrm504=# explain analyze select * from vtiger_contactscf where
> lower(cf_1253) like 'customer';
>
> QUERY
> PLAN
> ------------------------------------------------------------------------------------------------------------------------------------------------------------
> Index Scan using vtiger_contactscf_cf_1253_idx on vtiger_contactscf
> (cost=0.00..146.54 rows=6093 width=179) (actual time=0.083..29.868 rows=5171
> loops=1)
> Index Cond: (lower((cf_1253)::text) ~=~ 'customer'::character varying)
> Filter: (lower((cf_1253)::text) ~~ 'customer'::text)
> Total runtime: 34.956 ms
> (4 rows)
> vtigercrm504=# explain analyze select * from vtiger_contactscf where
> lower(cf_1253) like 'customer';
>
> QUERY
> PLAN
> ------------------------------------------------------------------------------------------------------------------------------------------------------------
> Index Scan using vtiger_contactscf_cf_1253_idx on vtiger_contactscf
> (cost=0.00..146.54 rows=6093 width=179) (actual time=0.083..29.868 rows=5171
> loops=1)
> Index Cond: (lower((cf_1253)::text) ~=~ 'customer'::character varying)
> Filter: (lower((cf_1253)::text) ~~ 'customer'::text)
> Total runtime: 34.956 ms
> (4 rows)

Could you do the same again for a "not like" query?

Thom

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message A. Kretschmer 2010-02-18 12:18:10 Re: index usage in not like
Previous Message Thom Brown 2010-02-18 12:00:29 Re: index usage in not like