diff --git a/src/backend/executor/execJunk.c b/src/backend/executor/execJunk.c index 0484786794..2d3fdd9228 100644 --- a/src/backend/executor/execJunk.c +++ b/src/backend/executor/execJunk.c @@ -7,7 +7,7 @@ * * * 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 @@ * ExecInitJunkFilter * * Initialize the Junk filter. + * + * The initial targetlist and associated tuple descriptor are passed in. *------------------------------------------------------------------------- */ JunkFilter * -ExecInitJunkFilter(List *targetList) +ExecInitJunkFilter(List *targetList, TupleDesc tupType) { JunkFilter *junkfilter; List *cleanTargetList; int len, cleanLength; - TupleDesc tupType, - cleanTupType; + TupleDesc cleanTupType; List *t; TargetEntry *tle; Resdom *resdom, @@ -154,15 +155,11 @@ ExecInitJunkFilter(List *targetList) } /* --------------------- - * Now calculate the tuple types for the original and the clean tuple - * - * XXX ExecTypeFromTL should be used sparingly. Don't we already - * have the tupType corresponding to the targetlist we are passed? - * -cim 5/31/91 + * Now calculate the tuple type for the cleaned tuple (we were already + * given the type for the original targetlist). * --------------------- */ - tupType = (TupleDesc) ExecTypeFromTL(targetList); - cleanTupType = (TupleDesc) ExecTypeFromTL(cleanTargetList); + cleanTupType = ExecTypeFromTL(cleanTargetList); len = ExecTargetListLength(targetList); cleanLength = ExecTargetListLength(cleanTargetList); diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index fed4666aee..d11e3414dd 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * 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) Relation intoRelationDesc; TupleDesc tupType; List *targetList; - int len; /* * get information from query descriptor @@ -655,40 +654,43 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate) */ tupType = ExecGetTupType(plan); /* tuple descriptor */ targetList = plan->targetlist; - len = ExecTargetListLength(targetList); /* number of attributes */ /* - * now that we have the target list, initialize the junk filter if - * this is a REPLACE or a DELETE query. We also init the junk filter - * if this is an append query (there might be some rule lock info - * there...) NOTE: in the future we might want to initialize the junk - * 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. + * Now that we have the target list, initialize the junk filter if needed. + * SELECT and INSERT queries need a filter if there are any junk attrs + * in the tlist. UPDATE and DELETE always need one, since there's always + * a junk 'ctid' attribute present --- no need to look first. */ { bool junk_filter_needed = false; List *tlist; - if (operation == CMD_SELECT) + switch (operation) { - foreach(tlist, targetList) - { - TargetEntry *tle = lfirst(tlist); - - if (tle->resdom->resjunk) + case CMD_SELECT: + case CMD_INSERT: + foreach(tlist, targetList) { - junk_filter_needed = true; - break; + TargetEntry *tle = (TargetEntry *) lfirst(tlist); + + 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 || - operation == CMD_INSERT || - (operation == CMD_SELECT && junk_filter_needed)) + if (junk_filter_needed) { - JunkFilter *j = (JunkFilter *) ExecInitJunkFilter(targetList); + JunkFilter *j = ExecInitJunkFilter(targetList, tupType); estate->es_junkFilter = j; diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c index f20d9c56bc..e04113149f 100644 --- a/src/backend/executor/nodeAppend.c +++ b/src/backend/executor/nodeAppend.c @@ -7,7 +7,7 @@ * * * 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) for (i = 0; i < nplans; i++) { - JunkFilter *j; - List *targetList; - /* ---------------- * NOTE: we first modify range table in * exec_append_initialize_next() and @@ -302,9 +299,8 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) if ((es_rri != (RelationInfo *) NULL) && (node->inheritrelid == es_rri->ri_RangeTableIndex)) { - - targetList = initNode->targetlist; - j = (JunkFilter *) ExecInitJunkFilter(targetList); + JunkFilter *j = ExecInitJunkFilter(initNode->targetlist, + ExecGetTupType(initNode)); junkList = lappend(junkList, j); } @@ -318,9 +314,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) * ---------------- */ initNode = (Plan *) nth(0, appendplans); - ExecAssignResultType(&appendstate->cstate, -/* ExecGetExecTupDesc(initNode), */ - ExecGetTupType(initNode)); + ExecAssignResultType(&appendstate->cstate, ExecGetTupType(initNode)); appendstate->cstate.cs_ProjInfo = NULL; /* ---------------- @@ -329,9 +323,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) */ appendstate->as_whichplan = 0; exec_append_initialize_next(node); -#ifdef NOT_USED - result = (List *) initialized[0]; -#endif + return TRUE; } diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index 662358f459..cf9ec0d291 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -6,7 +6,7 @@ * * 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); /* * 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, char *attrName, Datum *value, bool *isNull); extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot);