Re: LIKE and REGEX optimization - Mailing list pgsql-general

From Scott Marlowe
Subject Re: LIKE and REGEX optimization
Date
Msg-id dcc563d10801151449t47aba4f4n49980389bc213a0f@mail.gmail.com
Whole thread Raw
In response to Re: LIKE and REGEX optimization  (Chris Browne <cbbrowne@acm.org>)
Responses Re: LIKE and REGEX optimization
List pgsql-general
On Jan 15, 2008 2:29 PM, Chris Browne <cbbrowne@acm.org> wrote:
> Kico Zaninetti <kicozaninetti@gmail.com> writes:
> > Hi all.
> >
> > I have a database with 62 million registers and I have to make a
> > SELECT using LIKE.
> >
> > This is my select:
> > SELECT * FROM phone WHERE name LIKE = '%ZANINETTI%' AND city = 'SAO
> > PAULO' AND state = 'SP'

This query is not capable of using an index on name, since you can't
use an index with a like beginning with a %... So

> > I have an index created like this:
> > CREATE INDEX "telefones_idx2" ON "public"."phone"
> >   USING btree ("name" varchar_pattern_ops, "city", "state");

This index serves no purpose, because they get used left to right.
Since you can't match name, the other two parts aren't used.

Does the OP have an index on city,state?  That might help.

pgsql-general by date:

Previous
From: Erik Jones
Date:
Subject: Re: Clearing old user ids completely
Next
From: Justin Pasher
Date:
Subject: Re: Clearing old user ids completely