Commit ffb087ce authored by Bruce Momjian's avatar Bruce Momjian

This patch refactors execTuples.c in two ways.

Neil Conway
parent 8f61184d
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.73 2003/11/29 19:51:48 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.74 2003/12/01 23:09:02 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -112,6 +112,8 @@ ...@@ -112,6 +112,8 @@
#include "executor/executor.h" #include "executor/executor.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
static TupleDesc ExecTypeFromTLInternal(List *targetList,
bool hasoid, bool skipjunk);
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* tuple table create/delete functions * tuple table create/delete functions
...@@ -469,13 +471,6 @@ ExecSetSlotDescriptorIsNew(TupleTableSlot *slot, /* slot to change */ ...@@ -469,13 +471,6 @@ ExecSetSlotDescriptorIsNew(TupleTableSlot *slot, /* slot to change */
* is used for initializing special-purpose slots. * is used for initializing special-purpose slots.
* -------------------------------- * --------------------------------
*/ */
#define INIT_SLOT_DEFS \
TupleTable tupleTable; \
TupleTableSlot* slot
#define INIT_SLOT_ALLOC \
tupleTable = (TupleTable) estate->es_tupleTable; \
slot = ExecAllocTableSlot(tupleTable);
/* ---------------- /* ----------------
* ExecInitResultTupleSlot * ExecInitResultTupleSlot
...@@ -484,9 +479,7 @@ ExecSetSlotDescriptorIsNew(TupleTableSlot *slot, /* slot to change */ ...@@ -484,9 +479,7 @@ ExecSetSlotDescriptorIsNew(TupleTableSlot *slot, /* slot to change */
void void
ExecInitResultTupleSlot(EState *estate, PlanState *planstate) ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
{ {
INIT_SLOT_DEFS; planstate->ps_ResultTupleSlot = ExecAllocTableSlot(estate->es_tupleTable);
INIT_SLOT_ALLOC;
planstate->ps_ResultTupleSlot = slot;
} }
/* ---------------- /* ----------------
...@@ -496,9 +489,7 @@ ExecInitResultTupleSlot(EState *estate, PlanState *planstate) ...@@ -496,9 +489,7 @@ ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
void void
ExecInitScanTupleSlot(EState *estate, ScanState *scanstate) ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
{ {
INIT_SLOT_DEFS; scanstate->ss_ScanTupleSlot = ExecAllocTableSlot(estate->es_tupleTable);
INIT_SLOT_ALLOC;
scanstate->ss_ScanTupleSlot = slot;
} }
/* ---------------- /* ----------------
...@@ -508,9 +499,7 @@ ExecInitScanTupleSlot(EState *estate, ScanState *scanstate) ...@@ -508,9 +499,7 @@ ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
TupleTableSlot * TupleTableSlot *
ExecInitExtraTupleSlot(EState *estate) ExecInitExtraTupleSlot(EState *estate)
{ {
INIT_SLOT_DEFS; return ExecAllocTableSlot(estate->es_tupleTable);
INIT_SLOT_ALLOC;
return slot;
} }
/* ---------------- /* ----------------
...@@ -560,34 +549,7 @@ ExecInitNullTupleSlot(EState *estate, TupleDesc tupType) ...@@ -560,34 +549,7 @@ ExecInitNullTupleSlot(EState *estate, TupleDesc tupType)
TupleDesc TupleDesc
ExecTypeFromTL(List *targetList, bool hasoid) ExecTypeFromTL(List *targetList, bool hasoid)
{ {
TupleDesc typeInfo; return ExecTypeFromTLInternal(targetList, hasoid, false);
List *tlitem;
int len;
/*
* allocate a new typeInfo
*/
len = ExecTargetListLength(targetList);
typeInfo = CreateTemplateTupleDesc(len, hasoid);
/*
* scan list, generate type info for each entry
*/
foreach(tlitem, targetList)
{
TargetEntry *tle = lfirst(tlitem);
Resdom *resdom = tle->resdom;
TupleDescInitEntry(typeInfo,
resdom->resno,
resdom->resname,
resdom->restype,
resdom->restypmod,
0,
false);
}
return typeInfo;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
...@@ -598,31 +560,33 @@ ExecTypeFromTL(List *targetList, bool hasoid) ...@@ -598,31 +560,33 @@ ExecTypeFromTL(List *targetList, bool hasoid)
*/ */
TupleDesc TupleDesc
ExecCleanTypeFromTL(List *targetList, bool hasoid) ExecCleanTypeFromTL(List *targetList, bool hasoid)
{
return ExecTypeFromTLInternal(targetList, hasoid, true);
}
static TupleDesc
ExecTypeFromTLInternal(List *targetList, bool hasoid, bool skipjunk)
{ {
TupleDesc typeInfo; TupleDesc typeInfo;
List *tlitem; List *l;
int len; int len;
int cleanresno; int cur_resno = 1;
/* if (skipjunk)
* allocate a new typeInfo
*/
len = ExecCleanTargetListLength(targetList); len = ExecCleanTargetListLength(targetList);
else
len = ExecTargetListLength(targetList);
typeInfo = CreateTemplateTupleDesc(len, hasoid); typeInfo = CreateTemplateTupleDesc(len, hasoid);
/* foreach(l, targetList)
* scan list, generate type info for each entry
*/
cleanresno = 1;
foreach(tlitem, targetList)
{ {
TargetEntry *tle = lfirst(tlitem); TargetEntry *tle = lfirst(l);
Resdom *resdom = tle->resdom; Resdom *resdom = tle->resdom;
if (resdom->resjunk) if (skipjunk && resdom->resjunk)
continue; continue;
TupleDescInitEntry(typeInfo, TupleDescInitEntry(typeInfo,
cleanresno++, cur_resno++,
resdom->resname, resdom->resname,
resdom->restype, resdom->restype,
resdom->restypmod, resdom->restypmod,
......
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