Skip site navigation (1) Skip section navigation (2)

Re: Bypassing useless ORDER BY in a VIEW

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Robins Tharakan" <tharakan(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Bypassing useless ORDER BY in a VIEW
Date: 2008-02-28 17:13:40
Message-ID: 8366.1204218820@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-performance
"Robins Tharakan" <tharakan(at)gmail(dot)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

In response to

Responses

pgsql-performance by date

Next:From: Laurent RaufasteDate: 2008-02-28 17:46:43
Subject: Re: PG planning randomly ?
Previous:From: Robins TharakanDate: 2008-02-28 14:31:19
Subject: Bypassing useless ORDER BY in a VIEW

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group