Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id F08299FBFE0 for ; Wed, 30 May 2007 14:03:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 87851-02-4 for ; Wed, 30 May 2007 14:03:11 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from web52709.mail.re2.yahoo.com (web52709.mail.re2.yahoo.com [206.190.48.232]) by postgresql.org (Postfix) with SMTP id 7FF579FBFB5 for ; Wed, 30 May 2007 14:03:17 -0300 (ADT) Received: (qmail 41103 invoked by uid 60001); 30 May 2007 17:03:16 -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=pITYOhjqUX//gYhPZaybiSy3fI7roTrXf1W8Ht6bnmbRymmGdutUPCtHLBK3UsNV75/9k3WxBLolt9P/hnXGFc69ckEuOCXrJxiARgOV/BYiSDpa/H1zOiFKdqxjpjE3vPsfjBExZa3oRG8/Jfvi3JnK2eLKhhanmm9vKFKd/ys=; X-YMail-OSG: p6ayyeQVM1k0983ncECLtlwiAIi6f9DMHa1KCbCMRyuSbH2.eKq6AZ8ll_KqfMG.YsS03I7jpqw1ShJ.IDSUSj5TzDEz9VsALtjZ.zNFukFZnKfNncuTfEAO8cMin.D32JaQbLhKoBN6SFM- Received: from [195.168.227.227] by web52709.mail.re2.yahoo.com via HTTP; Wed, 30 May 2007 10:03:16 PDT X-Mailer: YahooMailRC/651.23.1 YahooMailWebService/0.7.41.14 Date: Wed, 30 May 2007 10:03:16 -0700 (PDT) From: Trigve Siver Subject: Re: slow query execution To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Message-ID: <710412.41081.qm@web52709.mail.re2.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.986 tagged_above=0 required=5 tests=AWL=0.370, BAYES_20=-0.74, 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/194 X-Sequence-Number: 28474 Hi, Thanks for reply, As you have mentioned I need to get row numbers for my query, so when I make some other query with same data I will know which row number has a particular ID. As you mentioned "You can do this with a temporary sequence, among other approaches...". Can you point me to some sources or give me some examples, please? Thanks Trigve ----- Original Message ---- From: Andrew Sullivan To: pgsql-sql@postgresql.org Sent: Wednesday, May 30, 2007 6:45:53 PM Subject: Re: [SQL] slow query execution On Wed, May 30, 2007 at 08:56:45AM -0700, Trigve Siver wrote: > 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; So you are trying to get the ordinal position of every ID in the table? I'm not surprised it takes a long time -- you have to join the whole table to itself and then do a lot of counting. Are you just trying to get the "row number" for your query answer? You can do this with a temporary sequence, among other approaches, more cheaply. A -- Andrew Sullivan | ajs@crankycanuck.ca Users never remark, "Wow, this software may be buggy and hard to use, but at least there is a lot of code underneath." --Damien Katz ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq ____________________________________________________________________________________Yahoo! oneSearch: Finally, mobile search that gives answers, not web links. http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC