"Steinar H. Gunderson" <[EMAIL PROTECTED]> 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 ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org