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>, "Hitoshi Harada" <umi(dot)tanuki(at)gmail(dot)com>
Cc: "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 14:34:09
Message-ID: 4A6045910200002500028902@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:

> postgres=# explain select count(*) over () from x;

> WindowAgg (cost=0.00..265.00 rows=10000 width=0)
> -> Seq Scan on x (cost=0.00..140.00 rows=10000 width=0)

> postgres=# explain select count(*) over (order by a) from x;

> WindowAgg (cost=0.00..556.25 rows=10000 width=4)
> -> Index Scan using gg on x (cost=0.00..406.25 rows=10000
width=4)

> query1: 160ms
> query2: 72ms

EXPLAIN ANALYZE is more telling than just EXPLAIN.

Did you run both several times or flush caches carefully between the
runs to eliminate caching effects?

Is it possible that there are a lot of dead rows in the table (from
UPDATEs or DELETEs), and the table has been vacuumed? (Output from
VACUUM VERBOSE on the table would show that.)

-Kevin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2009-07-17 14:43:37 Re: slow count in window query
Previous Message Boszormenyi Zoltan 2009-07-17 13:58:21 Re: ECPG support for struct in INTO list