Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 6EC052E0062 for ; Wed, 30 Apr 2008 20:20:35 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 40356-02 for ; Wed, 30 Apr 2008 20:20:24 -0300 (ADT) Received: from mx1.hub.org (mx1.hub.org [200.46.208.106]) by developer.postgresql.org (Postfix) with ESMTP id BCA862E0041 for ; Wed, 30 Apr 2008 20:20:30 -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 mx1.hub.org (Postfix) with ESMTP id F32C6B07A56 for ; Wed, 30 Apr 2008 20:20:25 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m3UNHiZ2026231; Wed, 30 Apr 2008 19:17:44 -0400 (EDT) To: Jeff Davis cc: len@pdx.edu, len@cs.pdx.edu, pgsql-performance@postgresql.org Subject: Re: Understanding histograms In-reply-to: <1209595622.14025.112.camel@dogma.ljc.laika.com> References: <4817FC00.50609@cs.pdx.edu> <14251.1209532791@sss.pgh.pa.us> <18628.1209566591@sss.pgh.pa.us> <1209595622.14025.112.camel@dogma.ljc.laika.com> Comments: In-reply-to Jeff Davis message dated "Wed, 30 Apr 2008 15:47:02 -0700" Date: Wed, 30 Apr 2008 19:17:44 -0400 Message-ID: <26230.1209597464@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/474 X-Sequence-Number: 29967 Jeff Davis writes: > On Wed, 2008-04-30 at 10:43 -0400, Tom Lane wrote: >> Surely that's not very sane? The MCV list plus histogram generally >> don't include every value in the table. > My understanding of Len's question is that, although the MCV list plus > the histogram don't include every distinct value in the general case, > they do include every value in the specific case where the histogram is > not full. I don't believe that's true. It's possible that a small histogram means that you are seeing every value that was in ANALYZE's sample, but it's a mighty long leap from that to the assumption that there are no other values in the table. In any case that seems more an artifact of the implementation than a property the histogram would be guaranteed to have. > ... the statistics aren't guaranteed to be perfectly up-to-date, so an > estimate of zero might be risky. Right. As a matter of policy we never estimate less than one matching row; and I've seriously considered pushing that up to at least two rows except when we see that the query condition matches a unique constraint. You can get really bad join plans from overly-small estimates. regards, tom lane