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 4B8919DC801 for ; Mon, 19 Dec 2005 16:54:39 -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 49821-05 for ; Mon, 19 Dec 2005 16:54:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by postgresql.org (Postfix) with ESMTP id 27FDE9DC810 for ; Mon, 19 Dec 2005 16:54:36 -0400 (AST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1EoS1d-0000QO-00; Mon, 19 Dec 2005 15:54:29 -0500 To: Carlos Benkendorf Cc: pgsql-performance@postgresql.org Subject: Re: Is the optimizer choice right? References: <20051219202258.30740.qmail@web35510.mail.mud.yahoo.com> In-Reply-To: <20051219202258.30740.qmail@web35510.mail.mud.yahoo.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 19 Dec 2005 15:54:29 -0500 Message-ID: <87r788ajui.fsf@stark.xeocode.com> Lines: 29 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200512/465 X-Sequence-Number: 16286 Carlos Benkendorf writes: > Hi, > > We´re running 8.03 and I´m trying to understand why the following SELECT doesn´t use iarchave05 index. > > If you disable seqscan then iarchave05 index is used and the total runtime > is about 50% less than when iarchave05 index is not used. > > Why is the optimizer not using iarchave05 index? The optimizer is calculating that the index scan would require more i/o than the sequential scan and be slower. The only reason it isn't is because most of the data is cached from your previous tests. If this test accurately represents the production situation and most of this data is in fact routinely cached then you might consider lowering the random_page_cost to represent this. The value of 4 is reasonable for actual i/o but if most of the data is cached then you effectively are getting something closer to 1. Try 2 or 1.5 or so. Note that the sequential scan has to scan the entire table. The index scan has to scan the entire table *and* the entire index, and in a pretty random order. If the table didn't fit entirely in RAM it would end up reading the entire table several times over. -- greg