slow query execution - Mailing list pgsql-sql

From Trigve Siver
Subject slow query execution
Date
Msg-id 543741.9839.qm@web52709.mail.re2.yahoo.com
Whole thread Raw
Responses Re: slow query execution
List 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.37rows=10855 width=14)  Sort Key: id  ->  Seq Scan on customer a  (cost=0.00..6513046.62
rows=10855width=14)        SubPlan          ->  Aggregate  (cost=599.94..599.95 rows=1 width=0)                ->
BitmapHeap 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/  


pgsql-sql by date:

Previous
From: Gerardo Herzig
Date:
Subject: logging amount rows retrieved?
Next
From: Andrew Sullivan
Date:
Subject: Re: slow query execution