Performance of count(*) - Mailing list pgsql-performance

From Andreas Tille
Subject Performance of count(*)
Date
Msg-id Pine.LNX.4.62.0703221149210.13747@wr-linux02
Whole thread Raw
Responses Re: Performance of count(*)  (Andreas Kostyrka <andreas@kostyrka.org>)
Re: Performance of count(*)  (Albert Cervera Areny <albert@sedifa.com>)
Re: Performance of count(*)  (ismo.tuononen@solenovo.fi)
Re: Performance of count(*)  ("Merlin Moncure" <mmoncure@gmail.com>)
List pgsql-performance
Hi,

I just try to find out why a simple count(*) might last that long.
At first I tried explain, which rather quickly knows how many rows
to check, but the final count is two orders of magnitude slower.

My MS_SQL server using colleague can't believe that.

$ psql InfluenzaWeb -c 'explain SELECT count(*) from agiraw ;'
                               QUERY PLAN
-----------------------------------------------------------------------
  Aggregate  (cost=196969.77..196969.77 rows=1 width=0)
    ->  Seq Scan on agiraw  (cost=0.00..185197.41 rows=4708941 width=0)
(2 rows)

real    0m0.066s
user    0m0.024s
sys     0m0.008s

$ psql InfluenzaWeb -c 'SELECT count(*) from agiraw ;'
   count
---------
  4708941
(1 row)

real    0m4.474s
user    0m0.036s
sys     0m0.004s


Any explanation?

Kind regards

          Andreas.

--
http://fam-tille.de

pgsql-performance by date:

Previous
From: "Michael Ben-Nes"
Date:
Subject: Lower Random Access Time vs RAID 0 / 1
Next
From: Andreas Kostyrka
Date:
Subject: Re: Performance of count(*)