From: | Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my> |
---|---|
To: | David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Can LIKE use indexes or not? |
Date: | 2004-02-05 09:43:31 |
Message-ID: | 5.2.0.9.1.20040205173614.02547bb0@mbox.jaring.my |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
If you use an exact = does it use the index?
e.g. explain select ... where lower(f)='xxxxxxxx'
If so it could be your locale setting. On some versions of Postgresql like
is disabled on non-C locales. On some versions of Postgresql on some
platforms the default is a non-C locale. With version 7.4 you can
workaround that:
http://www.postgresql.org/docs/current/static/indexes-opclass.html
Hope that helps,
At 03:30 PM 2/5/2004 +0700, David Garamond wrote:
>Reading the archives and the FAQ, it seems to be implied that LIKE can use
>index (and ILIKE can't; so to do case-insensitive search you need to
>create a functional index on LOWER(field) and say: LOWER(field) LIKE 'foo%').
>
>However, EXPLAIN always says seq scan for the test data I'm using. I've
>done 'set enable_seqscan to off' and it still says seq scan. I was curious
>as to how the index will help this query:
>
>db1=> set enable_seqscan to off;
>SET
>Time: 5.732 ms
>db1=> explain select * from t where f like 'xx%';
> QUERY PLAN
>-------------------------------------------------------------------
> Seq Scan on t (cost=100000000.00..100002698.90 rows=89 width=14)
> Filter: (f ~~ 'xx%'::text)
>(2 rows)
>
>db1=> explain select * from t where lower(f) like 'xx%';
> QUERY PLAN
>--------------------------------------------------------------------
> Seq Scan on t (cost=100000000.00..100002893.68 rows=390 width=14)
> Filter: (lower(f) ~~ 'xx%'::text)
>(2 rows)
From | Date | Subject | |
---|---|---|---|
Next Message | Carlos Ojea Castro | 2004-02-05 09:48:41 | Proper tool to display graphics? |
Previous Message | Jan Poslusny | 2004-02-05 09:22:29 | Re: Can LIKE use indexes or not? |