From: | "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> |
---|---|
To: | "Chris Browne" <cbbrowne(at)acm(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: LIKE and REGEX optimization |
Date: | 2008-01-15 22:49:41 |
Message-ID: | dcc563d10801151449t47aba4f4n49980389bc213a0f@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Jan 15, 2008 2:29 PM, Chris Browne <cbbrowne(at)acm(dot)org> wrote:
> Kico Zaninetti <kicozaninetti(at)gmail(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Justin Pasher | 2008-01-15 22:53:26 | Re: Clearing old user ids completely |
Previous Message | Hannes Dorbath | 2008-01-15 22:42:22 | Re: Segmentation fault with 8.3 FTS ISpell |