Skip site navigation (1) Skip section navigation (2)

Re: count(*) slow on large tables

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
To: Dror Matalon <dror(at)zapatec(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: count(*) slow on large tables
Date: 2003-10-02 19:36:42
Message-ID: 3F7C7E4A.9080803@klaster.net (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-performance
> 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


In response to

pgsql-performance by date

Next:From: Bruno Wolff IIIDate: 2003-10-02 19:39:05
Subject: Re: count(*) slow on large tables
Previous:From: scott.marloweDate: 2003-10-02 19:34:16
Subject: further testing on IDE drives

pgsql-hackers by date

Next:From: Bruno Wolff IIIDate: 2003-10-02 19:39:05
Subject: Re: count(*) slow on large tables
Previous:From: Dror MatalonDate: 2003-10-02 19:15:47
Subject: count(*) slow on large tables

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group