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

Re: Unexpected sort order.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Unexpected sort order.
Date: 2006-11-27 22:05:27
Message-ID: 24807.1164665127@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-general
Jeff Davis <pgsql(at)j-davis(dot)com> writes:
> On Mon, 2006-11-27 at 12:44 -0800, Ron Mayer wrote:
>> Shouldn't the results of this query shown here been sorted by "b" rather than by "a"?

>> li=# select * from (select (random()*10)::int as a, (random()*10)::int as b from generate_series(1,10) order by a) as x order by b;

> It looks like a planner bug.

It looks to me like the planner thinks that order by a and order by b
are equivalent because the expressions are equal(); hence it discards
what it thinks is a redundant second sort step.

I suppose we could add a check for whether the sort expression contains
volatile functions before believing this, but I'm having a hard time
believing that there are any real-world cases where the check wouldn't
be a waste of cycles.  What's the use-case for sorting by a volatile
expression in the first place?

			regards, tom lane

In response to

Responses

pgsql-bugs by date

Next:From: Ron MayerDate: 2006-11-27 22:10:08
Subject: Re: Unexpected sort order (suspected bug)
Previous:From: Shawn TaylerDate: 2006-11-27 21:53:28
Subject: BUG #2788: Create Function operator Broken?

pgsql-general by date

Next:From: Ron MayerDate: 2006-11-27 22:10:08
Subject: Re: Unexpected sort order (suspected bug)
Previous:From: Martijn van OosterhoutDate: 2006-11-27 21:51:18
Subject: Re: fatal error on 8.1 server

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