Re: ORDER BY vs. volatile functions

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane), Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ORDER BY vs. volatile functions
Date: 2009-11-16 19:10:23
Message-ID: 87d43igv4w.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

Tom> Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com> writes:
>> [1] http://archives.postgresql.org/pgsql-general/2006-11/msg01544.php

Tom> FWIW, the behavior has changed from the time of that discussion ---
Tom> we now track sort ordering using EquivalenceClasses, which are able
Tom> to distinguish different instances of textually equal() volatile
Tom> expressions. The particular cases of
Tom> select random() from foo order by 1;
Tom> select random() from foo order by random();
Tom> still behave the same, but that's intentional for backwards
Tom> compatibility (and because SQL99 forbids the first, which would mean
Tom> there's no way to get the behavior except via deprecated syntax).

SQL99 doesn't forbid:

select random() as r from foo order by r;

or

select r from (select random() as r from foo) as s order by r;

--
Andrew (irc:RhodiumToad)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2009-11-16 19:17:25 Re: Unpredictable shark slowdown after migrating to 8.4
Previous Message Robert Haas 2009-11-16 19:10:10 Re: Update on Insert