Re: Query plan and sub-queries

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: Steve Heaven <steve(at)thornet(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Query plan and sub-queries
Date: 2000-08-08 12:24:28
Message-ID: 398FFBFC.65E69E05@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Steve Heaven wrote:
>
> When the WHERE clause includes a sub query the query plan seems to ignore
> indexes.

This is a FAQ:

4.23) Why are my subqueries using IN so slow?

Currently, we join subqueries to outer queries by sequential
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.

Hope that helps,

Mike Mascari

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Philip Warner 2000-08-08 12:29:17 RE: pg_dump help
Previous Message Robert D. Nelson 2000-08-08 12:18:00 RE: pg_dump help

Browse pgsql-hackers by date

  From Date Subject
Next Message Steve Heaven 2000-08-08 12:47:34 Re: Query plan and sub-queries
Previous Message Steve Heaven 2000-08-08 11:22:12 Query plan and sub-queries