Re: Alternative to INTERSECT

Поиск
Список
Период
Сортировка
От Josh Trutwin
Тема Re: Alternative to INTERSECT
Дата
Msg-id 20070731135222.394da3dd@sinkhole.intrcomm.net
обсуждение исходный текст
Ответ на Alternative to INTERSECT  (Andreas Joseph Krogh <andreak@officenet.no>)
Ответы Re: Alternative to INTERSECT  (Andreas Joseph Krogh <andreak@officenet.no>)
Список pgsql-sql
On Tue, 31 Jul 2007 17:30:51 +0000
Andreas Joseph Krogh <andreak@officenet.no> wrote:

> Hi all. I have the following schema:
> 
> CREATE TABLE test (
>     id integer NOT NULL,
>     field character varying NOT NULL,
>     value character varying NOT NULL
> );
> 
> ALTER TABLE ONLY test
>     ADD CONSTRAINT test_id_key UNIQUE (id, field, value);
> 
> CREATE INDEX test_like_idx ON test USING btree (id, field, value 
> varchar_pattern_ops);
> 
> Using INTERSECT I want to retrieve the rows matching (pseudo-code)
> "firstname LIKE ('andrea%' OR 'jose%') AND lastname LIKE 'kro%'"

Why not:

WHERE (t.field = lastname AND t.value LIKE 'kro%')  OR (t.field = firsname AND (      t.value LIKE 'jose%' OR t.value
LIKE'andrea%')      )
 

Not tested.  If you're having performance problems is probably less
like that the INTERSECT is the problem with all those LIKE's in
there?  Is t.value indexed?

Josh


В списке pgsql-sql по дате отправления:

Предыдущее
От: Andreas Joseph Krogh
Дата:
Сообщение: Alternative to INTERSECT
Следующее
От: "Jon Horsman"
Дата:
Сообщение: Re: Connection Limit