Re: Some question about lazy subquery/procedures execution in SELECT ... ORDER BY... LIMIT N queries

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Some question about lazy subquery/procedures execution in SELECT ... ORDER BY... LIMIT N queries
Дата
Msg-id 24774.1322154302@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Some question about lazy subquery/procedures execution in SELECT ... ORDER BY... LIMIT N queries  (Maxim Boguk <maxim.boguk@gmail.com>)
Ответы Re: Some question about lazy subquery/procedures execution in SELECT ... ORDER BY... LIMIT N queries  (Maxim Boguk <maxim.boguk@gmail.com>)
Список pgsql-performance
Maxim Boguk <maxim.boguk@gmail.com> writes:
> Is here any reason why Postgresql calculates subqueries/storable procedures
> in select list before applying ORDER BY / LIMIT?

Well, that's the definition of ORDER BY --- it happens after computing
the select list, according to the SQL standard.  We try to optimize this
in some cases but you can't really complain when we don't.  Consider
putting the expensive function outside the ORDER BY/LIMIT, ie

select ..., expensive_fn() from (select ... order by ... limit ...) ss;

            regards, tom lane

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

Предыдущее
От: Maxim Boguk
Дата:
Сообщение: Some question about lazy subquery/procedures execution in SELECT ... ORDER BY... LIMIT N queries
Следующее
От: MirrorX
Дата:
Сообщение: query uses index but takes too much time?