Commit f92e8a4b authored by Tom Lane's avatar Tom Lane

Replace the array-style TupleTable data structure with a simple List of

TupleTableSlot nodes.  This eliminates the need to count in advance
how many Slots will be needed, which seems more than worth the small
increase in the amount of palloc traffic during executor startup.

The ExecCountSlots infrastructure is now all dead code, but I'll remove it
in a separate commit for clarity.

Per a comment from Robert Haas.
parent 61be11ff
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.328 2009/09/26 22:42:01 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.329 2009/09/27 20:09:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -755,40 +755,12 @@ InitPlan(QueryDesc *queryDesc, int eflags) ...@@ -755,40 +755,12 @@ InitPlan(QueryDesc *queryDesc, int eflags)
} }
/* /*
* Initialize the executor "tuple" table. We need slots for all the plan * Initialize the executor's tuple table. Also, if it's not a SELECT,
* nodes, plus possibly output slots for the junkfilter(s). At this point * set up a tuple table slot for use for trigger output tuples.
* we aren't sure if we need junkfilters, so just add slots for them
* unconditionally. Also, if it's not a SELECT, set up a slot for use for
* trigger output tuples. Also, one for RETURNING-list evaluation.
*/ */
{ estate->es_tupleTable = NIL;
int nSlots;
/* Slots for the main plan tree */
nSlots = ExecCountSlotsNode(plan);
/* Add slots for subplans and initplans */
foreach(l, plannedstmt->subplans)
{
Plan *subplan = (Plan *) lfirst(l);
nSlots += ExecCountSlotsNode(subplan);
}
/* Add slots for junkfilter(s) */
if (plannedstmt->resultRelations != NIL)
nSlots += list_length(plannedstmt->resultRelations);
else
nSlots += 1;
if (operation != CMD_SELECT)
nSlots++; /* for es_trig_tuple_slot */
if (plannedstmt->returningLists)
nSlots++; /* for RETURNING projection */
estate->es_tupleTable = ExecCreateTupleTable(nSlots);
if (operation != CMD_SELECT) if (operation != CMD_SELECT)
estate->es_trig_tuple_slot = estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate);
ExecAllocTableSlot(estate->es_tupleTable);
}
/* mark EvalPlanQual not active */ /* mark EvalPlanQual not active */
estate->es_plannedstmt = plannedstmt; estate->es_plannedstmt = plannedstmt;
...@@ -909,7 +881,7 @@ InitPlan(QueryDesc *queryDesc, int eflags) ...@@ -909,7 +881,7 @@ InitPlan(QueryDesc *queryDesc, int eflags)
j = ExecInitJunkFilter(subplan->plan->targetlist, j = ExecInitJunkFilter(subplan->plan->targetlist,
resultRelInfo->ri_RelationDesc->rd_att->tdhasoid, resultRelInfo->ri_RelationDesc->rd_att->tdhasoid,
ExecAllocTableSlot(estate->es_tupleTable)); ExecInitExtraTupleSlot(estate));
/* /*
* Since it must be UPDATE/DELETE, there had better be a * Since it must be UPDATE/DELETE, there had better be a
...@@ -953,7 +925,7 @@ InitPlan(QueryDesc *queryDesc, int eflags) ...@@ -953,7 +925,7 @@ InitPlan(QueryDesc *queryDesc, int eflags)
j = ExecInitJunkFilter(planstate->plan->targetlist, j = ExecInitJunkFilter(planstate->plan->targetlist,
tupType->tdhasoid, tupType->tdhasoid,
ExecAllocTableSlot(estate->es_tupleTable)); ExecInitExtraTupleSlot(estate));
estate->es_junkFilter = j; estate->es_junkFilter = j;
if (estate->es_result_relation_info) if (estate->es_result_relation_info)
estate->es_result_relation_info->ri_junkFilter = j; estate->es_result_relation_info->ri_junkFilter = j;
...@@ -1026,7 +998,7 @@ InitPlan(QueryDesc *queryDesc, int eflags) ...@@ -1026,7 +998,7 @@ InitPlan(QueryDesc *queryDesc, int eflags)
false); false);
/* Set up a slot for the output of the RETURNING projection(s) */ /* Set up a slot for the output of the RETURNING projection(s) */
slot = ExecAllocTableSlot(estate->es_tupleTable); slot = ExecInitExtraTupleSlot(estate);
ExecSetSlotDescriptor(slot, tupType); ExecSetSlotDescriptor(slot, tupType);
/* Need an econtext too */ /* Need an econtext too */
econtext = CreateExprContext(estate); econtext = CreateExprContext(estate);
...@@ -1387,10 +1359,12 @@ ExecEndPlan(PlanState *planstate, EState *estate) ...@@ -1387,10 +1359,12 @@ ExecEndPlan(PlanState *planstate, EState *estate)
} }
/* /*
* destroy the executor "tuple" table. * destroy the executor's tuple table. Actually we only care about
* releasing buffer pins and tupdesc refcounts; there's no need to
* pfree the TupleTableSlots, since the containing memory context
* is about to go away anyway.
*/ */
ExecDropTupleTable(estate->es_tupleTable, true); ExecResetTupleTable(estate->es_tupleTable, false);
estate->es_tupleTable = NULL;
/* /*
* close the result relation(s) if any, but hold locks until xact commit. * close the result relation(s) if any, but hold locks until xact commit.
...@@ -2712,10 +2686,9 @@ EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq) ...@@ -2712,10 +2686,9 @@ EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq)
epqstate->es_evTuple = priorepq->estate->es_evTuple; epqstate->es_evTuple = priorepq->estate->es_evTuple;
/* /*
* Create sub-tuple-table; we needn't redo the CountSlots work though. * Each epqstate also has its own tuple table.
*/ */
epqstate->es_tupleTable = epqstate->es_tupleTable = NIL;
ExecCreateTupleTable(estate->es_tupleTable->size);
/* /*
* Initialize private state information for each SubPlan. We must do this * Initialize private state information for each SubPlan. We must do this
...@@ -2770,8 +2743,9 @@ EvalPlanQualStop(evalPlanQual *epq) ...@@ -2770,8 +2743,9 @@ EvalPlanQualStop(evalPlanQual *epq)
ExecEndNode(subplanstate); ExecEndNode(subplanstate);
} }
ExecDropTupleTable(epqstate->es_tupleTable, true); /* throw away the per-epqstate tuple table completely */
epqstate->es_tupleTable = NULL; ExecResetTupleTable(epqstate->es_tupleTable, true);
epqstate->es_tupleTable = NIL;
if (epqstate->es_evTuple[epq->rti - 1] != NULL) if (epqstate->es_evTuple[epq->rti - 1] != NULL)
{ {
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* execTuples.c * execTuples.c
* Routines dealing with the executor tuple tables. These are used to * Routines dealing with TupleTableSlots. These are used for resource
* ensure that the executor frees copies of tuples (made by * management associated with tuples (eg, releasing buffer pins for
* ExecTargetList) properly. * tuples in disk buffers, or freeing the memory occupied by transient
* tuples). Slots also provide access abstraction that lets us implement
* "virtual" tuples to reduce data-copying overhead.
* *
* Routines dealing with the type information for tuples. Currently, * Routines dealing with the type information for tuples. Currently,
* the type information for a tuple is an array of FormData_pg_attribute. * the type information for a tuple is an array of FormData_pg_attribute.
...@@ -15,21 +17,19 @@ ...@@ -15,21 +17,19 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.109 2009/07/23 21:27:10 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.110 2009/09/27 20:09:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
/* /*
* INTERFACE ROUTINES * INTERFACE ROUTINES
* *
* TABLE CREATE/DELETE * SLOT CREATION/DESTRUCTION
* ExecCreateTupleTable - create a new tuple table * MakeTupleTableSlot - create an empty slot
* ExecDropTupleTable - destroy a table * ExecAllocTableSlot - create a slot within a tuple table
* MakeSingleTupleTableSlot - make a single-slot table * ExecResetTupleTable - clear and optionally delete a tuple table
* ExecDropSingleTupleTableSlot - destroy same * MakeSingleTupleTableSlot - make a standalone slot, set its descriptor
* * ExecDropSingleTupleTableSlot - destroy a standalone slot
* SLOT RESERVATION
* ExecAllocTableSlot - find an available slot in the table
* *
* SLOT ACCESSORS * SLOT ACCESSORS
* ExecSetSlotDescriptor - set a slot's tuple descriptor * ExecSetSlotDescriptor - set a slot's tuple descriptor
...@@ -57,12 +57,9 @@ ...@@ -57,12 +57,9 @@
* *
* At ExecutorStart() * At ExecutorStart()
* ---------------- * ----------------
* - InitPlan() calls ExecCreateTupleTable() to create the tuple
* table which will hold tuples processed by the executor.
*
* - ExecInitSeqScan() calls ExecInitScanTupleSlot() and * - ExecInitSeqScan() calls ExecInitScanTupleSlot() and
* ExecInitResultTupleSlot() to reserve places in the tuple * ExecInitResultTupleSlot() to construct TupleTableSlots
* table for the tuples returned by the access methods and the * for the tuples returned by the access methods and the
* tuples resulting from performing target list projections. * tuples resulting from performing target list projections.
* *
* During ExecutorRun() * During ExecutorRun()
...@@ -79,7 +76,7 @@ ...@@ -79,7 +76,7 @@
* *
* At ExecutorEnd() * At ExecutorEnd()
* ---------------- * ----------------
* - EndPlan() calls ExecDropTupleTable() to clean up any remaining * - EndPlan() calls ExecResetTupleTable() to clean up any remaining
* tuples left over from executing the query. * tuples left over from executing the query.
* *
* The important thing to watch in the executor code is how pointers * The important thing to watch in the executor code is how pointers
...@@ -110,41 +107,16 @@ static TupleDesc ExecTypeFromTLInternal(List *targetList, ...@@ -110,41 +107,16 @@ static TupleDesc ExecTypeFromTLInternal(List *targetList,
*/ */
/* -------------------------------- /* --------------------------------
* ExecCreateTupleTable * MakeTupleTableSlot
*
* This creates a new tuple table of the specified size.
* *
* This should be used by InitPlan() to allocate the table. * Basic routine to make an empty TupleTableSlot.
* The table's address will be stored in the EState structure.
* -------------------------------- * --------------------------------
*/ */
TupleTable TupleTableSlot *
ExecCreateTupleTable(int tableSize) MakeTupleTableSlot(void)
{ {
TupleTable newtable; TupleTableSlot *slot = makeNode(TupleTableSlot);
int i;
/*
* sanity checks
*/
Assert(tableSize >= 1);
/*
* allocate the table itself
*/
newtable = (TupleTable) palloc(sizeof(TupleTableData) +
(tableSize - 1) *sizeof(TupleTableSlot));
newtable->size = tableSize;
newtable->next = 0;
/*
* initialize all the slots to empty states
*/
for (i = 0; i < tableSize; i++)
{
TupleTableSlot *slot = &(newtable->array[i]);
slot->type = T_TupleTableSlot;
slot->tts_isempty = true; slot->tts_isempty = true;
slot->tts_shouldFree = false; slot->tts_shouldFree = false;
slot->tts_shouldFreeMin = false; slot->tts_shouldFreeMin = false;
...@@ -156,57 +128,70 @@ ExecCreateTupleTable(int tableSize) ...@@ -156,57 +128,70 @@ ExecCreateTupleTable(int tableSize)
slot->tts_values = NULL; slot->tts_values = NULL;
slot->tts_isnull = NULL; slot->tts_isnull = NULL;
slot->tts_mintuple = NULL; slot->tts_mintuple = NULL;
}
return newtable; return slot;
} }
/* -------------------------------- /* --------------------------------
* ExecDropTupleTable * ExecAllocTableSlot
* *
* This frees the storage used by the tuple table itself * Create a tuple table slot within a tuple table (which is just a List).
* and optionally frees the contents of the table also. * --------------------------------
*/
TupleTableSlot *
ExecAllocTableSlot(List **tupleTable)
{
TupleTableSlot *slot = MakeTupleTableSlot();
*tupleTable = lappend(*tupleTable, slot);
return slot;
}
/* --------------------------------
* ExecResetTupleTable
*
* This releases any resources (buffer pins, tupdesc refcounts)
* held by the tuple table, and optionally releases the memory
* occupied by the tuple table data structure.
* It is expected that this routine be called by EndPlan(). * It is expected that this routine be called by EndPlan().
* -------------------------------- * --------------------------------
*/ */
void void
ExecDropTupleTable(TupleTable table, /* tuple table */ ExecResetTupleTable(List *tupleTable, /* tuple table */
bool shouldFree) /* true if we should free slot bool shouldFree) /* true if we should free memory */
* contents */
{ {
/* ListCell *lc;
* sanity checks
*/
Assert(table != NULL);
/* foreach(lc, tupleTable)
* first free all the valid pointers in the tuple array and drop refcounts
* of any referenced buffers, if that's what the caller wants. (There is
* probably no good reason for the caller ever not to want it!)
*/
if (shouldFree)
{ {
int next = table->next; TupleTableSlot *slot = (TupleTableSlot *) lfirst(lc);
int i;
for (i = 0; i < next; i++) /* Sanity checks */
{ Assert(IsA(slot, TupleTableSlot));
TupleTableSlot *slot = &(table->array[i]);
/* Always release resources and reset the slot to empty */
ExecClearTuple(slot); ExecClearTuple(slot);
if (slot->tts_tupleDescriptor) if (slot->tts_tupleDescriptor)
{
ReleaseTupleDesc(slot->tts_tupleDescriptor); ReleaseTupleDesc(slot->tts_tupleDescriptor);
slot->tts_tupleDescriptor = NULL;
}
/* If shouldFree, release memory occupied by the slot itself */
if (shouldFree)
{
if (slot->tts_values) if (slot->tts_values)
pfree(slot->tts_values); pfree(slot->tts_values);
if (slot->tts_isnull) if (slot->tts_isnull)
pfree(slot->tts_isnull); pfree(slot->tts_isnull);
pfree(slot);
} }
} }
/* /* If shouldFree, release the list structure */
* finally free the tuple table itself. if (shouldFree)
*/ list_free(tupleTable);
pfree(table);
} }
/* -------------------------------- /* --------------------------------
...@@ -214,27 +199,14 @@ ExecDropTupleTable(TupleTable table, /* tuple table */ ...@@ -214,27 +199,14 @@ ExecDropTupleTable(TupleTable table, /* tuple table */
* *
* This is a convenience routine for operations that need a * This is a convenience routine for operations that need a
* standalone TupleTableSlot not gotten from the main executor * standalone TupleTableSlot not gotten from the main executor
* tuple table. It makes a single slot and initializes it as * tuple table. It makes a single slot and initializes it
* though by ExecSetSlotDescriptor(slot, tupdesc). * to use the given tuple descriptor.
* -------------------------------- * --------------------------------
*/ */
TupleTableSlot * TupleTableSlot *
MakeSingleTupleTableSlot(TupleDesc tupdesc) MakeSingleTupleTableSlot(TupleDesc tupdesc)
{ {
TupleTableSlot *slot = makeNode(TupleTableSlot); TupleTableSlot *slot = MakeTupleTableSlot();
/* This should match ExecCreateTupleTable() */
slot->tts_isempty = true;
slot->tts_shouldFree = false;
slot->tts_shouldFreeMin = false;
slot->tts_tuple = NULL;
slot->tts_tupleDescriptor = NULL;
slot->tts_mcxt = CurrentMemoryContext;
slot->tts_buffer = InvalidBuffer;
slot->tts_nvalid = 0;
slot->tts_values = NULL;
slot->tts_isnull = NULL;
slot->tts_mintuple = NULL;
ExecSetSlotDescriptor(slot, tupdesc); ExecSetSlotDescriptor(slot, tupdesc);
...@@ -245,16 +217,14 @@ MakeSingleTupleTableSlot(TupleDesc tupdesc) ...@@ -245,16 +217,14 @@ MakeSingleTupleTableSlot(TupleDesc tupdesc)
* ExecDropSingleTupleTableSlot * ExecDropSingleTupleTableSlot
* *
* Release a TupleTableSlot made with MakeSingleTupleTableSlot. * Release a TupleTableSlot made with MakeSingleTupleTableSlot.
* DON'T use this on a slot that's part of a tuple table list!
* -------------------------------- * --------------------------------
*/ */
void void
ExecDropSingleTupleTableSlot(TupleTableSlot *slot) ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
{ {
/* /* This should match ExecResetTupleTable's processing of one slot */
* sanity checks Assert(IsA(slot, TupleTableSlot));
*/
Assert(slot != NULL);
ExecClearTuple(slot); ExecClearTuple(slot);
if (slot->tts_tupleDescriptor) if (slot->tts_tupleDescriptor)
ReleaseTupleDesc(slot->tts_tupleDescriptor); ReleaseTupleDesc(slot->tts_tupleDescriptor);
...@@ -262,50 +232,10 @@ ExecDropSingleTupleTableSlot(TupleTableSlot *slot) ...@@ -262,50 +232,10 @@ ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
pfree(slot->tts_values); pfree(slot->tts_values);
if (slot->tts_isnull) if (slot->tts_isnull)
pfree(slot->tts_isnull); pfree(slot->tts_isnull);
pfree(slot); pfree(slot);
} }
/* ----------------------------------------------------------------
* tuple table slot reservation functions
* ----------------------------------------------------------------
*/
/* --------------------------------
* ExecAllocTableSlot
*
* This routine is used to reserve slots in the table for
* use by the various plan nodes. It is expected to be
* called by the node init routines (ex: ExecInitNestLoop)
* once per slot needed by the node. Not all nodes need
* slots (some just pass tuples around).
* --------------------------------
*/
TupleTableSlot *
ExecAllocTableSlot(TupleTable table)
{
int slotnum; /* new slot number */
/*
* sanity checks
*/
Assert(table != NULL);
/*
* We expect that the table was made big enough to begin with. We cannot
* reallocate it on the fly since previous plan nodes have already got
* pointers to individual entries.
*/
if (table->next >= table->size)
elog(ERROR, "plan requires more slots than are available");
slotnum = table->next;
table->next++;
return &(table->array[slotnum]);
}
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* tuple table slot accessor functions * tuple table slot accessor functions
* ---------------------------------------------------------------- * ----------------------------------------------------------------
...@@ -915,7 +845,7 @@ ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot) ...@@ -915,7 +845,7 @@ ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
void void
ExecInitResultTupleSlot(EState *estate, PlanState *planstate) ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
{ {
planstate->ps_ResultTupleSlot = ExecAllocTableSlot(estate->es_tupleTable); planstate->ps_ResultTupleSlot = ExecAllocTableSlot(&estate->es_tupleTable);
} }
/* ---------------- /* ----------------
...@@ -925,7 +855,7 @@ ExecInitResultTupleSlot(EState *estate, PlanState *planstate) ...@@ -925,7 +855,7 @@ ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
void void
ExecInitScanTupleSlot(EState *estate, ScanState *scanstate) ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
{ {
scanstate->ss_ScanTupleSlot = ExecAllocTableSlot(estate->es_tupleTable); scanstate->ss_ScanTupleSlot = ExecAllocTableSlot(&estate->es_tupleTable);
} }
/* ---------------- /* ----------------
...@@ -935,7 +865,7 @@ ExecInitScanTupleSlot(EState *estate, ScanState *scanstate) ...@@ -935,7 +865,7 @@ ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
TupleTableSlot * TupleTableSlot *
ExecInitExtraTupleSlot(EState *estate) ExecInitExtraTupleSlot(EState *estate)
{ {
return ExecAllocTableSlot(estate->es_tupleTable); return ExecAllocTableSlot(&estate->es_tupleTable);
} }
/* ---------------- /* ----------------
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.161 2009/07/29 20:56:18 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.162 2009/09/27 20:09:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -197,7 +197,7 @@ CreateExecutorState(void) ...@@ -197,7 +197,7 @@ CreateExecutorState(void)
estate->es_query_cxt = qcontext; estate->es_query_cxt = qcontext;
estate->es_tupleTable = NULL; estate->es_tupleTable = NIL;
estate->es_processed = 0; estate->es_processed = 0;
estate->es_lastoid = InvalidOid; estate->es_lastoid = InvalidOid;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.99 2009/06/11 14:48:57 momjian Exp $ * $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.100 2009/09/27 20:09:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -721,7 +721,6 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent) ...@@ -721,7 +721,6 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
int ncols, int ncols,
i; i;
TupleDesc tupDesc; TupleDesc tupDesc;
TupleTable tupTable;
TupleTableSlot *slot; TupleTableSlot *slot;
List *oplist, List *oplist,
*lefttlist, *lefttlist,
...@@ -852,15 +851,6 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent) ...@@ -852,15 +851,6 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
i++; i++;
} }
/*
* Create a tupletable to hold these tuples. (Note: we never bother
* to free the tupletable explicitly; that's okay because it will
* never store raw disk tuples that might have associated buffer pins.
* The only resource involved is memory, which will be cleaned up by
* freeing the query context.)
*/
tupTable = ExecCreateTupleTable(2);
/* /*
* Construct tupdescs, slots and projection nodes for left and right * Construct tupdescs, slots and projection nodes for left and right
* sides. The lefthand expressions will be evaluated in the parent * sides. The lefthand expressions will be evaluated in the parent
...@@ -870,7 +860,7 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent) ...@@ -870,7 +860,7 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
* own innerecontext. * own innerecontext.
*/ */
tupDesc = ExecTypeFromTL(leftptlist, false); tupDesc = ExecTypeFromTL(leftptlist, false);
slot = ExecAllocTableSlot(tupTable); slot = ExecInitExtraTupleSlot(estate);
ExecSetSlotDescriptor(slot, tupDesc); ExecSetSlotDescriptor(slot, tupDesc);
sstate->projLeft = ExecBuildProjectionInfo(lefttlist, sstate->projLeft = ExecBuildProjectionInfo(lefttlist,
NULL, NULL,
...@@ -878,7 +868,7 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent) ...@@ -878,7 +868,7 @@ ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
NULL); NULL);
tupDesc = ExecTypeFromTL(rightptlist, false); tupDesc = ExecTypeFromTL(rightptlist, false);
slot = ExecAllocTableSlot(tupTable); slot = ExecInitExtraTupleSlot(estate);
ExecSetSlotDescriptor(slot, tupDesc); ExecSetSlotDescriptor(slot, tupDesc);
sstate->projRight = ExecBuildProjectionInfo(righttlist, sstate->projRight = ExecBuildProjectionInfo(righttlist,
sstate->innerecontext, sstate->innerecontext,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/executor/tuptable.h,v 1.42 2009/06/11 14:49:11 momjian Exp $ * $PostgreSQL: pgsql/src/include/executor/tuptable.h,v 1.43 2009/09/27 20:09:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "storage/buf.h" #include "storage/buf.h"
/*---------- /*----------
* The executor stores tuples in a "tuple table" which is composed of * The executor stores tuples in a "tuple table" which is a List of
* independent TupleTableSlots. There are several cases we need to handle: * independent TupleTableSlots. There are several cases we need to handle:
* 1. physical tuple in a disk buffer page * 1. physical tuple in a disk buffer page
* 2. physical tuple constructed in palloc'ed memory * 2. physical tuple constructed in palloc'ed memory
...@@ -112,7 +112,7 @@ ...@@ -112,7 +112,7 @@
*/ */
typedef struct TupleTableSlot typedef struct TupleTableSlot
{ {
NodeTag type; /* vestigial ... allows IsA tests */ NodeTag type;
bool tts_isempty; /* true = slot is empty */ bool tts_isempty; /* true = slot is empty */
bool tts_shouldFree; /* should pfree tts_tuple? */ bool tts_shouldFree; /* should pfree tts_tuple? */
bool tts_shouldFreeMin; /* should pfree tts_mintuple? */ bool tts_shouldFreeMin; /* should pfree tts_mintuple? */
...@@ -132,19 +132,6 @@ typedef struct TupleTableSlot ...@@ -132,19 +132,6 @@ typedef struct TupleTableSlot
#define TTS_HAS_PHYSICAL_TUPLE(slot) \ #define TTS_HAS_PHYSICAL_TUPLE(slot) \
((slot)->tts_tuple != NULL && (slot)->tts_tuple != &((slot)->tts_minhdr)) ((slot)->tts_tuple != NULL && (slot)->tts_tuple != &((slot)->tts_minhdr))
/*
* Tuple table data structure: an array of TupleTableSlots.
*/
typedef struct TupleTableData
{
int size; /* size of the table (number of slots) */
int next; /* next available slot number */
TupleTableSlot array[1]; /* VARIABLE LENGTH ARRAY - must be last */
} TupleTableData; /* VARIABLE LENGTH STRUCT */
typedef TupleTableData *TupleTable;
/* /*
* TupIsNull -- is a TupleTableSlot empty? * TupIsNull -- is a TupleTableSlot empty?
*/ */
...@@ -152,11 +139,11 @@ typedef TupleTableData *TupleTable; ...@@ -152,11 +139,11 @@ typedef TupleTableData *TupleTable;
((slot) == NULL || (slot)->tts_isempty) ((slot) == NULL || (slot)->tts_isempty)
/* in executor/execTuples.c */ /* in executor/execTuples.c */
extern TupleTable ExecCreateTupleTable(int tableSize); extern TupleTableSlot *MakeTupleTableSlot(void);
extern void ExecDropTupleTable(TupleTable table, bool shouldFree); extern TupleTableSlot *ExecAllocTableSlot(List **tupleTable);
extern void ExecResetTupleTable(List *tupleTable, bool shouldFree);
extern TupleTableSlot *MakeSingleTupleTableSlot(TupleDesc tupdesc); extern TupleTableSlot *MakeSingleTupleTableSlot(TupleDesc tupdesc);
extern void ExecDropSingleTupleTableSlot(TupleTableSlot *slot); extern void ExecDropSingleTupleTableSlot(TupleTableSlot *slot);
extern TupleTableSlot *ExecAllocTableSlot(TupleTable table);
extern void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc); extern void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc);
extern TupleTableSlot *ExecStoreTuple(HeapTuple tuple, extern TupleTableSlot *ExecStoreTuple(HeapTuple tuple,
TupleTableSlot *slot, TupleTableSlot *slot,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.207 2009/08/23 18:26:08 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.208 2009/09/27 20:09:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -352,7 +352,7 @@ typedef struct EState ...@@ -352,7 +352,7 @@ typedef struct EState
/* Other working state: */ /* Other working state: */
MemoryContext es_query_cxt; /* per-query context in which EState lives */ MemoryContext es_query_cxt; /* per-query context in which EState lives */
TupleTable es_tupleTable; /* Array of TupleTableSlots */ List *es_tupleTable; /* List of TupleTableSlots */
uint32 es_processed; /* # of tuples processed */ uint32 es_processed; /* # of tuples processed */
Oid es_lastoid; /* last oid processed (by INSERT) */ Oid es_lastoid; /* last oid processed (by INSERT) */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment