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 700E99DC89F for ; Wed, 1 Feb 2006 18:13:01 -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 43723-07 for ; Wed, 1 Feb 2006 18:13:00 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.206]) by postgresql.org (Postfix) with ESMTP id F3B699DC871 for ; Wed, 1 Feb 2006 18:12:56 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 16so249888nzp for ; Wed, 01 Feb 2006 14:12:59 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=S8YyTTmzHdYM2Fre0FM2o/H5SOpgq6sZwC1cuM29NmHsJoMyatNn3Kk/GuhaP6HLID+oCinxHQr4mtTjachjEuyiOrd1YGdFT8EpslY7uOva2OUTXPUUXgdGyWySM0NCFlHLSi1KwWyBnRcN3PoKC7GGsNeexOHz7516zPqabWk= Received: by 10.64.10.17 with SMTP id 17mr24963qbj; Wed, 01 Feb 2006 14:12:59 -0800 (PST) Received: from ?64.161.133.227? ( [64.161.133.227]) by mx.gmail.com with ESMTP id f17sm581319qba.2006.02.01.14.12.58; Wed, 01 Feb 2006 14:12:58 -0800 (PST) Message-ID: <43E13266.2090101@gmail.com> Date: Wed, 01 Feb 2006 14:12:54 -0800 From: Hari Warrier User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: Ralph Mason CC: pgsql-performance@postgresql.org Subject: Re: Index Usage using IN References: <43E1164B.7020104@telogis.com> In-Reply-To: <43E1164B.7020104@telogis.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200602/35 X-Sequence-Number: 17021 Select ID from TableA where not exists ( Select ID from Table B where ID = TableA.ID) might give you index scan. Of course, that is only useful is TableA is very small table. Not appropriate for 250k rows on 2/1/2006 12:12 PM Ralph Mason said the following: > 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. > > Is there any way to force this? enable_seqscan off doesn't help at all. > > The Plan is > > Seq Scan on tablea(cost=100000000.00..23883423070450.96 rows=119414 > width=4) > Filter: (NOT (subplan))" > SubPlan -> Seq Scan on tableb (cost=100000000.00..100004611.17 > rows=242617 width=4) > > > Thanks > Ralph > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend >