Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id DCACF2E018D for ; Thu, 28 Feb 2008 13:13:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 72330-02 for ; Thu, 28 Feb 2008 13:13:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 7C7D42E0185 for ; Thu, 28 Feb 2008 13:13:42 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m1SHDeHT008367; Thu, 28 Feb 2008 12:13:40 -0500 (EST) To: "Robins Tharakan" cc: pgsql-performance@postgresql.org Subject: Re: Bypassing useless ORDER BY in a VIEW In-reply-to: <36af4bed0802280631ja29c636w2256fb329e14b95e@mail.gmail.com> References: <36af4bed0802280631ja29c636w2256fb329e14b95e@mail.gmail.com> Comments: In-reply-to "Robins Tharakan" message dated "Thu, 28 Feb 2008 20:01:19 +0530" Date: Thu, 28 Feb 2008 12:13:40 -0500 Message-ID: <8366.1204218820@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/393 X-Sequence-Number: 28935 "Robins Tharakan" 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