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/ ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq