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 6417AD1B51D for ; Thu, 2 Oct 2003 19:32:35 +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 56864-09 for ; Thu, 2 Oct 2003 16:31:50 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 0C6F6D1B4E1 for ; Thu, 2 Oct 2003 16:31:48 -0300 (ADT) Received: (qmail 18747 invoked by uid 500); 2 Oct 2003 19:39:05 -0000 Date: Thu, 2 Oct 2003 14:39:05 -0500 From: Bruno Wolff III To: Dror Matalon Cc: "pgsql-performance@postgresql.org" Subject: Re: count(*) slow on large tables Message-ID: <20031002193905.GD18417@wolff.to> Mail-Followup-To: Dror Matalon , "pgsql-performance@postgresql.org" References: <20031002191547.GZ87525@rlx11.zapatec.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031002191547.GZ87525@rlx11.zapatec.com> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/59 X-Sequence-Number: 3807 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.