Re: constant time count(*) ?

From: Tino Wildenhain <tino(at)wildenhain(dot)de>
To: Mark Harrison <mh(at)pixar(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: constant time count(*) ?
Date: 2003-10-15 18:59:09
Message-ID: 3F8D98FD.5010500@wildenhain.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Mark,

Mark Harrison wrote:
> We're looking into moving some data from mysql to postgresql, and
> notice that count(*) does not seem to be a constant-time function
> as it seems to be in mysql.
>
> planb=# explain select count(*) from assets;
> QUERY PLAN
> ----------------------------------------------------------------
> Aggregate (cost=22.50..22.50 rows=1 width=0)
> -> Seq Scan on assets (cost=0.00..20.00 rows=1000 width=0)
> (2 rows)
>
> Is there a way to optimize count(*) such that it does not have
> to do a sequential scan? We use this on some big tables and it
> is slowing down processing quite a lot.

How do you need an unqualified
select count(*) on a table so often
it is making a problem?

Regards
Tino

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2003-10-15 19:02:06 Re: Getting error codes for failed queries?
Previous Message Kaarel 2003-10-15 18:58:55 Re: Triggers tutorial