X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 53B899DCDF2 for ; Wed, 1 Feb 2006 17:15:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33761-09 for ; Wed, 1 Feb 2006 17:15:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from wolff.to (wolff.to [66.93.197.194]) by postgresql.org (Postfix) with SMTP id 52FF39DCDE3 for ; Wed, 1 Feb 2006 17:15:12 -0400 (AST) Received: (qmail 2867 invoked by uid 500); 1 Feb 2006 21:23:03 -0000 Date: Wed, 1 Feb 2006 15:23:03 -0600 From: Bruno Wolff III To: Ralph Mason Cc: pgsql-performance@postgresql.org Subject: Re: Index Usage using IN Message-ID: <20060201212303.GA1212@wolff.to> Mail-Followup-To: Bruno Wolff III , Ralph Mason , pgsql-performance@postgresql.org References: <43E1164B.7020104@telogis.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43E1164B.7020104@telogis.com> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200602/32 X-Sequence-Number: 17018 On Thu, Feb 02, 2006 at 09:12:59 +1300, Ralph Mason wrote: > Hi, > > I have 2 tables both have an index on ID (both ID columns are an oid). > > I want to find only only rows in one and not the other. > > Select ID from TableA where ID not IN ( Select ID from Table B) > > This always generates sequential scans. > > Table A has about 250,000 rows. Table B has about 250,000 Rows. > > We should get a Scan on Table B and a Index Lookup on Table A. I don't think that is going to work if there are NULLs in table B. I don't know whether or not Postgres has code to special case NULL testing (either for constraints ruling them out, or doing probes for them in addition to the key it is trying to match) for doing NOT IN. Just doing a simple index probe into table A isn't going to tell you all you need to know if you don't find a match.