slow query execution

From: Trigve Siver <trigves(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: slow query execution
Date: 2007-05-30 15:56:45
Message-ID: 543741.9839.qm@web52709.mail.re2.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi all,

This query executes very slow:

select (select count(*) from customer where id <= a.id) as row, id, from customer as a order by id;

Where customer has id column and others and has also index on id column. The table has about 10.000+ records. When used with "explain", it gives me this output:

QUERY PLAN

-----------------------------------------------------------------------------------------
Sort (cost=6513774.23..6513801.37 rows=10855 width=14)
Sort Key: id
-> Seq Scan on customer a (cost=0.00..6513046.62 rows=10855 width=14)
SubPlan
-> Aggregate (cost=599.94..599.95 rows=1 width=0)
-> Bitmap Heap Scan on customer (cost=28.66..590.89 rows=361 width=0)
Recheck Cond: (id <= $0)
-> Bitmap Index Scan on iid (cost=0.00..28.66 rows=361 width=0)
Index Cond: (id <= $0)
(9 riadkov)

So is there any solution to speed up this query? Or can I get the same result but with some other query?

thanks

Trigve


____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew Sullivan 2007-05-30 16:45:53 Re: slow query execution
Previous Message Michael Fuhr 2007-05-30 14:13:49 Re: spi and error messages