Re: [PATCH] Use optimized single-datum tuplesort in ExecSort - Mailing list pgsql-hackers

From Ronan Dunklau
Subject Re: [PATCH] Use optimized single-datum tuplesort in ExecSort
Date
Msg-id 3060002.hb0XKQ11pn@aivenronan
Whole thread Raw
In response to Re: [PATCH] Use optimized single-datum tuplesort in ExecSort  (James Coleman <jtc331@gmail.com>)
Responses Re: [PATCH] Use optimized single-datum tuplesort in ExecSort
List pgsql-hackers
Le mardi 6 juillet 2021, 17:37:53 CEST James Coleman a écrit :
> Yes and no. When incremental sort has to do a full sort there will
> always be at least 2 attributes. But in prefix sort mode (see
> prefixsort_state) only non-presorted columns are sorted (i.e., if
> given a,b already sorted by a, then only b is sorted). So the
> prefixsort_state could use this optimization.

The optimization is not when we actually sort on a single key, but when we get
a single attribute in / out of the tuplesort.  Since sorting always add
resjunk entries for the keys being sorted on, I don't think we can ever end up
in a situation where the optimization would kick in, since the entries for the
already-performed-sort keys will need to be present in the output.

Maybe if instead of adding resjunk entries to the whole query's targetlist,
sort and incrementalsort nodes were able to do a projection from the input
(needed tle + resjunk sorting tle) to a tuple containing only the needed tle
on output before actually sorting it, it would be possible, but that would be
quite a big design change.

In the meantime I fixed some formatting issues, please find attached a new
patch.


--
Ronan Dunklau
Attachment

pgsql-hackers by date:

Previous
From: Julien Rouhaud
Date:
Subject: Re: Hook for extensible parsing.
Next
From: Boris Kolpackov
Date:
Subject: Re: Pipeline mode and PQpipelineSync()