Re: PoC: Partial sort - Mailing list pgsql-hackers

From Andreas Karlsson
Subject Re: PoC: Partial sort
Date
Msg-id 55745ECE.6080009@proxel.se
Whole thread Raw
In response to Re: PoC: Partial sort  (Alexander Korotkov <aekorotkov@gmail.com>)
Responses Re: PoC: Partial sort  (Peter Geoghegan <pg@heroku.com>)
List pgsql-hackers
On 09/15/2014 01:58 PM, Alexander Korotkov wrote:
> On Sun, Sep 14, 2014 at 9:32 AM, Peter Geoghegan <pg@heroku.com
> <mailto:pg@heroku.com>> wrote:
>
>     I think we might be better off if a tuplesort function was called
>     shortly after tuplesort_begin_heap() is called. How top-n heap sorts
>     work is something that largely lives in tuplesort's head. Today, we
>     call tuplesort_set_bound() to hint to tuplesort "By the way, this is a
>     top-n heap sort applicable sort". I think that with this patch, we
>     should then hint (where applicable) "by the way, you won't actually be
>     required to sort those first n indexed attributes; rather, you can
>     expect to scan those in logical order. You may work the rest out
>     yourself, and may be clever about exploiting the sorted-ness of the
>     first few columns". The idea of managing a bunch of tiny sorts from
>     with ExecSort(), and calling the new function tuplesort_reset() seems
>     questionable. tuplesortstate is supposed to be private/opaque to
>     nodeSort.c, and the current design strains that.
>
>     I'd like to keep nodeSort.c simple. I think it's pretty clear that the
>     guts of this do not belong within ExecSort(), in any case. Also, the
>     additions there should be much better commented, wherever they finally
>     end up.
>
>
> As I understand, you propose to incapsulate partial sort algorithm into
> tuplesort. However, in this case we anyway need some significant change
> of its interface: let tuplesort decide when it's able to return tuple.
> Otherwise, we would miss significant part of LIMIT clause optimization.
> tuplesort_set_bound() can't solve all the cases. There could be other
> planner nodes between the partial sort and LIMIT.

Hi,

Are you planning to work on this patch for 9.6?

I generally agree with Peter that the changes to the sorting probably 
belong in the tuplesort code rather than in the executor. This way it 
should also be theoretically possible to support mark/restore.

Andreas



pgsql-hackers by date:

Previous
From: Fabien COELHO
Date:
Subject: Re: checkpointer continuous flushing
Next
From: Jeff Janes
Date:
Subject: Re: [CORE] Restore-reliability mode