Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 153911337B4A for ; Mon, 10 Jan 2011 13:28:43 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 56179-01 for ; Mon, 10 Jan 2011 17:28:36 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lpo-relay-05.vmsinfo.com (lpo-relay-05.vmsinfo.com [216.169.137.116]) by mail.postgresql.org (Postfix) with ESMTP id B06F21336971 for ; Mon, 10 Jan 2011 13:28:35 -0400 (AST) X-IronPort-AV: E=Sophos;i="4.60,302,1291611600"; d="scan'208";a="31146768" Received: from unknown (HELO lpo-mailbox-02.vmsinfo.com) ([216.169.137.252]) by lpo-relay-05.vmsinfo.com with ESMTP; 10 Jan 2011 12:28:34 -0500 Received: from [10.101.43.35] (lpo-autonomy-p03.vmsinfo.com [216.169.135.234]) by lpo-mailbox-02.vmsinfo.com (Postfix) with ESMTP id 8625856258; Mon, 10 Jan 2011 12:28:34 -0500 (EST) Message-ID: <4D2B41C2.8020605@vmsinfo.com> Date: Mon, 10 Jan 2011 12:28:34 -0500 From: Mladen Gogala Organization: VMS User-Agent: Thunderbird 2.0.0.24 (X11/20101027) MIME-Version: 1.0 To: =?ISO-8859-7?Q?=C3=E9=F9=F1=E3=EF=F2_=C2=E1=EB=EA=E1=ED=E1=F2?= CC: "pgsql-performance@postgresql.org" Subject: Re: "SELECT .. WHERE NOT IN" query running for hours References: <4D2695C9.10204@vmsinfo.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-7; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201101/56 X-Sequence-Number: 41843 Γιωργος Βαλκανας 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