X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6A2DF9DC823 for ; Tue, 28 Feb 2006 19:02:54 -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 33110-09 for ; Tue, 28 Feb 2006 19:02:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 0DD1D9DC806 for ; Tue, 28 Feb 2006 19:02:52 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 6E13D30C21; Wed, 1 Mar 2006 00:02:54 +0100 (MET) From: Lukas Smith X-Newsgroups: pgsql.hackers Subject: Re: [PERFORM] temporary indexes Date: Wed, 01 Mar 2006 00:02:55 +0100 Organization: Hub.Org Networking Services Lines: 30 Message-ID: <4404D69F.7000407@pooteeweet.org> References: <44041B68.EE98.0025.0@wicourts.gov> <20060228164515.GS82012@pervasive.com><20060228164515.GS82012@pervasive.com> <16076.1141146348@sss.pgh.pa.us> <44046913.EE98.0025.0@wicourts.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org To: Kevin Grittner User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <44046913.EE98.0025.0@wicourts.gov> To: pgsql-hackers@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.114 required=5 tests=[AWL=0.114] X-Spam-Score: 0.114 X-Spam-Level: X-Archive-Number: 200602/1247 X-Sequence-Number: 80385 Kevin Grittner wrote: > I rewrote the query to use IN predicates rather than EXISTS predicates, > and the cost estimates look like this: > > EXISTS, no index: 1.6 billion > EXISTS, with index: 0.023 billion > IN, no index: 13.7 billion > IN, with index: 10.6 billion > > At least for the two EXISTS cases, the estimates were roughly accurate. > These plans were run against the data after the fix, but analyze has > not been run since then, so the estimates should be comparable with the > earlier post. > > I'm not used to using the IN construct this way, so maybe someone can > spot something horribly stupid in how I tried to use it. I will have a look at your queries tomorrow. Some general advice (rdbms agnostic) on when to use IN and when to use EXISTS taken from "SQL performance tuning": - if the inner table has few rows and the outer has many then IN is preferred - if however you have a restrictive expression on the outer query you should preferr EXISTS - use NOT EXISTS instead of NOT IN (break out early) regards, Lukas