Re: efficiency of group by 1 order by 1

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: efficiency of group by 1 order by 1
Дата
Msg-id b42b73150603171015l4686dc17y1281e3625d318be8@mail.gmail.com
обсуждение исходный текст
Ответ на efficiency of group by 1 order by 1  (TJ O'Donnell <tjo@acm.org>)
Ответы Re: efficiency of group by 1 order by 1  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
> I use a similar SQL, e.g.:
>   select func(x)....group by func(x) order by func(x)
> but my func is rather expensive.  Is func(x) evaluated three times
> in the above statement?  Would it be evaluated only once if I used
>   select func(x)....group by 1 order by 1

try:

select q.v from (select func(t.x) as v from t) q order group by 1 order by 1;

Is your function immutable?  You have to be very careful with
expensive functions in the select clause.  for example

select f(x) from t where id = 1 order by n;

can cause f to execute for the entire table even if id is unique.
Solution is to subquery as in the above.

merlin

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

Предыдущее
От: SunWuKung
Дата:
Сообщение: Re: pgsql variables from records
Следующее
От: karly@kipshouse.org
Дата:
Сообщение: pgsql variables from records