OSDN Git Service

Avoid duplicate ExecTypeFromTL() call in ExecInitJunkFilter() by passing
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 30 Oct 1999 23:13:30 +0000 (23:13 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 30 Oct 1999 23:13:30 +0000 (23:13 +0000)
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.

src/backend/executor/execJunk.c
src/backend/executor/execMain.c
src/backend/executor/nodeAppend.c
src/include/executor/executor.h

index 0484786..2d3fdd9 100644 (file)
@@ -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 $
  *
  *-------------------------------------------------------------------------
  */
  * 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);
index fed4666..d11e341 100644 (file)
@@ -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;
 
index f20d9c5..e041131 100644 (file)
@@ -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;
 }
 
index 662358f..cf9ec0d 100644 (file)
@@ -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);