pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Sullivan <ajs@crankycanuck.ca>
To: pgsql-sql@postgresql.org
Subject: Re: slow query execution
Date: Wed, 30 May 2007 12:45:53 -0400
Message-ID: <20070530164553.GK16260@phlogiston.dyndns.org> (raw)
In-Reply-To: <543741.9839.qm@web52709.mail.re2.yahoo.com>
References: <543741.9839.qm@web52709.mail.re2.yahoo.com>

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



view thread (16+ messages)  latest in thread

Message-ID: <20070530164553.GK16260@phlogiston.dyndns.org>
Permalink:  ../20070530164553.GK16260@phlogiston.dyndns.org/
Also on:    postgresql.org/message-id/20070530164553.GK16260@phlogiston.dyndns.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ajs@crankycanuck.ca
  Subject: Re: slow query execution
  In-Reply-To: <20070530164553.GK16260@phlogiston.dyndns.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox