Re: Bypassing useless ORDER BY in a VIEW - Mailing list pgsql-performance

From Tom Lane
Subject Re: Bypassing useless ORDER BY in a VIEW
Date
Msg-id 8366.1204218820@sss.pgh.pa.us
Whole thread Raw
In response to Bypassing useless ORDER BY in a VIEW  ("Robins Tharakan" <tharakan@gmail.com>)
Responses Re: Bypassing useless ORDER BY in a VIEW  ("Dean Gibson (DB Administrator)" <postgresql@ultimeth.com>)
Re: Bypassing useless ORDER BY in a VIEW  ("Robins Tharakan" <tharakan@gmail.com>)
List pgsql-performance
"Robins Tharakan" <tharakan@gmail.com> writes:
> If I give an ORDER BY clause in a VIEW and then use it in another query
> where the VIEW's ORDER BY is immaterial, would the planner be able to
> discard this ORDER BY clause ?

No.  That's a feature not a bug; the sorts of cases where you want an
ORDER BY in a subquery, it's because you really want those rows computed
in that order (eg you've got side-effect-causing functions reading the
results).  Postgres will never discard an ORDER BY as "immaterial".

A rule of thumb is that ORDER BY in a view is bad design, IMHO.

            regards, tom lane

pgsql-performance by date:

Previous
From: "Robins Tharakan"
Date:
Subject: Bypassing useless ORDER BY in a VIEW
Next
From: "Laurent Raufaste"
Date:
Subject: Re: PG planning randomly ?