Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id E6C3D9F992F for ; Fri, 21 Sep 2007 14:40:44 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 07623-08 for ; Fri, 21 Sep 2007 14:40:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from outmail136081.authsmtp.net (outmail136081.authsmtp.net [62.13.136.81]) by postgresql.org (Postfix) with ESMTP id 98D649F991A for ; Fri, 21 Sep 2007 14:40:38 -0300 (ADT) Received: from outmail128183.authsmtp.com (outmail128183.authsmtp.com [62.13.128.183]) by punt2.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id l8LHeZRn092755; Fri, 21 Sep 2007 18:40:35 +0100 (BST) Received: from [192.168.0.3] (85-211-21-1.dyn.gotadsl.co.uk [85.211.21.1]) (authenticated bits=0) by mail.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id l8LHeVFk059017; Fri, 21 Sep 2007 18:40:32 +0100 (BST) Subject: Re: Searching for the cause of a bad plan From: Simon Riggs To: Tom Lane Cc: Csaba Nagy , postgres performance list In-Reply-To: <6175.1190390913@sss.pgh.pa.us> References: <1190369024.4661.173.camel@PCD12478> <6175.1190390913@sss.pgh.pa.us> Content-Type: text/plain Date: Fri, 21 Sep 2007 18:39:12 +0100 Message-Id: <1190396352.4202.109.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Content-Transfer-Encoding: 7bit X-Server-Quench: c071190b-6869-11dc-b86a-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadRtFagRbflxB HGQLW1NEUVV7XWN/ aAgfZQBDYEtPQQdr TklWQFdNFEs0CWB5 U3hoCRl3fgVHfzBx ZENgECNbW0V7fEYv X0hcE2QbZGY0O31N WEYJagNUcQJCe0tG bVcsBT1vNG8XDRoV JSEUBRUEdQ5SIT5e QgALIhocRlxDAj4x DxsLAC4iVUoLDyx7 JRUqYkYYFUB5 X-Authentic-SMTP: 61633235383639.squirrel.dmpriest.net.uk:752/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/373 X-Sequence-Number: 26918 On Fri, 2007-09-21 at 12:08 -0400, Tom Lane wrote: > 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: That's true, but its not relevant, since the query would still be fast even if that estimate was exactly right. With LIMIT 10, it wouldn't matter how many rows were there as long as there were more than 10. The true execution cost is limited, the cost model is not. -- Simon Riggs 2ndQuadrant http://www.2ndQuadrant.com