Re: Slow query: table iteration (8.3)

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: Slow query: table iteration (8.3)
Дата
Msg-id 603c8f071002041357k72da49a7yc5ecb7a78ef6c52f@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Slow query: table iteration (8.3)  (Glenn Maynard <glenn@zewt.org>)
Список pgsql-performance
On Thu, Feb 4, 2010 at 3:24 AM, Glenn Maynard <glenn@zewt.org> wrote:
> On Wed, Feb 3, 2010 at 10:05 PM, Robert Haas <robertmhaas@gmail.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

В списке pgsql-performance по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: bigint integers up to 19 digits.
Следующее
От: Robert Haas
Дата:
Сообщение: Re: Slow-ish Query Needs Some Love