X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 8037ED1B551 for ; Thu, 2 Oct 2003 21:21:26 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 79221-09 for ; Thu, 2 Oct 2003 18:20:38 -0300 (ADT) Received: from beamish.nsd.ca (beamish.nsd.ca [205.150.156.194]) by svr1.postgresql.org (Postfix) with ESMTP id 489BAD1B542 for ; Thu, 2 Oct 2003 18:20:23 -0300 (ADT) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id RAA09382; Thu, 2 Oct 2003 17:20:20 -0400 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma009378; Thu, 2 Oct 03 17:20:09 -0400 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id RAA17094; Thu, 2 Oct 2003 17:06:17 -0400 Message-ID: <3F7C98B8.C892D0E5@nsd.ca> Date: Thu, 02 Oct 2003 17:29:28 -0400 From: Jean-Luc Lachance X-Mailer: Mozilla 4.8 [en] (X11; U; Linux 2.4.18-24.7.x i686) X-Accept-Language: en MIME-Version: 1.0 To: Bruno Wolff III Cc: Dror Matalon , "pgsql-performance@postgresql.org" Subject: Re: count(*) slow on large tables References: <20031002191547.GZ87525@rlx11.zapatec.com> <20031002193905.GD18417@wolff.to> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/66 X-Sequence-Number: 3814 That's one of the draw back of MVCC. I once suggested that the transaction number and other house keeping info be included in the index, but was told to forget it... It would solve once and for all the issue of seq_scan vs index_scan. It would simplify the aggregate problem. Bruno Wolff III wrote: > > On Thu, Oct 02, 2003 at 12:15:47 -0700, > Dror Matalon wrote: > > Hi, > > > > I have a somewhat large table, 3 million rows, 1 Gig on disk, and growing. Doing a > > count(*) takes around 40 seconds. > > > > Looks like the count(*) fetches the table from disk and goes through it. > > Made me wonder, why the optimizer doesn't just choose the smallest index > > which in my case is around 60 Megs and goes through it, which it could > > do in a fraction of the time. > > Because it can't tell from the index if a tuple is visible to the current > transaction and would still have to hit the table to check this. So that > performance would be a lot worse instead of better. > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html