Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 25ED04762EA for ; Mon, 6 Jan 2003 16:08:18 -0500 (EST) Received: from torque.intervideoinc.com (mail.intervideo.com [206.112.112.151]) by postgresql.org (Postfix) with ESMTP id 750804762CF for ; Mon, 6 Jan 2003 16:08:17 -0500 (EST) Received: from ron [206.112.112.139] by torque.intervideoinc.com with ESMTP (SMTPD32-5.05) id A4AC55A027E; Mon, 06 Jan 2003 13:27:08 -0800 Date: Mon, 6 Jan 2003 14:09:47 -0800 (PST) From: Ron Mayer X-X-Sender: To: Jeff Boes Cc: Subject: Re: ANALYZE not working? In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/43 X-Sequence-Number: 6885 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