X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 91114D1B554 for ; Tue, 6 Jan 2004 16:04:41 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 05279-07 for ; Tue, 6 Jan 2004 12:03:52 -0400 (AST) Received: from bramble.mmrd.com (unknown [65.217.53.66]) by svr1.postgresql.org (Postfix) with ESMTP id 0A907D1B8EA for ; Tue, 6 Jan 2004 12:03:51 -0400 (AST) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by bramble.mmrd.com (8.12.8/8.12.8) with ESMTP id i06FLJcM013644; Tue, 6 Jan 2004 10:21:20 -0500 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [192.168.3.55]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id i06G3Nl08025; Tue, 6 Jan 2004 11:03:28 -0500 Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2657.72) id XT879Y02; Tue, 6 Jan 2004 11:03:21 -0500 Subject: Re: Select max(foo) and select count(*) optimization From: Robert Treat To: Shridhar Daithankar Cc: Postgresql Performance In-Reply-To: <200401061750.09530.shridhar_daithankar@persistent.co.in> References: <200401061212.21344.shridhar_daithankar@persistent.co.in> <200401060718.08444.darcy@druid.net> <200401061750.09530.shridhar_daithankar@persistent.co.in> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 06 Jan 2004 11:03:23 -0500 Message-Id: <1073405003.20751.2.camel@camel> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/67 X-Sequence-Number: 5242 On Tue, 2004-01-06 at 07:20, Shridhar Daithankar wrote: > On Tuesday 06 January 2004 17:48, D'Arcy J.M. Cain wrote: > > On January 6, 2004 01:42 am, Shridhar Daithankar wrote: > > cert=# select relpages,reltuples::bigint from pg_class where relname= > > 'certificate'; > > relpages | reltuples > > ----------+----------- > > 399070 | 24858736 > > (1 row) > > > > But: > > > > cert=# select count(*) from certificate; > > [*Crunch* *Crunch* *Crunch*] > > count > > ---------- > > 19684668 > > (1 row) > > > > Am I missing something? Max certificate_id is 20569544 btw. > > Do 'vacuum analyze certificate' and try..:-) > > The numbers from pg_class are estimates updated by vacuum /analyze. Of course > you need to run vacuum frequent enough for that statistics to be updated all > the time or run autovacuum daemon.. > > Ran into same problem on my machine till I remembered about vacuum..:-) > Actually you only need to run analyze to update the statistics. Robert Treat -- Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL