Re: LIKE and REGEX optimization

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: LIKE and REGEX optimization
Дата
Msg-id dcc563d10801151449t47aba4f4n49980389bc213a0f@mail.gmail.com
обсуждение исходный текст
Ответ на Re: LIKE and REGEX optimization  (Chris Browne <cbbrowne@acm.org>)
Ответы Re: LIKE and REGEX optimization
Список 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 по дате отправления: