Remove extraneous SeqScan node that make_noname was inserting
authorTom Lane
Wed, 18 Aug 1999 04:15:16 +0000 (04:15 +0000)
committerTom Lane
Wed, 18 Aug 1999 04:15:16 +0000 (04:15 +0000)
above a Sort or Materialize node.  As far as I can tell, the only place
that actually needed that was set_tlist_references, which was being lazy
about checking to see if it had a noname node to fix or not...

src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/setrefs.c

index 3310bf5f925f2423920e20616bcc2e6ef9d8fbac..40923fe27dadc731cabaaa8f10bddf5f866d982b 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.72 1999/08/16 23:07:20 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.73 1999/08/18 04:15:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -895,9 +895,7 @@ copy_costsize(Plan *dest, Plan *src)
 
 /*
  * make_noname
- *   Create plan nodes to sort or materialize relations into noname. The
- *   result returned for a sort will look like (SEQSCAN(SORT(plan_node)))
- *   or (SEQSCAN(MATERIAL(plan_node)))
+ *   Create plan node to sort or materialize relations into noname.
  *
  *   'tlist' is the target list of the scan to be sorted or materialized
  *   'pathkeys' is the list of pathkeys by which the result is to be sorted
@@ -911,8 +909,7 @@ make_noname(List *tlist,
 {
    List       *noname_tlist;
    int         numsortkeys;
-   Plan       *tmpplan;
-   Noname     *retval;
+   Plan       *retval;
 
    /* Create a new target list for the noname, with sort keys set. */
    noname_tlist = new_unsorted_tlist(tlist);
@@ -921,27 +918,21 @@ make_noname(List *tlist,
    if (numsortkeys > 0)
    {
        /* need to sort */
-       tmpplan = (Plan *) make_sort(noname_tlist,
-                                    _NONAME_RELATION_ID_,
-                                    plan_node,
-                                    numsortkeys);
+       retval = (Plan *) make_sort(noname_tlist,
+                                   _NONAME_RELATION_ID_,
+                                   plan_node,
+                                   numsortkeys);
    }
    else
    {
        /* no sort */
-       tmpplan = (Plan *) make_material(noname_tlist,
-                                        _NONAME_RELATION_ID_,
-                                        plan_node,
-                                        0);
+       retval = (Plan *) make_material(noname_tlist,
+                                       _NONAME_RELATION_ID_,
+                                       plan_node,
+                                       0);
    }
 
-   /* Return a seqscan using the original tlist */
-   retval = (Noname *) make_seqscan(tlist,
-                                    NIL,
-                                    _NONAME_RELATION_ID_,
-                                    tmpplan);
-
-   return retval;
+   return (Noname *) retval;
 }
 
 
index c4c19780ca9a29cf99dd4adefa67fa7744e819e6..6471ad4e41bca77bd00da20169e030baa5e03047 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.54 1999/08/09 00:56:05 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.55 1999/08/18 04:15:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -82,10 +82,10 @@ set_tlist_references(Plan *plan)
 
    if (IsA_Join(plan))
        set_join_tlist_references((Join *) plan);
-   else if (IsA(plan, SeqScan) &&plan->lefttree &&
+   else if (IsA(plan, SeqScan) && plan->lefttree &&
             IsA_Noname(plan->lefttree))
        set_nonamescan_tlist_references((SeqScan *) plan);
-   else if (IsA(plan, Sort))
+   else if (IsA_Noname(plan))
        set_noname_tlist_references((Noname *) plan);
    else if (IsA(plan, Result))
        set_result_tlist_references((Result *) plan);
@@ -112,12 +112,12 @@ set_tlist_references(Plan *plan)
 static void
 set_join_tlist_references(Join *join)
 {
-   Plan       *outer = ((Plan *) join)->lefttree;
-   Plan       *inner = ((Plan *) join)->righttree;
+   Plan       *outer = join->lefttree;
+   Plan       *inner = join->righttree;
    List       *outer_tlist = ((outer == NULL) ? NIL : outer->targetlist);
    List       *inner_tlist = ((inner == NULL) ? NIL : inner->targetlist);
    List       *new_join_targetlist = NIL;
-   List       *qptlist = ((Plan *) join)->targetlist;
+   List       *qptlist = join->targetlist;
    List       *entry;
 
    foreach(entry, qptlist)
@@ -130,18 +130,16 @@ set_join_tlist_references(Join *join)
        new_join_targetlist = lappend(new_join_targetlist,
                                      makeTargetEntry(xtl->resdom, joinexpr));
    }
+   join->targetlist = new_join_targetlist;
 
-   ((Plan *) join)->targetlist = new_join_targetlist;
-   if (outer != NULL)
-       set_tlist_references(outer);
-   if (inner != NULL)
-       set_tlist_references(inner);
+   set_tlist_references(outer);
+   set_tlist_references(inner);
 }
 
 /*
  * set_nonamescan_tlist_references
  *   Modifies the target list of a node that scans a noname relation (i.e., a
- *   sort or hash node) so that the varnos refer to the child noname.
+ *   sort or materialize node) so that the varnos refer to the child noname.
  *
  * 'nonamescan' is a seqscan node
  *
@@ -151,10 +149,13 @@ set_join_tlist_references(Join *join)
 static void
 set_nonamescan_tlist_references(SeqScan *nonamescan)
 {
-   Noname     *noname = (Noname *) ((Plan *) nonamescan)->lefttree;
+   Noname     *noname = (Noname *) nonamescan->plan.lefttree;
 
-   ((Plan *) nonamescan)->targetlist = tlist_noname_references(noname->nonameid,
-                                     ((Plan *) nonamescan)->targetlist);
+   nonamescan->plan.targetlist = tlist_noname_references(noname->nonameid,
+                                     nonamescan->plan.targetlist);
+   /* since we know child is a Noname, skip recursion through
+    * set_tlist_references() and just get the job done
+    */
    set_noname_tlist_references(noname);
 }
 
@@ -164,7 +165,7 @@ set_nonamescan_tlist_references(SeqScan *nonamescan)
  *   modified version of the target list of the node from which noname node
  *   receives its tuples.
  *
- * 'noname' is a noname (e.g., sort, hash) plan node
+ * 'noname' is a noname (e.g., sort, materialize) plan node
  *
  * Returns nothing of interest, but modifies internal fields of nodes.
  *
@@ -172,13 +173,13 @@ set_nonamescan_tlist_references(SeqScan *nonamescan)
 static void
 set_noname_tlist_references(Noname *noname)
 {
-   Plan       *source = ((Plan *) noname)->lefttree;
+   Plan       *source = noname->plan.lefttree;
 
    if (source != NULL)
    {
        set_tlist_references(source);
-       ((Plan *) noname)->targetlist = copy_vars(((Plan *) noname)->targetlist,
-                                                 (source)->targetlist);
+       noname->plan.targetlist = copy_vars(noname->plan.targetlist,
+                                           source->targetlist);
    }
    else
        elog(ERROR, "calling set_noname_tlist_references with empty lefttree");