Re: union vs. sort
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Karel Zak <zakkr@zf.jcu.cz>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2004-04-07T18:20:55Z
Lists: pgsql-hackers
Karel Zak <zakkr@zf.jcu.cz> writes:
> On Tue, Apr 06, 2004 at 10:33:25AM -0400, Tom Lane wrote:
>> This isn't simply a matter of "omitting the sort".
> I didn't talk about "Append" result, but about "Unique" result. The
> ORDER BY in UNION query works with final concanated data -- that's
> right. My question is why a result from this ORDER BY is again sorted:
Oh, okay, that's just something that never got done, per this old
comment:
/*
* We set current_pathkeys NIL indicating we do not know sort
* order. This is correct when the top set operation is UNION
* ALL, since the appended-together results are unsorted even if
* the subplans were sorted. For other set operations we could be
* smarter --- room for future improvement!
*/
I've committed changes to do the right thing in CVS tip.
regards, tom lane