From: Mladen Gogala <mladen.gogala@vmsinfo.com>
To: Ãéùñãïò Âáëêáíáò <lebiathan@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: "SELECT .. WHERE NOT IN" query running for hours
Date: Mon, 10 Jan 2011 12:28:34 -0500
Message-ID: <4D2B41C2.8020605@vmsinfo.com> (raw)
In-Reply-To: <AANLkTimCc6U-xHigzNcjF3xABadg-yKV_1+kTqXRXhnL@mail.gmail.com>
References: <AANLkTi=ir8MdWX3ecbhfx3AFp1Uv7DWkLG68S26VLkRM@mail.gmail.com>
<4D2695C9.10204@vmsinfo.com>
<AANLkTimCc6U-xHigzNcjF3xABadg-yKV_1+kTqXRXhnL@mail.gmail.com>
Ãéùñãïò Âáëêáíáò wrote:
>
> Are there any particular semantics for the "NOT IN" statement that
> cause the correlated query to execute for every row of the outter
> query, as opposed to the "NOT EXISTS" ? Or are there any other
> practical reasons, related to "IN / NOT IN", for this to be happening?
> Or is it simply due to implementation details of each RDBMS? I guess
> the former (or the 2nd one), since, as you say, this is common in most
> databases, but I would most appreciate an answer to clarify this.
>
> Thanks again!
>
> Best regards,
> George
>
>
>
Well, I really hoped that Bruce, Robert or Greg would take on this one,
but since there are no more qualified takers, I'll take a shot at this
one. For the "NOT IN (result of a correlated sub-query)", the sub-query
needs to be executed for every row matching the conditions on the
driving table, while the !EXISTS is just a complement of join. It's
all in the basic set theory which serves as a model for the relational
databases.
--
Mladen Gogala
Sr. Oracle DBA
1500 Broadway
New York, NY 10036
(212) 329-5251
http://www.vmsinfo.com
The Leader in Integrated Media Intelligence Solutions
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: mladen.gogala@vmsinfo.com, lebiathan@gmail.com
Subject: Re: "SELECT .. WHERE NOT IN" query running for hours
In-Reply-To: <4D2B41C2.8020605@vmsinfo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox