Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4EBD86502A5 for ; Fri, 12 Dec 2008 11:08:17 -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 87770-02-6 for ; Fri, 12 Dec 2008 11:08:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail137090.authsmtp.net (outmail137090.authsmtp.net [62.13.137.90]) by mail.postgresql.org (Postfix) with ESMTP id 91CBC65038D for ; Fri, 12 Dec 2008 11:08:08 -0400 (AST) Received: from mail-c188.authsmtp.com (mail-c188.authsmtp.com [62.13.128.25]) by punt4.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id mBCF77uT099463; Fri, 12 Dec 2008 15:07:07 GMT Received: from [192.168.0.3] (85-211-226-82.dyn.gotadsl.co.uk [85.211.226.82]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id mBCF76PC016571; Fri, 12 Dec 2008 15:07:06 GMT Subject: Re: benchmarking the query planner From: Simon Riggs To: Tom Lane Cc: Robert Haas , Greg Stark , Kevin Grittner , "jd@commandprompt.com" , Josh Berkus , Greg Smith , pgsql-hackers@postgresql.org In-Reply-To: <5301.1229092509@sss.pgh.pa.us> 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> <5301.1229092509@sss.pgh.pa.us> Content-Type: text/plain Date: Fri, 12 Dec 2008 15:06:49 +0000 Message-Id: <1229094409.13078.283.camel@ebony.2ndQuadrant> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: 8ad3f181-c85e-11dd-aecc-001871e930f4 X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksafhtFaQdbaVxS HGQLW1xEUVh7WWR/ aw0fZQBDYEtPQQdo VlZBQE1QEQdtHhxP W2xtJB50F3ZGeXh1 YkcsXHVcWQpyJBJ+ FE9cFHBVbWI1dWEe BBRFJlYHIx5Kfh5N bVEqXXANN2FJBC9q VzwTFhsSEA9kHWxf TwcGLVcbW0UKGDF0 WxAPVSwyEFcUDz03 JhogJ0R0 X-Authentic-SMTP: 61633235383639.cat.dmpriest.net.uk:1378/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! 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/939 X-Sequence-Number: 129568 On Fri, 2008-12-12 at 09:35 -0500, Tom Lane wrote: > AFAICS, marginal enlargements in the sample size aren't going to help > much for ndistinct --- you really need to look at most or all of the > table to be guaranteed anything about that. > > But having said that, I have wondered whether we should consider > allowing the sample to grow to fill maintenance_work_mem, rather than > making it a predetermined number of rows. One difficulty is that the > random-sampling code assumes it has a predetermined rowcount target; > I haven't looked at whether that'd be easy to change or whether we'd > need a whole new sampling algorithm. I think we need to do block sampling before we increase sample size. On large tables we currently do one I/O per sampled row, so the I/O cost of ANALYZE would just increase linearly. We need the increased sample size for ndistinct, not for other stats. So I would suggest we harvest a larger sample, use that for ndistinct estimation, but then sample-the-sample to minimise processing time for other stats that aren't as sensitive as ndistinct. Currently we fail badly on columns that have been CLUSTERed and we can improve that significantly by looking at adjacent groups of rows, i.e. block sampling. -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support