Re: Slow query: table iteration (8.3)

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Glenn Maynard <glenn(at)zewt(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow query: table iteration (8.3)
Date: 2010-02-04 21:57:21
Message-ID: 603c8f071002041357k72da49a7yc5ecb7a78ef6c52f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Thu, Feb 4, 2010 at 3:24 AM, Glenn Maynard <glenn(at)zewt(dot)org> wrote:
> On Wed, Feb 3, 2010 at 10:05 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> Rewriting it as a join will likely be faster still:
>>
>> SELECT r.id FROM stomp_steps s, stomp_round r WHERE (s.id IS NULL OR
>> r.steps_id = s.id) AND ($1 IS NULL OR r.user_card_id = $1) ORDER BY
>> r.score DESC LIMIT $2
>
> That's not the same; this SELECT will only find the N highest scores,
> since the LIMIT applies to the whole results.  Mine finds the highest
> scores for each stage (steps), since the scope of the LIMIT is each
> call of the function (eg. "find the top score for each stage" as
> opposed to "find the top five scores for each stage").
>
> That's the only reason I used a function at all to begin with--I know
> no way to do this with a plain SELECT.

Oh, I get it. Yeah, I don't think you can do that without LATERAL(),
which we don't have, unless the window-function thing works...

...Robert

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Robert Haas 2010-02-05 01:49:26 Re: Slow-ish Query Needs Some Love
Previous Message Alvaro Herrera 2010-02-04 20:09:29 Re: bigint integers up to 19 digits.