From: Simon Riggs <simon@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: josh@agliodbs.com, Greg Stark <gsstark@mit.edu>
Cc: Marko Ristola <marko.ristola@kolumbus.fi>
Cc: pgsql-perform <pgsql-performance@postgresql.org>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] Bad n_distinct estimation; hacks suggested?
Date: Mon, 25 Apr 2005 19:49:01 +0100
Message-ID: <1114454941.21529.245.camel@localhost.localdomain> (raw)
In-Reply-To: <19276.1114442580@sss.pgh.pa.us>
References: <200504191209.05181.josh@agliodbs.com>
<200504221336.08325.josh@agliodbs.com>
<8764ydapky.fsf@stark.xeocode.com>
<200504231639.11897.josh@agliodbs.com>
<1114419467.21529.210.camel@localhost.localdomain>
<19276.1114442580@sss.pgh.pa.us>
On Mon, 2005-04-25 at 11:23 -0400, Tom Lane wrote:
> Simon Riggs <simon@2ndquadrant.com> writes:
> > My suggested hack for PostgreSQL is to have an option to *not* sample,
> > just to scan the whole table and find n_distinct accurately.
> > ...
> > What price a single scan of a table, however large, when incorrect
> > statistics could force scans and sorts to occur when they aren't
> > actually needed ?
>
> It's not just the scan --- you also have to sort, or something like
> that, if you want to count distinct values. I doubt anyone is really
> going to consider this a feasible answer for large tables.
Assuming you don't use the HashAgg plan, which seems very appropriate
for the task? (...but I understand the plan otherwise).
If that was the issue, then why not keep scanning until you've used up
maintenance_work_mem with hash buckets, then stop and report the result.
The problem is if you don't do the sort once for statistics collection
you might accidentally choose plans that force sorts on that table. I'd
rather do it once...
The other alternative is to allow an ALTER TABLE command to set
statistics manually, but I think I can guess what you'll say to that!
Best Regards, Simon Riggs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: simon@2ndquadrant.com, tgl@sss.pgh.pa.us, gsstark@mit.edu, marko.ristola@kolumbus.fi, pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] Bad n_distinct estimation; hacks suggested?
In-Reply-To: <1114454941.21529.245.camel@localhost.localdomain>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox