Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 247439FB78F for ; Tue, 5 Jun 2007 18:30:27 -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 79791-01 for ; Tue, 5 Jun 2007 18:30:19 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.238]) by postgresql.org (Postfix) with ESMTP id 1BF639FB78E for ; Tue, 5 Jun 2007 18:30:23 -0300 (ADT) Received: by wx-out-0506.google.com with SMTP id s16so1529970wxc for ; Tue, 05 Jun 2007 14:30:15 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=E2d5mpc5OWTRZVJ60T9Q1LIgju8KpeJ67mF7AxC19qcMeZpsjXZEP0mK15cg37vTcKDgd/VoaoybVnfbKT4YdUMSyWAHLJMLe26zPtq25LGFGfrQVPEBPnoKYB94heqhlEaJ/E00A0Y9I1XCeCsXoWlhX3E1drq3J84AEgjZHww= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=fwfxjuF5a+KZ28NwbgpT4Y9G5Vvhsiceaf91bNihkN3WLLeYXOEV5zg59LPOU9oow6Aie37N62UkA+LC6v/D74drHufex31NqTnaqD+0h4Laca/DCo3QSrPBjEUDIhpxixRKZgbSrXE4vmOdqV6S36/uasJWiGWrrwBw9NzfasY= Received: by 10.70.42.20 with SMTP id p20mr9774800wxp.1181079015335; Tue, 05 Jun 2007 14:30:15 -0700 (PDT) Received: by 10.70.102.7 with HTTP; Tue, 5 Jun 2007 14:30:14 -0700 (PDT) Message-ID: <357fa7590706051430h5db6760dx9d4a46c7a8a36205@mail.gmail.com> Date: Tue, 5 Jun 2007 17:30:14 -0400 From: "Steven Flatt" To: "Tom Lane" Subject: Re: performance drop on 8.2.4, reverting to 8.1.4 Cc: "Steinar H. Gunderson" , pgsql-performance@postgresql.org In-Reply-To: <28604.1179503689@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_20428_6830388.1181079014572" References: <20070518104646.GA13811@uio.no> <008201c7993c$76c88a10$653e10ac@ilgvaio> <20070518111455.GA13978@uio.no> <28604.1179503689@sss.pgh.pa.us> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/79 X-Sequence-Number: 25112 ------=_Part_20428_6830388.1181079014572 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 5/18/07, Tom Lane wrote: > > > 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. > This problem is causing us a bit of grief as we plan to move from 8.1.4 to 8.2.4. We have many (on the order of a hundred) queries that are of the form: (A) LEFT JOIN (B) ON col WHERE B.col IS NULL These queries are much slower on 8.2 than on 8.1 for what looks like the reason outlined above. I have rewritten a few key queries to be of the equivalent form: (A) WHERE col NOT IN (SELECT col FROM (B)) which has resulted in a dramatic improvement. I'm really hoping that I'm not going to need to re-write every single one of our queries that are of the first form above. Is there any estimation as to if/when the fix will become available? I'm hoping this isn't going to be a showstopper in us moving to 8.2. Thanks, Steve ------=_Part_20428_6830388.1181079014572 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
On 5/18/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:

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.
This problem is causing us a bit of grief as we plan to move from 8.1.4 to 8.2.4.  We have many (on the order of a hundred) queries that are of the form:
 
(A) LEFT JOIN (B) ON col WHERE B.col IS NULL
 
These queries are much slower on 8.2 than on 8.1 for what looks like the reason outlined above.  I have rewritten a few key queries to be of the equivalent form:
 
(A) WHERE col NOT IN (SELECT col FROM (B))
 
which has resulted in a dramatic improvement.  I'm really hoping that I'm not going to need to re-write every single one of our queries that are of the first form above.  Is there any estimation as to if/when the fix will become available?  I'm hoping this isn't going to be a showstopper in us moving to 8.2.
 
Thanks,
Steve
 
------=_Part_20428_6830388.1181079014572--