pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Tille <tillea@rki.de>
To: pgsql-performance@postgresql.org
Subject: Performance of count(*)
Date: Thu, 22 Mar 2007 11:53:00 +0100 (CET)
Message-ID: <Pine.LNX.4.62.0703221149210.13747@wr-linux02> (raw)

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



view thread (41+ messages)  latest in thread

Message-ID: <Pine.LNX.4.62.0703221149210.13747@wr-linux02>
Permalink:  ../Pine.LNX.4.62.0703221149210.13747@wr-linux02/
Also on:    postgresql.org/message-id/Pine.LNX.4.62.0703221149210.13747@wr-linux02

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tillea@rki.de
  Subject: Re: Performance of count(*)
  In-Reply-To: <Pine.LNX.4.62.0703221149210.13747@wr-linux02>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox