Re: slow count in window query

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Hitoshi Harada" <umi(dot)tanuki(at)gmail(dot)com>, "Greg Stark" <gsstark(at)mit(dot)edu>, "PostgreSQL Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: slow count in window query
Date: 2009-07-17 16:00:03
Message-ID: 4A6059B30200002500028918@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:

> table was filled with random numbers and analyzed - you can simple
> check it - look on begin of the thread. This table wasn't updated.

Confirmed. The ORDER BY consistently speeds up the query. Odd....

Sort speed varied based on random sequence generated, but typical
plan and timings:

test=# explain analyze select count(*) over () from x;
WindowAgg (cost=0.00..229.00 rows=10000 width=0) (actual
time=32.435..97.448 rows=10000 loops=1)
-> Seq Scan on x (cost=0.00..104.00 rows=10000 width=0) (actual
time=0.007..14.818 rows=10000 loops=1)
Total runtime: 112.526 ms

test=# explain analyze select count(*) over (order by a) from x;
WindowAgg (cost=768.39..943.39 rows=10000 width=4) (actual
time=34.982..87.803 rows=10000 loops=1)
-> Sort (cost=768.39..793.39 rows=10000 width=4) (actual
time=34.962..49.533 rows=10000 loops=1)
Sort Key: a
Sort Method: quicksort Memory: 491kB
-> Seq Scan on x (cost=0.00..104.00 rows=10000 width=4)
(actual time=0.006..14.682 rows=10000 loops=1)
Total runtime: 102.023 ms

-Kevin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dickson S. Guedes 2009-07-17 16:25:25 Re: Duplicate key value error
Previous Message Campbell, Lance 2009-07-17 15:34:34 Enhancement - code completion when typing set search_path