From: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Gaetano Mendola <mendola@gmail.com>
Cc: pgsql-performance@postgreSQL.org
Subject: Re: Useless sort by
Date: Tue, 14 Sep 2010 10:10:37 +0300
Message-ID: <4C8F1FED.3050902@enterprisedb.com> (raw)
In-Reply-To: <14518.1284396487@sss.pgh.pa.us>
References: <i6ks04$2jet$1@news.hub.org>
<12103.1284389088@sss.pgh.pa.us>
<4C8E4982.70004@gmail.com>
<14518.1284396487@sss.pgh.pa.us>
On 13/09/10 19:48, Tom Lane wrote:
> 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.
You could check for volatile functions. I think this could be done
safely. However, it doesn't seem worthwhile, it would be a fair amount
of code, and it's not usually a good idea to put an ORDER BY in a view
or subquery anyway unless you also have volatile functions in there, or
you want to coerce the optimizer to choose a certain plan.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: heikki.linnakangas@enterprisedb.com, tgl@sss.pgh.pa.us, mendola@gmail.com
Subject: Re: Useless sort by
In-Reply-To: <4C8F1FED.3050902@enterprisedb.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox