Re: why does count take so long? - Mailing list pgsql-general

From Tom Lane
Subject Re: why does count take so long?
Date
Msg-id 29367.1062995090@sss.pgh.pa.us
Whole thread Raw
In response to Re: why does count take so long?  (Bruno Wolff III <bruno@wolff.to>)
Responses Re: why does count take so long?
Re: why does count take so long?
List pgsql-general
Bruno Wolff III <bruno@wolff.to> writes:
>   Joseph Shraibman <jks@selectacast.net> wrote:
>> It looks like the aggregate took 10 secs all by itself.  What's taking
>> so long?

> It looks like there are 8 million log records that need to be counted.

Yeah, but I think he's complaining about the 10sec delta for the
aggregate on top of the 71sec to read the 8 million rows.  That
seems high to me too.  On a 10-mil-row test table, I get

regression=# explain analyze select count(*) from foo;
                                                    QUERY PLAN
------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=22.50..22.50 rows=1 width=0) (actual time=189865.81..189865.81 rows=1 loops=1)
   ->  Seq Scan on foo  (cost=0.00..20.00 rows=1000 width=0) (actual time=18.88..163833.61 rows=10240000 loops=1)
 Total runtime: 189865.91 msec
(3 rows)

in other words 26sec to do the aggregate on top of 163sec to read the
rows.

Unless Joseph's machine has a way better IO-to-CPU ratio than my little
development machine, there's something odd about his numbers.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Unix domain instead of TCP socket connections with JDBC.
Next
From: Sergey Suleymanov
Date:
Subject: Re: default EXECUTE privilege