Re: LIKE query on indexes

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Ibrahim Tekin <itekin(at)gmail(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: LIKE query on indexes
Date: 2006-02-21 16:42:24
Message-ID: 1140540144.5777.5.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, 2006-02-21 at 10:34, Alvaro Herrera wrote:
> Scott Marlowe wrote:
> > On Tue, 2006-02-21 at 09:57, Ibrahim Tekin wrote:
> > > hi,
> > > i have btree index on a text type field. i want see rows which starts
> > > with certain characters on that field. so i write a query like this:
> > >
> > > SELECT * FROM mytable WHERE myfield LIKE 'john%'
> > >
> > > since this condition is from start of the field, query planner should
> > > use index to find such elements but explain command shows me it will
> > > do a sequential scan.
> > >
> > > is this lack of a feature or i am wrong somewhere?
> >
> > This is an artifact of how PostgreSQL handles locales other than ASCII.
> >
> > If you want such a query to use an index, you need to back up your
> > database, and re-initdb with --locale=C as an argument.
>
> ... or you can choose to create an index with the text_pattern_ops
> operator class, which would be used in a LIKE constraint regardless of
> locale.
>
> http://www.postgresql.org/docs/8.1/static/indexes-opclass.html

Good point. I tend to view the world from the perspective of the 7.4
and before user...

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message mark 2006-02-21 17:40:48 Re: LIKE query on indexes
Previous Message Alvaro Herrera 2006-02-21 16:34:16 Re: LIKE query on indexes