Re: slow count in window query - Mailing list pgsql-hackers

From Kevin Grittner
Subject Re: slow count in window query
Date
Msg-id 4A6059B30200002500028918@gw.wicourts.gov
Whole thread Raw
In response to Re: slow count in window query  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: slow count in window query
List pgsql-hackers
Pavel Stehule <pavel.stehule@gmail.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
Scanon 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


pgsql-hackers by date:

Previous
From: Fernando Ike
Date:
Subject: Re: [PATCH] Psql List Languages
Next
From: "Dickson S. Guedes"
Date:
Subject: Re: Duplicate key value error