Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1B73B65035B for ; Fri, 12 Dec 2008 12:10:29 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 98705-09 for ; Fri, 12 Dec 2008 12:10:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from yx-out-2324.google.com (yx-out-2324.google.com [74.125.44.28]) by mail.postgresql.org (Postfix) with ESMTP id 2E94B64FD3C for ; Fri, 12 Dec 2008 12:10:19 -0400 (AST) Received: by yx-out-2324.google.com with SMTP id 8so677153yxb.73 for ; Fri, 12 Dec 2008 08:10:18 -0800 (PST) Received: by 10.64.21.10 with SMTP id 10mr3158269qbu.48.1229098217298; Fri, 12 Dec 2008 08:10:17 -0800 (PST) Received: from oxford.xeocode.com.enterprisedb.com (69-196-191-94.dsl.teksavvy.com [69.196.191.94]) by mx.google.com with ESMTPS id k29sm5109419qba.7.2008.12.12.08.10.14 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 12 Dec 2008 08:10:16 -0800 (PST) To: Simon Riggs Cc: Robert Haas , Tom Lane , Kevin Grittner , "jd\@commandprompt.com" , Josh Berkus , Greg Smith , pgsql-hackers@postgresql.org Subject: Re: benchmarking the query planner In-Reply-To: <1229093975.13078.275.camel@ebony.2ndQuadrant> (Simon Riggs's message of "Fri\, 12 Dec 2008 14\:59\:35 +0000") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+imap.gmail.com:HACKERS" 51022) References: <603c8f070812061019r5aca3aajeaa5493b11c5feff@mail.gmail.com> <603c8f070812092025k6325e0fcud001b205a507a634@mail.gmail.com> <4313.1228931932@sss.pgh.pa.us> <603c8f070812101828p1bd7df49yb8c916adedb49fe1@mail.gmail.com> <9565.1229018968@sss.pgh.pa.us> <1229033073.13078.179.camel@hp_dx2400_1> <87ej0etkfh.fsf@oxford.xeocode.com> <1229039044.13078.193.camel@hp_dx2400_1> <4136ffa0812111823u645b6ec9wdca60b3da4b00499@mail.gmail.com> <1229072675.13078.196.camel@hp_dx2400_1> <603c8f070812120344m67ef2c1fs41806cfb4ff9e396@mail.gmail.com> <1229093975.13078.275.camel@ebony.2ndQuadrant> From: Gregory Stark Organization: EnterpriseDB Date: Fri, 12 Dec 2008 16:10:13 +0000 Message-ID: <87tz99s7bu.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200812/945 X-Sequence-Number: 129574 Simon Riggs writes: > On Fri, 2008-12-12 at 06:44 -0500, Robert Haas wrote: >> It is a pretty well-known mathematical fact that for something like an >> opinion poll your margin of error does not depend on the size of the >> population but only on the size of your sample. > > Yes, I agree with that *but* that refers to population statistics and > has nothing at all to do with the calculation of ndistinct, which is > what we were discussing. You can't just switch topics and have the > statement remain true. If you go back to my email that was kind of my point. The existing sample size is on a solid foundation for the histograms and most use cases for the statistics. But entirely bogus for ndistinct. The ndistinct estimate is just piggy-backing on that data. However to fix it would require switching over to scanning a percentage of the whole table which would be a massive increase in work for that one calculation. You can't fix it by just adjusting the sample size slightly. > Note that the estimator we use was shown to be stable in the range of > sample size between 5-20%. > http://www.almaden.ibm.com/cs/people/peterh/jasa3rj.pdf Uhm, this is a survey of lots of different methods and does lots of analysis. I don't see any simple conclusions about stability. Perhaps I'm just missing it in the technical details. Could you point out exactly what part of the paper you're basing this on and what "stable" means? > We currently use a sample size of 300*stats_target. With default=10 that > means our sample size is 0.3% on a 1 million row table, and 0.003% on a > 100 million row table (they're common, I find). > > That size of sample is OK for some kinds of statistics, but not much > good for ndistinct estimation. Right, but increasing our sample size by a factor of 150 for a 100M row table doesn't seem like a reasonable solution to one metric being bogus. For that matter, if we do consider sampling 5% of the table we may as well just go ahead and scan the whole table. It wouldn't take much longer and it would actually produce good estimates. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me about EnterpriseDB's Slony Replication support!