pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: nickf@ontko.com
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: Problem with n_distinct being consistently inaccurate.
Date: Tue, 23 Sep 2003 13:37:16 -0400
Message-ID: <20330.1064338636@sss.pgh.pa.us> (raw)
In-Reply-To: <NEBBLAAHGLEEPCGOBHDGKEHOIJAA.nickf@ontko.com>
References: <NEBBLAAHGLEEPCGOBHDGKEHOIJAA.nickf@ontko.com>

"Nick Fankhauser" <nickf@ontko.com> writes:
> So the question is- how can I get a better estimate of n_distinct from
> analyze?
> If I alter the stats target as high as it will go, I get closer, but it
> still shows the index to be about 1/2 as selective as it actually is:

AFAIK, estimating number of distinct values from a small sample is
inherently an ill-conditioned problem.   You should probably be happy
it can get within a factor of 2 ;-).

You could try sticking the correct n_distinct into pg_statistic by hand
just to see if it really does change the plan, but I'd like to think
that getting within a factor of 2 is good enough.  If it's not, then we
probably ought to look for ways to avoid using number-of-distinct-values
statistics altogether, because we'll seldom have a hard value for it.

			regards, tom lane



view thread (9+ messages)  latest in thread

Message-ID: <20330.1064338636@sss.pgh.pa.us>
Permalink:  ../20330.1064338636@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20330.1064338636@sss.pgh.pa.us

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, nickf@ontko.com
  Subject: Re: Problem with n_distinct being consistently inaccurate.
  In-Reply-To: <20330.1064338636@sss.pgh.pa.us>
  References: <NEBBLAAHGLEEPCGOBHDGKEHOIJAA.nickf@ontko.com> <20330.1064338636@sss.pgh.pa.us>

* 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