Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 526369F9A27 for ; Fri, 21 Sep 2007 13:08:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 70739-09 for ; Fri, 21 Sep 2007 13:08:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 077549F9A26 for ; Fri, 21 Sep 2007 13:08:37 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l8LG8Yn2006176; Fri, 21 Sep 2007 12:08:34 -0400 (EDT) To: Csaba Nagy cc: postgres performance list Subject: Re: Searching for the cause of a bad plan In-reply-to: <1190369024.4661.173.camel@PCD12478> References: <1190369024.4661.173.camel@PCD12478> Comments: In-reply-to Csaba Nagy message dated "Fri, 21 Sep 2007 12:03:44 +0200" Date: Fri, 21 Sep 2007 12:08:33 -0400 Message-ID: <6175.1190390913@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/369 X-Sequence-Number: 26914 Csaba Nagy writes: > Looking at Plan 2, it looks like the "limit" step is estimating wrongly > it's cost. The reason you get a bad plan is that this rowcount estimate is so far off: > -> Index Scan using pk_table_a on table_a ta (cost=0.00..324786.18 rows=388532 width=16) (actual time=454.389..460.138 rows=2 loops=1) > Index Cond: (a = $1) Raising the stats target helped no doubt because it didn't overestimate the number of rows so much... regards, tom lane