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

Re: Useless sort by

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Gaetano Mendola <mendola(at)gmail(dot)com>, pgsql-performance(at)postgreSQL(dot)org
Subject: Re: Useless sort by
Date: 2010-09-14 07:10:37
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
On 13/09/10 19:48, Tom Lane wrote:
> Gaetano Mendola<mendola(at)gmail(dot)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

In response to


pgsql-performance by date

Next:From: Merlin MoncureDate: 2010-09-14 12:01:05
Subject: Re: Major performance problem after upgrade from 8.3 to 8.4
Previous:From: Gerhard WiesingerDate: 2010-09-14 06:07:18
Subject: Re: Major performance problem after upgrade from 8.3 to 8.4

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