Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] Bad n_distinct estimation; hacks suggested?

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: josh(at)agliodbs(dot)com, Greg Stark <gsstark(at)mit(dot)edu>,Marko Ristola <marko(dot)ristola(at)kolumbus(dot)fi>,pgsql-perform <pgsql-performance(at)postgresql(dot)org>,pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Bad n_distinct estimation; hacks suggested?
Date: 2005-04-25 18:49:01
Message-ID: 1114454941.21529.245.camel@localhost.localdomain (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-performance
On Mon, 2005-04-25 at 11:23 -0400, Tom Lane wrote:
> Simon Riggs <simon(at)2ndquadrant(dot)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


In response to

Responses

pgsql-performance by date

Next:From: Josh BerkusDate: 2005-04-25 19:13:18
Subject: Re: [HACKERS] Bad n_distinct estimation; hacks suggested?
Previous:From: Steve PoeDate: 2005-04-25 17:18:23
Subject: Re: pgbench Comparison of 7.4.7 to 8.0.2

pgsql-hackers by date

Next:From: Josh BerkusDate: 2005-04-25 19:13:18
Subject: Re: [HACKERS] Bad n_distinct estimation; hacks suggested?
Previous:From: Michael PaesoldDate: 2005-04-25 17:51:31
Subject: Re: [PATCHES] Continue transactions after errors in psql

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group