Commit 5b9d655b authored by Tom Lane's avatar Tom Lane

Avoid duplicate ExecTypeFromTL() call in ExecInitJunkFilter() by passing

in the TupleDesc that the caller already has (for call from ExecMain) or
can make just as easily as ExecInitJunkFilter() can (for call from
ExecAppend).  Also, don't bother to build a junk filter for an INSERT
operation that doesn't actually need one, which is the normal case.
parent 4ce4d7f7
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.20 1999/07/17 20:16:56 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.21 1999/10/30 23:13:30 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -55,17 +55,18 @@ ...@@ -55,17 +55,18 @@
* ExecInitJunkFilter * ExecInitJunkFilter
* *
* Initialize the Junk filter. * Initialize the Junk filter.
*
* The initial targetlist and associated tuple descriptor are passed in.
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
JunkFilter * JunkFilter *
ExecInitJunkFilter(List *targetList) ExecInitJunkFilter(List *targetList, TupleDesc tupType)
{ {
JunkFilter *junkfilter; JunkFilter *junkfilter;
List *cleanTargetList; List *cleanTargetList;
int len, int len,
cleanLength; cleanLength;
TupleDesc tupType, TupleDesc cleanTupType;
cleanTupType;
List *t; List *t;
TargetEntry *tle; TargetEntry *tle;
Resdom *resdom, Resdom *resdom,
...@@ -154,15 +155,11 @@ ExecInitJunkFilter(List *targetList) ...@@ -154,15 +155,11 @@ ExecInitJunkFilter(List *targetList)
} }
/* --------------------- /* ---------------------
* Now calculate the tuple types for the original and the clean tuple * Now calculate the tuple type for the cleaned tuple (we were already
* * given the type for the original targetlist).
* XXX ExecTypeFromTL should be used sparingly. Don't we already
* have the tupType corresponding to the targetlist we are passed?
* -cim 5/31/91
* --------------------- * ---------------------
*/ */
tupType = (TupleDesc) ExecTypeFromTL(targetList); cleanTupType = ExecTypeFromTL(cleanTargetList);
cleanTupType = (TupleDesc) ExecTypeFromTL(cleanTargetList);
len = ExecTargetListLength(targetList); len = ExecTargetListLength(targetList);
cleanLength = ExecTargetListLength(cleanTargetList); cleanLength = ExecTargetListLength(cleanTargetList);
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.97 1999/10/07 04:23:01 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.98 1999/10/30 23:13:30 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -529,7 +529,6 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate) ...@@ -529,7 +529,6 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
Relation intoRelationDesc; Relation intoRelationDesc;
TupleDesc tupType; TupleDesc tupType;
List *targetList; List *targetList;
int len;
/* /*
* get information from query descriptor * get information from query descriptor
...@@ -655,40 +654,43 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate) ...@@ -655,40 +654,43 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
*/ */
tupType = ExecGetTupType(plan); /* tuple descriptor */ tupType = ExecGetTupType(plan); /* tuple descriptor */
targetList = plan->targetlist; targetList = plan->targetlist;
len = ExecTargetListLength(targetList); /* number of attributes */
/* /*
* now that we have the target list, initialize the junk filter if * Now that we have the target list, initialize the junk filter if needed.
* this is a REPLACE or a DELETE query. We also init the junk filter * SELECT and INSERT queries need a filter if there are any junk attrs
* if this is an append query (there might be some rule lock info * in the tlist. UPDATE and DELETE always need one, since there's always
* there...) NOTE: in the future we might want to initialize the junk * a junk 'ctid' attribute present --- no need to look first.
* filter for all queries. SELECT added by daveh@insightdist.com
* 5/20/98 to allow ORDER/GROUP BY have an identifier missing from the
* target.
*/ */
{ {
bool junk_filter_needed = false; bool junk_filter_needed = false;
List *tlist; List *tlist;
if (operation == CMD_SELECT) switch (operation)
{ {
foreach(tlist, targetList) case CMD_SELECT:
{ case CMD_INSERT:
TargetEntry *tle = lfirst(tlist); foreach(tlist, targetList)
if (tle->resdom->resjunk)
{ {
junk_filter_needed = true; TargetEntry *tle = (TargetEntry *) lfirst(tlist);
break;
if (tle->resdom->resjunk)
{
junk_filter_needed = true;
break;
}
} }
} break;
case CMD_UPDATE:
case CMD_DELETE:
junk_filter_needed = true;
break;
default:
break;
} }
if (operation == CMD_UPDATE || operation == CMD_DELETE || if (junk_filter_needed)
operation == CMD_INSERT ||
(operation == CMD_SELECT && junk_filter_needed))
{ {
JunkFilter *j = (JunkFilter *) ExecInitJunkFilter(targetList); JunkFilter *j = ExecInitJunkFilter(targetList, tupType);
estate->es_junkFilter = j; estate->es_junkFilter = j;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.26 1999/09/24 00:24:23 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.27 1999/10/30 23:13:30 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -276,9 +276,6 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) ...@@ -276,9 +276,6 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
for (i = 0; i < nplans; i++) for (i = 0; i < nplans; i++)
{ {
JunkFilter *j;
List *targetList;
/* ---------------- /* ----------------
* NOTE: we first modify range table in * NOTE: we first modify range table in
* exec_append_initialize_next() and * exec_append_initialize_next() and
...@@ -302,9 +299,8 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) ...@@ -302,9 +299,8 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
if ((es_rri != (RelationInfo *) NULL) && if ((es_rri != (RelationInfo *) NULL) &&
(node->inheritrelid == es_rri->ri_RangeTableIndex)) (node->inheritrelid == es_rri->ri_RangeTableIndex))
{ {
JunkFilter *j = ExecInitJunkFilter(initNode->targetlist,
targetList = initNode->targetlist; ExecGetTupType(initNode));
j = (JunkFilter *) ExecInitJunkFilter(targetList);
junkList = lappend(junkList, j); junkList = lappend(junkList, j);
} }
...@@ -318,9 +314,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) ...@@ -318,9 +314,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
* ---------------- * ----------------
*/ */
initNode = (Plan *) nth(0, appendplans); initNode = (Plan *) nth(0, appendplans);
ExecAssignResultType(&appendstate->cstate, ExecAssignResultType(&appendstate->cstate, ExecGetTupType(initNode));
/* ExecGetExecTupDesc(initNode), */
ExecGetTupType(initNode));
appendstate->cstate.cs_ProjInfo = NULL; appendstate->cstate.cs_ProjInfo = NULL;
/* ---------------- /* ----------------
...@@ -329,9 +323,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) ...@@ -329,9 +323,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
*/ */
appendstate->as_whichplan = 0; appendstate->as_whichplan = 0;
exec_append_initialize_next(node); exec_append_initialize_next(node);
#ifdef NOT_USED
result = (List *) initialized[0];
#endif
return TRUE; return TRUE;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: executor.h,v 1.38 1999/09/24 00:25:10 tgl Exp $ * $Id: executor.h,v 1.39 1999/10/30 23:13:30 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -53,7 +53,7 @@ extern Relation ExecCreatR(TupleDesc tupType, Oid relationOid); ...@@ -53,7 +53,7 @@ extern Relation ExecCreatR(TupleDesc tupType, Oid relationOid);
/* /*
* prototypes from functions in execJunk.c * prototypes from functions in execJunk.c
*/ */
extern JunkFilter *ExecInitJunkFilter(List *targetList); extern JunkFilter *ExecInitJunkFilter(List *targetList, TupleDesc tupType);
extern bool ExecGetJunkAttribute(JunkFilter *junkfilter, TupleTableSlot *slot, extern bool ExecGetJunkAttribute(JunkFilter *junkfilter, TupleTableSlot *slot,
char *attrName, Datum *value, bool *isNull); char *attrName, Datum *value, bool *isNull);
extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot); extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot);
......
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