Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id BF31A1337B98 for ; Sat, 6 Nov 2010 14:12:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 59851-02 for ; Sat, 6 Nov 2010 17:12:19 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 4AF3F1337B97 for ; Sat, 6 Nov 2010 14:12:19 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oA6HCILh021223; Sat, 6 Nov 2010 13:12:18 -0400 (EDT) To: David W Noon cc: pgsql-admin@postgresql.org Subject: Re: Interesting Query Performance Question In-reply-to: <20101106165354.67ed9532@karnak.local> References: <68C107706843A54BA7D9CAEF123ADF05010346CAE6@SP2-EX07VS03.ds.corp.yahoo.com> <20024.1289059188@sss.pgh.pa.us> <20101106165354.67ed9532@karnak.local> Comments: In-reply-to David W Noon message dated "Sat, 06 Nov 2010 16:53:54 -0000" Date: Sat, 06 Nov 2010 13:12:18 -0400 Message-ID: <21222.1289063538@sss.pgh.pa.us> From: Tom Lane 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: 201011/57 X-Sequence-Number: 36023 David W Noon writes: > On Sat, 06 Nov 2010 11:59:48 -0400, Tom Lane wrote about Re: [ADMIN] >> In general, NOT IN is hard to optimize because of its weird behavior >> for NULLs. I'd suggest looking into converting the query to use an >> EXISTS instead. > I have know about that issue for some years, so I always use a column > that has been declared NOT NULL for the sub-query. Does PostgreSQL not > use that property to bypass the vagaries of NULL in an IN predicate? No. It's a reasonable TODO item though. Up till fairly recently, we didn't have infrastructure that would allow building plans that depended for correctness on the existence of a constraint. (In particular, I'd want such a plan to get thrown away and redone if someone dropped the NOT NULL constraint.) We have most of that now, although it only works for constraints that have entries in pg_constraint, which NOT NULL doesn't yet. Maybe in another few months ... regards, tom lane