mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Allow avoiding tuple copy within tuplesort_gettupleslot().
Add a "copy" argument to make it optional to receive a copy of caller tuple that is safe to use following a subsequent manipulating of tuplesort's state. This is a performance optimization. Most existing tuplesort_gettupleslot() callers are made to opt out of copying. Existing callers that happen to rely on the validity of tuple memory beyond subsequent manipulations of the tuplesort request their own copy. This brings tuplesort_gettupleslot() in line with tuplestore_gettupleslot(). In the future, a "copy" tuplesort_getdatum() argument may be added, that similarly allows callers to opt out of receiving their own copy of tuple. In passing, clarify assumptions that callers of other tuplesort fetch routines may make about tuple memory validity, per gripe from Tom Lane. Author: Peter Geoghegan Discussion: CAM3SWZQWZZ_N=DmmL7tKy_OUjGH_5mN=N=A6h7kHyyDvEhg2DA@mail.gmail.com
This commit is contained in:
@ -666,6 +666,9 @@ initialize_phase(AggState *aggstate, int newphase)
|
||||
* Fetch a tuple from either the outer plan (for phase 1) or from the sorter
|
||||
* populated by the previous phase. Copy it to the sorter for the next phase
|
||||
* if any.
|
||||
*
|
||||
* Callers cannot rely on memory for tuple in returned slot remaining valid
|
||||
* past any subsequently fetched tuple.
|
||||
*/
|
||||
static TupleTableSlot *
|
||||
fetch_input_tuple(AggState *aggstate)
|
||||
@ -674,8 +677,8 @@ fetch_input_tuple(AggState *aggstate)
|
||||
|
||||
if (aggstate->sort_in)
|
||||
{
|
||||
if (!tuplesort_gettupleslot(aggstate->sort_in, true, aggstate->sort_slot,
|
||||
NULL))
|
||||
if (!tuplesort_gettupleslot(aggstate->sort_in, true, false,
|
||||
aggstate->sort_slot, NULL))
|
||||
return NULL;
|
||||
slot = aggstate->sort_slot;
|
||||
}
|
||||
@ -1409,7 +1412,7 @@ process_ordered_aggregate_multi(AggState *aggstate,
|
||||
ExecClearTuple(slot2);
|
||||
|
||||
while (tuplesort_gettupleslot(pertrans->sortstates[aggstate->current_set],
|
||||
true, slot1, &newAbbrevVal))
|
||||
true, true, slot1, &newAbbrevVal))
|
||||
{
|
||||
/*
|
||||
* Extract the first numTransInputs columns as datums to pass to the
|
||||
|
@ -132,12 +132,13 @@ ExecSort(SortState *node)
|
||||
|
||||
/*
|
||||
* Get the first or next tuple from tuplesort. Returns NULL if no more
|
||||
* tuples.
|
||||
* tuples. Note that we only rely on slot tuple remaining valid until the
|
||||
* next fetch from the tuplesort.
|
||||
*/
|
||||
slot = node->ss.ps.ps_ResultTupleSlot;
|
||||
(void) tuplesort_gettupleslot(tuplesortstate,
|
||||
ScanDirectionIsForward(dir),
|
||||
slot, NULL);
|
||||
false, slot, NULL);
|
||||
return slot;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user