Re: JOIN vs. WHERE ... IN (subselect)

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: JOIN vs. WHERE ... IN (subselect)
Дата
Msg-id 20030517090929.M99020-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на JOIN vs. WHERE ... IN (subselect)  ("Dean Gibson (DB Administrator)" <dba-sql@ultimeth.net>)
Список pgsql-sql
On Fri, 16 May 2003, Dean Gibson (DB Administrator) wrote:

> Using PostgreSQL 7.3.2 on Linux.
>
> One of the types of queries that I like to do on our database is:
>
> SELECT * FROM table1
>     WHERE indexed_column1 IN
>     (SELECT column2 FROM table2 WHERE <condition>);
>
> However, my third-party SQL book says that the above is equivalent to:
>
> SELECT table1.* FROM table1, table2
>     WHERE indexed_column1 = column2 AND <condition>;
>
> And indeed, the above query executes virtually instantaneously if
> "<condition>" results in a small number of rows from table2.
>
> I'm fairly new to SQL;  are they really equivalent?  If so, is there
> some reason that the first form is not optimized/transformed into the
> second form, or is this a planned enhancement?

7.4 already handles IN differently than previous versions and should
runs queries like the first one better than current versions.

And those two queries are not equivalent in any case unless the subselect
is guaranteed to only have one matching row (or you use a distinct in the
second query).



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

Предыдущее
От: "Dean Gibson (DB Administrator)"
Дата:
Сообщение: Re: JOIN vs. WHERE ... IN (subselect)
Следующее
От: "Terry Yapt"
Дата:
Сообщение: COALESCE in ORDER BY...