Re: Evaluation of secondary sort key. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Evaluation of secondary sort key.
Date
Msg-id 4066.1302368049@sss.pgh.pa.us
Whole thread Raw
In response to Re: Evaluation of secondary sort key.  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: Evaluation of secondary sort key.  (Jesper Krogh <jesper@krogh.cc>)
Re: Evaluation of secondary sort key.  (Jesper Krogh <jesper@krogh.cc>)
List pgsql-hackers
Martijn van Oosterhout <kleptog@svana.org> writes:
> On Sat, Apr 09, 2011 at 09:17:10AM -0700, David Fetter wrote:
>>> It seems strange that there is a need to evaluate testsort(id) at
>>> all in this case.

>> How would PostgreSQL know that sorting by id leaves no ambiguity for
>> the next key to address?

> Well, it doesn't know that, but I guess the point is it could wait with
> evaluating the second key until it needs it.

I think that would be a positive disimprovement.  The current design
guarantees that volatile sort expressions are evaluated exactly once,
in the order the rows are read from the data source.  There would be no
guarantees at all, either as to the number of evaluations or the order
in which they happen, if we tried to do evaluation only during the
actual sort.

Another small problem is that any such thing would require carrying
along some kind of closure (ie, the expression and all its input
values), not just the final sort key value, in tuples being sorted.
The ensuing complexity, speed penalty, and increase in data volume
to be sorted would be paid by everybody, making this probably a net
performance loss when considered across all applications.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Evaluation of secondary sort key.
Next
From: Tom Lane
Date:
Subject: Re: using a lot of maintenance_work_mem