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 7AC9BD1B533 for ; Thu, 2 Oct 2003 19:39:39 +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 64538-04 for ; Thu, 2 Oct 2003 16:38:55 -0300 (ADT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by svr1.postgresql.org (Postfix) with ESMTP id EBBB8D1B4E1 for ; Thu, 2 Oct 2003 16:38:50 -0300 (ADT) Received: from klaster.net (core-1.citynet.pl [80.48.135.69]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 9CB8C2B3CC; Thu, 2 Oct 2003 21:37:13 +0200 (CEST) Message-ID: <3F7C7E4A.9080803@klaster.net> Date: Thu, 02 Oct 2003 21:36:42 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.5) Gecko/20030916 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Dror Matalon Cc: "pgsql-performance@postgresql.org" Subject: Re: count(*) slow on large tables References: <20031002191547.GZ87525@rlx11.zapatec.com> In-Reply-To: <20031002191547.GZ87525@rlx11.zapatec.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=IN_REP_TO, QUOTED_EMAIL_TEXT, RCVD_IN_OSIRUSOFT_COM, REFERENCES, REPLY_WITH_QUOTES, USER_AGENT_MOZILLA_UA X-Spam-Level: X-Archive-Number: 200310/60 X-Sequence-Number: 3808 > 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. > > Dror Just like other aggregate functions, count(*) won't use indexes when counting whole table. Regards, Tomasz Myrta