Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 64D309FB3BB for ; Wed, 10 Oct 2007 16:52:29 -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 77325-03 for ; Wed, 10 Oct 2007 16:52:23 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from outmail136082.authsmtp.co.uk (outmail136082.authsmtp.co.uk [62.13.136.82]) by postgresql.org (Postfix) with ESMTP id DF3639FB54D for ; Wed, 10 Oct 2007 16:52:22 -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 l9AJqJV3088633; Wed, 10 Oct 2007 20:52:19 +0100 (BST) Received: from [192.168.0.3] (85-211-149-22.dyn.gotadsl.co.uk [85.211.149.22]) (authenticated bits=0) by mail.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id l9AJqGrx076904; Wed, 10 Oct 2007 20:52:17 +0100 (BST) Subject: Re: hashjoin chosen over 1000x faster plan From: Simon Riggs To: Kevin Grittner Cc: pgsql-performance@postgresql.org, Tom Lane In-Reply-To: <470CE34D.EE98.0025.0@wicourts.gov> References: <470B99BE.EE98.0025.0@wicourts.gov> <1191997904.4233.125.camel@ebony.site> <470C9813.EE98.0025.0@wicourts.gov> <1192035955.4233.306.camel@ebony.site> <1192035955.4233.306.camel@ebony.site> <20980.1192039650@sss.pgh.pa.us> <470CD3E3.EE98.0025.0@wicourts.gov> <1192042492.4233.334.camel@ebony.site> <470CE34D.EE98.0025.0@wicourts.gov> Content-Type: text/plain Date: Wed, 10 Oct 2007 20:52:25 +0100 Message-Id: <1192045945.4233.351.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Content-Transfer-Encoding: 7bit X-Server-Quench: 4e4665ca-776a-11dc-b86a-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadRtFaQVbYlpF HGQLW1NEUl17XGF/ ag0fZQBDYEtPQQRu WVZLQE1QERpoT0AI d2RfJVs6dwJAcX50 K0RiVnIVWBF+c0B4 ER9JEmoANHphaTRM TRJQcVJJcANLfxdA PlN4UyBcLwdSbGoL JyIJERcLGAAXKC1O QgMKLFRaSkYMBTM6 DxccEC9nRBVdHzV7 IRU9NlMGVF4VO0Na 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: 200710/107 X-Sequence-Number: 27129 On Wed, 2007-10-10 at 14:35 -0500, Kevin Grittner wrote: > >>> On Wed, Oct 10, 2007 at 1:54 PM, in message > <1192042492.4233.334.camel@ebony.site>, Simon Riggs > wrote: > > > > But the planner doesn't work on probability. It works on a best-guess > > selectivity, as known at planning time. > > The point I'm trying to make is that at planning time the > pg_statistic row for this "Charge"."reopHistSeqNo" column showed > stanullfrac as 0.989; it doesn't seem to have taken this into account > when making its guess about how many rows would be joined when it was > compared to the primary key column of the "CaseHist" table. I'm > suggesting that it might be a good thing if it did. Understood, it would be a good thing if it did. It's more complex than you think: The fast plan is an all-or-nothing plan. It is *only* faster when the number of matched rows is zero. You know it is zero, but currently the planner doesn't, nor is it able to make use of the information when it has it, half thru execution. Even if we could work out the high probability of it being zero, we would still be left with the decision of whether to optimise for the zero or for the non-zero. -- Simon Riggs 2ndQuadrant http://www.2ndQuadrant.com