Re: Useless sort by

Поиск
Список
Период
Сортировка
От Gaetano Mendola
Тема Re: Useless sort by
Дата
Msg-id 4C8E4982.70004@gmail.com
обсуждение исходный текст
Ответ на Re: Useless sort by  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Useless sort by  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-performance
On 09/13/2010 04:44 PM, Tom Lane wrote:
> Gaetano Mendola <mendola@gmail.com> writes:
>> because of that sort in the view definition the first query above
>> takes not less than 3 seconds. I have solved this performance issue
>> removing the sort from the view definition and putting it in the
>> select reducing the time from > 3secons to < 150ms.
>
>> Can not the optimizer take rid of that useless sort on those
>> kind of queries ?
>
> It is not the optimizer's job to second-guess the user on whether a sort
> is really needed there.  If we did make it throw away non-top-level
> sorts, we'd have hundreds of users screaming loudly.

Of course I'm not suggesting to take away the "sort by" and give the user
an unsorted result, I'm asking why the the optimizer in cases like:

   select unique(a) from v_table_with_order_by;

doesn't takes away the "order by" inside the view and puts it back "rewriting the
query like this:

   select unique(a) from v_table_without_order_by
   order by a;

then the user will not know about it. The result is the same but 30 times
faster (in my case).

Regards
Gaetano Mendola



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Problem with mergejoin performance
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Useless sort by