Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id A433D64FCD4 for ; Thu, 31 Jul 2008 00:26:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 77646-09 for ; Thu, 31 Jul 2008 00:25:46 -0300 (ADT) X-Greylist: delayed 00:05:51.239347 by SQLgrey-1.7.6 Received: from polica.at.xencon.net (polica.at.xencon.net [83.246.72.208]) by postgresql.org (Postfix) with ESMTP id DBCCD64FCBF for ; Thu, 31 Jul 2008 00:24:29 -0300 (ADT) Received: from apn-77-113-78-203.gprs.plus.pl ([77.113.78.203]:59009 helo=tarnica) by polica.at.xencon.net with esmtp (Exim 4.69) (envelope-from ) id 1KOOgQ-0001Gw-RK for pgsql-performance@postgresql.org; Thu, 31 Jul 2008 05:18:31 +0200 Received: from miernik by tarnica with local (Exim 4.69) (envelope-from ) id 1KOOgI-0000E7-RI for pgsql-performance@postgresql.org; Thu, 31 Jul 2008 05:18:23 +0200 Received: by tarnica (hashcash-sendmail, from uid 1000); Thu, 31 Jul 2008 05:18:22 +0200 Date: Thu, 31 Jul 2008 05:18:22 +0200 From: Miernik To: pgsql-performance@postgresql.org Subject: Re: why "WHERE uid NOT IN" is so slow, and EXCEPT in the same situtation is fast? Message-ID: <20080731031822.GA813@tarnica> References: <20080731024508.53F6.0.NOFFLE@turbacz.local> <27820.1217473686@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <27820.1217473686@sss.pgh.pa.us> X-Archive: encrypt=none X-Operating-System: Debian GNU/Linux User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200807/266 X-Sequence-Number: 30866 On Wed, Jul 30, 2008 at 11:08:06PM -0400, Tom Lane wrote: > Hmm, what have you got work_mem set to? The first one would likely > have been a lot faster if it had hashed the subplan; which I'd have > thought would happen with only 80K rows in the subplan result, > except it didn't. work_mem = 1024kB The machine has 48 MB total RAM and is a Xen host. > The queries are in fact not exactly equivalent, because EXCEPT > involves some duplicate-elimination behavior that won't happen > in the NOT IN formulation. So I don't apologize for your having > gotten different plans. But if use EXCEPT ALL? > Another issue is that the NOT IN will probably not do what you > expected if the subquery yields any NULLs. In this specific query I think it is not possible for the subquery to have NULLs, because its an INNER JOIN USING (the_only_column_in_the _result, some_other_column_also). If any "uid" column of any row would have been NULL, it wouldn't appear in that INNER JOIN, no? -- Miernik http://miernik.name/