Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 3590F632AAD for ; Mon, 13 Sep 2010 13:48:17 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 92804-04 for ; Mon, 13 Sep 2010 16:48:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id ACC9062DBEC for ; Mon, 13 Sep 2010 13:48:09 -0300 (ADT) 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 o8DGm8Dh014519; Mon, 13 Sep 2010 12:48:08 -0400 (EDT) To: Gaetano Mendola cc: pgsql-performance@postgreSQL.org Subject: Re: Useless sort by In-reply-to: <4C8E4982.70004@gmail.com> References: <12103.1284389088@sss.pgh.pa.us> <4C8E4982.70004@gmail.com> Comments: In-reply-to Gaetano Mendola message dated "Mon, 13 Sep 2010 17:55:46 +0200" Date: Mon, 13 Sep 2010 12:48:07 -0400 Message-ID: <14518.1284396487@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/58 X-Sequence-Number: 40261 Gaetano Mendola 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