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

Re: strange query behavior

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Tim Jones" <TJones(at)optio(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: strange query behavior
Date: 2006-12-14 17:48:35
Message-ID: 22464.1166118515@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-performance
"Tim Jones" <TJones(at)optio(dot)com> writes:
> 18,273,008 rows in observationresults
> [ and n_distinct = 12942 ]

OK, so the estimated rowcounts are coming from those two numbers.
It's notoriously hard to get a decent n_distinct estimate from a small
sample :-(, and I would imagine the number of batteryidentifiers is
really a lot more than 12942?

What you need to do is increase the statistics target for
observationresults.batteryidentifier (see ALTER TABLE) and re-ANALYZE
and see if you get a saner n_distinct in pg_stats.  I'd try 100 and
then 1000 as target.  Or you could just increase the global default
target (see postgresql.conf) but that might be overkill.

It's still a bit odd that the case with two batteryidentifiers was
estimated fairly accurately when the other wasn't; I'll go look into
that.  But in any case you need better stats if you want good plans.

			regards, tom lane

In response to

Responses

pgsql-performance by date

Next:From: Tom LaneDate: 2006-12-14 18:30:15
Subject: Re: strange query behavior
Previous:From: Bruno Wolff IIIDate: 2006-12-14 17:48:09
Subject: Re: File Systems Compared

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