1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-21 16:02:15 +03:00

Allow tupleslots to have a fixed tupledesc, use in executor nodes.

The reason for doing so is that it will allow expression evaluation to
optimize based on the underlying tupledesc. In particular it will
allow to JIT tuple deforming together with the expression itself.

For that expression initialization needs to be moved after the
relevant slots are initialized - mostly unproblematic, except in the
case of nodeWorktablescan.c.

After doing so there's no need for ExecAssignResultType() and
ExecAssignResultTypeFromTL() anymore, as all former callers have been
converted to create a slot with a fixed descriptor.

When creating a slot with a fixed descriptor, tts_values/isnull can be
allocated together with the main slot, reducing allocation overhead
and increasing cache density a bit.

Author: Andres Freund
Discussion: https://postgr.es/m/20171206093717.vqdxe5icqttpxs3p@alap3.anarazel.de
This commit is contained in:
Andres Freund
2018-02-16 21:17:38 -08:00
parent bf6c614a2f
commit ad7dbee368
52 changed files with 579 additions and 791 deletions

View File

@ -2287,30 +2287,6 @@ ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags)
"WindowAgg Aggregates",
ALLOCSET_DEFAULT_SIZES);
/*
* tuple table initialization
*/
ExecInitScanTupleSlot(estate, &winstate->ss);
ExecInitResultTupleSlot(estate, &winstate->ss.ps);
winstate->first_part_slot = ExecInitExtraTupleSlot(estate);
winstate->agg_row_slot = ExecInitExtraTupleSlot(estate);
winstate->temp_slot_1 = ExecInitExtraTupleSlot(estate);
winstate->temp_slot_2 = ExecInitExtraTupleSlot(estate);
/*
* create frame head and tail slots only if needed (must match logic in
* update_frameheadpos and update_frametailpos)
*/
winstate->framehead_slot = winstate->frametail_slot = NULL;
if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
{
if (!(frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING))
winstate->framehead_slot = ExecInitExtraTupleSlot(estate);
if (!(frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING))
winstate->frametail_slot = ExecInitExtraTupleSlot(estate);
}
/*
* WindowAgg nodes never have quals, since they can only occur at the
* logical top level of a query (ie, after any WHERE or HAVING filters)
@ -2328,28 +2304,35 @@ ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags)
* initialize source tuple type (which is also the tuple type that we'll
* store in the tuplestore and use in all our working slots).
*/
ExecAssignScanTypeFromOuterPlan(&winstate->ss);
ExecCreateScanSlotFromOuterPlan(estate, &winstate->ss);
scanDesc = winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
ExecSetSlotDescriptor(winstate->first_part_slot,
winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor);
ExecSetSlotDescriptor(winstate->agg_row_slot,
winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor);
ExecSetSlotDescriptor(winstate->temp_slot_1,
winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor);
ExecSetSlotDescriptor(winstate->temp_slot_2,
winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor);
if (winstate->framehead_slot)
ExecSetSlotDescriptor(winstate->framehead_slot,
winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor);
if (winstate->frametail_slot)
ExecSetSlotDescriptor(winstate->frametail_slot,
winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor);
/*
* tuple table initialization
*/
winstate->first_part_slot = ExecInitExtraTupleSlot(estate, scanDesc);
winstate->agg_row_slot = ExecInitExtraTupleSlot(estate, scanDesc);
winstate->temp_slot_1 = ExecInitExtraTupleSlot(estate, scanDesc);
winstate->temp_slot_2 = ExecInitExtraTupleSlot(estate, scanDesc);
/*
* Initialize result tuple type and projection info.
* create frame head and tail slots only if needed (must match logic in
* update_frameheadpos and update_frametailpos)
*/
ExecAssignResultTypeFromTL(&winstate->ss.ps);
winstate->framehead_slot = winstate->frametail_slot = NULL;
if (frameOptions & (FRAMEOPTION_RANGE | FRAMEOPTION_GROUPS))
{
if (!(frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING))
winstate->framehead_slot = ExecInitExtraTupleSlot(estate, scanDesc);
if (!(frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING))
winstate->frametail_slot = ExecInitExtraTupleSlot(estate, scanDesc);
}
/*
* Initialize result slot, type and projection.
*/
ExecInitResultTupleSlotTL(estate, &winstate->ss.ps);
ExecAssignProjectionInfo(&winstate->ss.ps, NULL);
/* Set up data for comparing tuples */