Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id F25F89FB627 for ; Fri, 18 May 2007 12:54:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 44157-07 for ; Fri, 18 May 2007 12:54:53 -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 85D3D9FB605 for ; Fri, 18 May 2007 12:54:53 -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 l4IFsnk7028605; Fri, 18 May 2007 11:54:49 -0400 (EDT) To: "Steinar H. Gunderson" cc: pgsql-performance@postgresql.org Subject: Re: performance drop on 8.2.4, reverting to 8.1.4 In-reply-to: <20070518111455.GA13978@uio.no> References: <20070518104646.GA13811@uio.no> <008201c7993c$76c88a10$653e10ac@ilgvaio> <20070518111455.GA13978@uio.no> Comments: In-reply-to "Steinar H. Gunderson" message dated "Fri, 18 May 2007 13:14:55 +0200" Date: Fri, 18 May 2007 11:54:49 -0400 Message-ID: <28604.1179503689@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/324 X-Sequence-Number: 24714 "Steinar H. Gunderson" writes: > On Fri, May 18, 2007 at 02:05:36PM +0300, Liviu Ionescu wrote: >> " -> Hash Left Join (cost=2.44..63.29 rows=1 width=49) (actual time=0.361..14.426 rows=2206 loops=1)" >> " Hash Cond: (n.nodeid = templates.nodeid)" >> " Filter: (templates.nodeid IS NULL)" > This seems to be the source of the misestimation. Yeah. 8.2 is estimating that the "nodeid IS NULL" condition will discard all or nearly all the rows, presumably because there aren't any null nodeid's in the underlying table --- it fails to consider that the LEFT JOIN may inject some nulls. 8.1 was not any brighter; the reason it gets a different estimate is that it doesn't distinguish left-join and WHERE clauses at all, but assumes that the result of the left join can't have fewer rows than its left input, even after applying the filter condition. In this particular scenario that happens to be a better estimate. So even though 8.2 is smarter, and there is no bug here that wasn't in 8.1 too, it's getting a worse estimate leading to a worse plan. This is a sufficiently common idiom that I think it's a must-fix problem. Not sure about details yet, but it seems somehow the selectivity estimator had better start accounting for outer-join-injected NULLs. regards, tom lane