Re: Useless sort by - Mailing list pgsql-performance

From Tom Lane
Subject Re: Useless sort by
Date
Msg-id 14518.1284396487@sss.pgh.pa.us
Whole thread Raw
In response to Re: Useless sort by  (Gaetano Mendola <mendola@gmail.com>)
Responses Re: Useless sort by
Re: Useless sort by
List pgsql-performance
Gaetano Mendola <mendola@gmail.com> writes:
> 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;

That changes the order in which the rows are fed to unique(a).  The
principal real-world use for a non-top-level ORDER BY is exactly to
determine the order in which rows are fed to a function, so we will
have a revolt on our hands if we break that.

            regards, tom lane

pgsql-performance by date:

Previous
From: Gaetano Mendola
Date:
Subject: Re: Useless sort by
Next
From: Gaetano Mendola
Date:
Subject: Re: Useless sort by