Re: expensive function in select list vs limit clause

Поиск
Список
Период
Сортировка
От Chris Mair
Тема Re: expensive function in select list vs limit clause
Дата
Msg-id 792ac2c7283e3efab818aba9ca063416@smtp.hushmail.com
обсуждение исходный текст
Ответ на Re: expensive function in select list vs limit clause  (Albe Laurenz <laurenz.albe@wien.gv.at>)
Список pgsql-general
>
> ORDER BY can only be processed after all rows have been fetched, this
> includes the expensive result column.
>
> You can easily avoid that by applying the LIMIT first:
>
>   SELECT r, expensive()
>   FROM (SELECT r
>         FROM big
>         ORDER BY r
>         LIMIT 10
>        ) inner;
>
> I don't know how hard it would be to only fetch the necessary columns before
> the ORDER BY and fetch the others after the LIMIT has been applied, but it
> is probably nontrivial and would require processing time for *everybody*
> who runs a query with ORDER BY to solve a rare problem that can easily be
> worked around.

Hi,

Tom Lane just pointed out that 9.6 is able to optimise this (at least
the synthetic example).

Anyway, my real problem could be beautifully improved by subselect-trick!

Thanks a lot!

Bye,
Chris.






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

Предыдущее
От: Chris Mair
Дата:
Сообщение: Re: expensive function in select list vs limit clause
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Advise on primary key for detail tables (OS: RaspberryPi)