Re: slow query execution - Mailing list pgsql-sql

From Trigve Siver
Subject Re: slow query execution
Date
Msg-id 710412.41081.qm@web52709.mail.re2.yahoo.com
Whole thread Raw
In response to slow query execution  (Trigve Siver <trigves@yahoo.com>)
Responses Re: slow query execution  ("Rodrigo De León" <rdeleonp@gmail.com>)
Re: slow query execution  (Andrew Sullivan <ajs@crankycanuck.ca>)
List pgsql-sql
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
samedata 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 <ajs@crankycanuck.ca>
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


pgsql-sql by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: slow query execution
Next
From: "Rodrigo De León"
Date:
Subject: Re: slow query execution