Re: index not used with subselect in where clause ?

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: index not used with subselect in where clause ?
Дата
Msg-id Pine.BSF.4.21.0104161028510.71895-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на index not used with subselect in where clause ?  (Christian Fritze <The.Finn@sprawl.de>)
Ответы Re: index not used with subselect in where clause ?  (Christian Fritze <The.Finn@sprawl.de>)
Список pgsql-general
On Mon, 16 Apr 2001, Christian Fritze wrote:

>   SELECT attr1 FROM table1 WHERE attr1 IN (<list of ints>)
>                              AND <more conditions>;
>
> where <list of ints> is entered explicitly (or generated by a
> program) everything works fine and fast using the index on attr1.
>
> But when I try doing a
>
>   SELECT attr1 FROM table1 WHERE attr1 IN (<SUBSELECT returning list of ints>)
>                              AND <more conditions>;
>
> then the SELECT on table1 uses a sequential scan running 'endlessly'.

From the FAQ:

4.23) Why are my subqueries using IN so slow?

Currently, we join subqueries to outer queries by sequentially scanning
the result of the subquery for each row of the outer query. A workaround
is to replace IN with EXISTS:

SELECT *
    FROM tab
    WHERE col1 IN (SELECT col2 FROM TAB2)


to:
SELECT *
    FROM tab
    WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2)


We hope to fix this limitation in a future release.


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

Предыдущее
От: Christian Fritze
Дата:
Сообщение: index not used with subselect in where clause ?
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: bpchar type