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 15583D1B465 for ; Tue, 6 Jan 2004 12:21:53 +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 60378-07 for ; Tue, 6 Jan 2004 08:21:11 -0400 (AST) Received: from smtp.pspl.co.in (www.pspl.co.in [202.54.11.65]) by svr1.postgresql.org (Postfix) with ESMTP id 90F1DD1B440 for ; Tue, 6 Jan 2004 08:20:58 -0400 (AST) Received: (from root@localhost) by smtp.pspl.co.in (8.12.9/8.12.9) id i06CLEQR019820 for ; Tue, 6 Jan 2004 17:51:14 +0530 Received: from daithan.intranet.pspl.co.in (daithan.intranet.pspl.co.in [192.168.7.161]) (authenticated bits=0) by persistent.co.in (8.12.9/8.12.9) with ESMTP id i06CLEJN019806 for ; Tue, 6 Jan 2004 17:51:14 +0530 From: Shridhar Daithankar To: Postgresql Performance Subject: Re: Select max(foo) and select count(*) optimization Date: Tue, 6 Jan 2004 17:50:09 +0530 User-Agent: KMail/1.5.4 References: <200401061212.21344.shridhar_daithankar@persistent.co.in> <200401060718.08444.darcy@druid.net> In-Reply-To: <200401060718.08444.darcy@druid.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200401061750.09530.shridhar_daithankar@persistent.co.in> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/65 X-Sequence-Number: 5240 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..:-) Shridhar