Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 363959FB781 for ; Wed, 10 Oct 2007 15:30:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 61184-09 for ; Wed, 10 Oct 2007 15:30:15 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from gwmta.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by postgresql.org (Postfix) with ESMTP id C9B259FB753 for ; Wed, 10 Oct 2007 15:30:21 -0300 (ADT) Received: from Courts-MTA by gwmta.wicourts.gov with Novell_GroupWise; Wed, 10 Oct 2007 13:30:17 -0500 Message-Id: <470CD3E3.EE98.0025.0@wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 7.0.2 Date: Wed, 10 Oct 2007 13:30:13 -0500 From: "Kevin Grittner" To: "Simon Riggs" , "Tom Lane" Cc: Subject: Re: hashjoin chosen over 1000x faster plan 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> In-Reply-To: <20980.1192039650@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/102 X-Sequence-Number: 27124 >>> On Wed, Oct 10, 2007 at 1:07 PM, in message <20980.1192039650@sss.pgh.= pa.us>, Tom Lane wrote:=20 > Simon Riggs writes: >> Basically the planner doesn't ever optimise for the possibility of the >> never-executed case because even a single row returned would destroy >> that assumption.=20 >=20 > It's worse than that: the outer subplan *does* return some rows. > I suppose that all of them had NULLs in the join keys, which means > that (since 8.1 or so) nodeMergejoin discards them as unmatchable. > Had even one been non-NULL the expensive subplan would have been run. =20 Well, this query is run tens of thousands of times per day by our web application; less than one percent of those runs would require the subplan. (In my initial post I showed counts to demonstrate that 1% of the rows had a non-NULL value and, while I wouldn't expect the planner to know this, these tend to be clustered on a lower percentage of cases.) If the philosophy of the planner is to go for the lowest average cost (versus lowest worst case cost) shouldn't it use the statistics for to look at the percentage of NULLs? =20 -Kevin =20