diff options
author | Andres Freund <andres@anarazel.de> | 2018-11-15 22:00:30 -0800 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2018-11-15 22:00:30 -0800 |
commit | 1a0586de3657cd35581f0639c87d5050c6197bb7 (patch) | |
tree | bcbf7206344c4e5b1bda4ba5f49d1f43e09ba167 /src/backend/executor/execTuples.c | |
parent | 763f2edd92095b1ca2f4476da073a28505c13820 (diff) | |
download | postgresql-1a0586de3657cd35581f0639c87d5050c6197bb7.tar.gz postgresql-1a0586de3657cd35581f0639c87d5050c6197bb7.zip |
Introduce notion of different types of slots (without implementing them).
Upcoming work intends to allow pluggable ways to introduce new ways of
storing table data. Accessing those table access methods from the
executor requires TupleTableSlots to be carry tuples in the native
format of such storage methods; otherwise there'll be a significant
conversion overhead.
Different access methods will require different data to store tuples
efficiently (just like virtual, minimal, heap already require fields
in TupleTableSlot). To allow that without requiring additional pointer
indirections, we want to have different structs (embedding
TupleTableSlot) for different types of slots. Thus different types of
slots are needed, which requires adapting creators of slots.
The slot that most efficiently can represent a type of tuple in an
executor node will often depend on the type of slot a child node
uses. Therefore we need to track the type of slot is returned by
nodes, so parent slots can create slots based on that.
Relatedly, JIT compilation of tuple deforming needs to know which type
of slot a certain expression refers to, so it can create an
appropriate deforming function for the type of tuple in the slot.
But not all nodes will only return one type of slot, e.g. an append
node will potentially return different types of slots for each of its
subplans.
Therefore add function that allows to query the type of a node's
result slot, and whether it'll always be the same type (whether it's
fixed). This can be queried using ExecGetResultSlotOps().
The scan, result, inner, outer type of slots are automatically
inferred from ExecInitScanTupleSlot(), ExecInitResultSlot(),
left/right subtrees respectively. If that's not correct for a node,
that can be overwritten using new fields in PlanState.
This commit does not introduce the actually abstracted implementation
of different kind of TupleTableSlots, that will be left for a followup
commit. The different types of slots introduced will, for now, still
use the same backing implementation.
While this already partially invalidates the big comment in
tuptable.h, it seems to make more sense to update it later, when the
different TupleTableSlot implementations actually exist.
Author: Ashutosh Bapat and Andres Freund, with changes by Amit Khandekar
Discussion: https://postgr.es/m/20181105210039.hh4vvi4vwoq5ba2q@alap3.anarazel.de
Diffstat (limited to 'src/backend/executor/execTuples.c')
-rw-r--r-- | src/backend/executor/execTuples.c | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c index 391db672d1d..2cd7e5c8669 100644 --- a/src/backend/executor/execTuples.c +++ b/src/backend/executor/execTuples.c @@ -73,6 +73,12 @@ static TupleDesc ExecTypeFromTLInternal(List *targetList, bool hasoid, bool skipjunk); +const TupleTableSlotOps TTSOpsVirtual; +const TupleTableSlotOps TTSOpsHeapTuple; +const TupleTableSlotOps TTSOpsMinimalTuple; +const TupleTableSlotOps TTSOpsBufferTuple; + + /* ---------------------------------------------------------------- * tuple table create/delete functions * ---------------------------------------------------------------- @@ -87,7 +93,8 @@ static TupleDesc ExecTypeFromTLInternal(List *targetList, * -------------------------------- */ TupleTableSlot * -MakeTupleTableSlot(TupleDesc tupleDesc) +MakeTupleTableSlot(TupleDesc tupleDesc, + const TupleTableSlotOps *tts_ops) { Size sz; TupleTableSlot *slot; @@ -104,6 +111,8 @@ MakeTupleTableSlot(TupleDesc tupleDesc) sz = sizeof(TupleTableSlot); slot = palloc0(sz); + /* const for optimization purposes, OK to modify at allocation time */ + *((const TupleTableSlotOps **) &slot->tts_ops) = tts_ops; slot->type = T_TupleTableSlot; slot->tts_flags |= TTS_FLAG_EMPTY; if (tupleDesc != NULL) @@ -140,9 +149,10 @@ MakeTupleTableSlot(TupleDesc tupleDesc) * -------------------------------- */ TupleTableSlot * -ExecAllocTableSlot(List **tupleTable, TupleDesc desc) +ExecAllocTableSlot(List **tupleTable, TupleDesc desc, + const TupleTableSlotOps *tts_ops) { - TupleTableSlot *slot = MakeTupleTableSlot(desc); + TupleTableSlot *slot = MakeTupleTableSlot(desc, tts_ops); *tupleTable = lappend(*tupleTable, slot); @@ -198,16 +208,17 @@ ExecResetTupleTable(List *tupleTable, /* tuple table */ /* -------------------------------- * MakeSingleTupleTableSlot * - * This is a convenience routine for operations that need a - * standalone TupleTableSlot not gotten from the main executor - * tuple table. It makes a single slot and initializes it - * to use the given tuple descriptor. + * This is a convenience routine for operations that need a standalone + * TupleTableSlot not gotten from the main executor tuple table. It makes + * a single slot of given TupleTableSlotType and initializes it to use the + * given tuple descriptor. * -------------------------------- */ TupleTableSlot * -MakeSingleTupleTableSlot(TupleDesc tupdesc) +MakeSingleTupleTableSlot(TupleDesc tupdesc, + const TupleTableSlotOps *tts_ops) { - TupleTableSlot *slot = MakeTupleTableSlot(tupdesc); + TupleTableSlot *slot = MakeTupleTableSlot(tupdesc, tts_ops); return slot; } @@ -964,13 +975,17 @@ ExecInitResultTypeTL(PlanState *planstate) * ---------------- */ void -ExecInitResultSlot(PlanState *planstate) +ExecInitResultSlot(PlanState *planstate, const TupleTableSlotOps *tts_ops) { TupleTableSlot *slot; slot = ExecAllocTableSlot(&planstate->state->es_tupleTable, - planstate->ps_ResultTupleDesc); + planstate->ps_ResultTupleDesc, tts_ops); planstate->ps_ResultTupleSlot = slot; + + planstate->resultopsfixed = planstate->ps_ResultTupleDesc != NULL; + planstate->resultops = tts_ops; + planstate->resultopsset = true; } /* ---------------- @@ -980,10 +995,11 @@ ExecInitResultSlot(PlanState *planstate) * ---------------- */ void -ExecInitResultTupleSlotTL(PlanState *planstate) +ExecInitResultTupleSlotTL(PlanState *planstate, + const TupleTableSlotOps *tts_ops) { ExecInitResultTypeTL(planstate); - ExecInitResultSlot(planstate); + ExecInitResultSlot(planstate, tts_ops); } /* ---------------- @@ -991,11 +1007,15 @@ ExecInitResultTupleSlotTL(PlanState *planstate) * ---------------- */ void -ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc) +ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, + TupleDesc tupledesc, const TupleTableSlotOps *tts_ops) { scanstate->ss_ScanTupleSlot = ExecAllocTableSlot(&estate->es_tupleTable, - tupledesc); + tupledesc, tts_ops); scanstate->ps.scandesc = tupledesc; + scanstate->ps.scanopsfixed = tupledesc != NULL; + scanstate->ps.scanops = tts_ops; + scanstate->ps.scanopsset = true; } /* ---------------- @@ -1007,9 +1027,11 @@ ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc) * ---------------- */ TupleTableSlot * -ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc) +ExecInitExtraTupleSlot(EState *estate, + TupleDesc tupledesc, + const TupleTableSlotOps *tts_ops) { - return ExecAllocTableSlot(&estate->es_tupleTable, tupledesc); + return ExecAllocTableSlot(&estate->es_tupleTable, tupledesc, tts_ops); } /* ---------------- @@ -1021,9 +1043,10 @@ ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc) * ---------------- */ TupleTableSlot * -ExecInitNullTupleSlot(EState *estate, TupleDesc tupType) +ExecInitNullTupleSlot(EState *estate, TupleDesc tupType, + const TupleTableSlotOps *tts_ops) { - TupleTableSlot *slot = ExecInitExtraTupleSlot(estate, tupType); + TupleTableSlot *slot = ExecInitExtraTupleSlot(estate, tupType, tts_ops); return ExecStoreAllNullTuple(slot); } @@ -1547,13 +1570,15 @@ HeapTupleHeaderGetDatum(HeapTupleHeader tuple) * table function capability. Currently used by EXPLAIN and SHOW ALL. */ TupOutputState * -begin_tup_output_tupdesc(DestReceiver *dest, TupleDesc tupdesc) +begin_tup_output_tupdesc(DestReceiver *dest, + TupleDesc tupdesc, + const TupleTableSlotOps *tts_ops) { TupOutputState *tstate; tstate = (TupOutputState *) palloc(sizeof(TupOutputState)); - tstate->slot = MakeSingleTupleTableSlot(tupdesc); + tstate->slot = MakeSingleTupleTableSlot(tupdesc, tts_ops); tstate->dest = dest; tstate->dest->rStartup(tstate->dest, (int) CMD_SELECT, tupdesc); |