Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 29A439FB874 for ; Wed, 30 May 2007 12:56:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 43769-08 for ; Wed, 30 May 2007 12:56:46 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from web52709.mail.re2.yahoo.com (web52709.mail.re2.yahoo.com [206.190.48.232]) by postgresql.org (Postfix) with SMTP id 5DD6D9FB32F for ; Wed, 30 May 2007 12:56:46 -0300 (ADT) Received: (qmail 11208 invoked by uid 60001); 30 May 2007 15:56:45 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Message-ID; b=NmDx1TWZKDhprO3ebKKzi+NqHI10j+RkxXH5HZ5PoBpJXR0LjBFeOBqnheOQLbZFjeelXHwb8YwshJDv/A6Uyq79BTazmyVoHMSw/aE/ZP+6Q3Ii1KL+Bmu9sTmmfeSCwpOLedSufQEjY+VL8COF4Z4lGbVD8Qx0P4GhfJsH43Y=; X-YMail-OSG: b8yFiaIVM1n7DWltWXaaut8mAQXZG5K4jwor4i1vtjFWUDCqv7ibonPE4cq78w8iZBlLJbFujIwVF4PHJFt0biovlhB8YJe3izQknzAdeBxTziE1bN.Y9y7rzmr5SQ-- Received: from [195.168.227.227] by web52709.mail.re2.yahoo.com via HTTP; Wed, 30 May 2007 08:56:45 PDT X-Mailer: YahooMailRC/651.23.1 YahooMailWebService/0.7.41.14 Date: Wed, 30 May 2007 08:56:45 -0700 (PDT) From: Trigve Siver Subject: slow query execution To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Message-ID: <543741.9839.qm@web52709.mail.re2.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.356 tagged_above=0 required=5 tests=BAYES_50=0.001, DNS_FROM_RFC_ABUSE=0.2, DNS_FROM_RFC_POST=1.708, DNS_FROM_RFC_WHOIS=1.447 X-Spam-Level: *** X-Archive-Number: 200705/192 X-Sequence-Number: 28472 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/