Re: strange query behavior - Mailing list pgsql-performance

From Tim Jones
Subject Re: strange query behavior
Date
Msg-id 47668A1334CDBF46927C1A0DFEB223D39F7C5D@mail.optiosoftware.com
Whole thread Raw
In response to Re: strange query behavior  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-performance
ok thanks Tom I will alter the statistics and re-analyze the table.

Tim Jones
Healthcare Project Manager
Optio Software, Inc.
(770) 576-3555

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Thursday, December 14, 2006 12:49 PM
To: Tim Jones
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] strange query behavior

"Tim Jones" <TJones@optio.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

pgsql-performance by date:

Previous
From: Alexander Staubo
Date:
Subject: Re: New to PostgreSQL, performance considerations
Next
From: Ron
Date:
Subject: Re: New to PostgreSQL, performance considerations