Re: ANALYZE not working?

From: Ron Mayer <ron(at)intervideo(dot)com>
To: Jeff Boes <jboes(at)nexcerpt(dot)com>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: ANALYZE not working?
Date: 2003-01-06 22:09:47
Message-ID: Pine.LNX.4.33.0301061403570.1653-100000@ron
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin


On Mon, 6 Jan 2003, Jeff Boes wrote:
>
> [...] Suddenly [...] ANALYZE isn't working properly (it is recording
> pg_class.reltuples far lower than the actual row count).

I had the same problem recently...
http://archives.postgresql.org/pgsql-bugs/2002-08/msg00015.php
where "vacuum analyze" and "vacuum; analyze;" were giving me
three orders of magnitude differences in estimates.

Apparently "analyze" is somewhat dependant on the order in which
rows had been inserted in the table; since it just does a (small)
random sample rather than a full table scan.

The thread there has some detailed explanation from Tom about the
underlying cause of the different results and how to diagnose it.

Short summary for me was that for a short term fix, I paid
the price for the slower "vacuum analzye" more frequently;
and later I re-ordered the whole table
create table tmp_table as select * from my_table order by foo;
drop table my_table;
alter table tmp_table rename to my_table;
which made "analyze;" give good estimates again.

Hope this helps.
Ron

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message mitchell laks 2003-01-06 22:21:53 repair table? database? how ? neccessary?
Previous Message Tom Lane 2003-01-06 21:16:11 Re: ANALYZE not working?