Re: slow query execution - Mailing list pgsql-sql

From Andrew Sullivan
Subject Re: slow query execution
Date
Msg-id 20070530164553.GK16260@phlogiston.dyndns.org
Whole thread Raw
In response to slow query execution  (Trigve Siver <trigves@yahoo.com>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Trigve Siver
Date:
Subject: slow query execution
Next
From: Trigve Siver
Date:
Subject: Re: slow query execution