Re: LIKE query on indexes - Mailing list pgsql-performance

From Alvaro Herrera
Subject Re: LIKE query on indexes
Date
Msg-id 20060221163416.GC6541@surnet.cl
Whole thread Raw
In response to Re: LIKE query on indexes  (Scott Marlowe <smarlowe@g2switchworks.com>)
Responses Re: LIKE query on indexes
Re: LIKE query on indexes
List pgsql-performance
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

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

pgsql-performance by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: LIKE query on indexes
Next
From: Scott Marlowe
Date:
Subject: Re: LIKE query on indexes