Commit abee4c29 authored by Tom Lane's avatar Tom Lane

Remove extraneous SeqScan node that make_noname was inserting

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...
parent 6defe494
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -895,9 +895,7 @@ copy_costsize(Plan *dest, Plan *src)
/* /*
* make_noname * make_noname
* Create plan nodes to sort or materialize relations into noname. The * Create plan node to sort or materialize relations into noname.
* result returned for a sort will look like (SEQSCAN(SORT(plan_node)))
* or (SEQSCAN(MATERIAL(plan_node)))
* *
* 'tlist' is the target list of the scan to be sorted or materialized * '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 * 'pathkeys' is the list of pathkeys by which the result is to be sorted
...@@ -911,8 +909,7 @@ make_noname(List *tlist, ...@@ -911,8 +909,7 @@ make_noname(List *tlist,
{ {
List *noname_tlist; List *noname_tlist;
int numsortkeys; int numsortkeys;
Plan *tmpplan; Plan *retval;
Noname *retval;
/* Create a new target list for the noname, with sort keys set. */ /* Create a new target list for the noname, with sort keys set. */
noname_tlist = new_unsorted_tlist(tlist); noname_tlist = new_unsorted_tlist(tlist);
...@@ -921,27 +918,21 @@ make_noname(List *tlist, ...@@ -921,27 +918,21 @@ make_noname(List *tlist,
if (numsortkeys > 0) if (numsortkeys > 0)
{ {
/* need to sort */ /* need to sort */
tmpplan = (Plan *) make_sort(noname_tlist, retval = (Plan *) make_sort(noname_tlist,
_NONAME_RELATION_ID_, _NONAME_RELATION_ID_,
plan_node, plan_node,
numsortkeys); numsortkeys);
} }
else else
{ {
/* no sort */ /* no sort */
tmpplan = (Plan *) make_material(noname_tlist, retval = (Plan *) make_material(noname_tlist,
_NONAME_RELATION_ID_, _NONAME_RELATION_ID_,
plan_node, plan_node,
0); 0);
} }
/* Return a seqscan using the original tlist */ return (Noname *) retval;
retval = (Noname *) make_seqscan(tlist,
NIL,
_NONAME_RELATION_ID_,
tmpplan);
return retval;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -82,10 +82,10 @@ set_tlist_references(Plan *plan)
if (IsA_Join(plan)) if (IsA_Join(plan))
set_join_tlist_references((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)) IsA_Noname(plan->lefttree))
set_nonamescan_tlist_references((SeqScan *) plan); set_nonamescan_tlist_references((SeqScan *) plan);
else if (IsA(plan, Sort)) else if (IsA_Noname(plan))
set_noname_tlist_references((Noname *) plan); set_noname_tlist_references((Noname *) plan);
else if (IsA(plan, Result)) else if (IsA(plan, Result))
set_result_tlist_references((Result *) plan); set_result_tlist_references((Result *) plan);
...@@ -112,12 +112,12 @@ set_tlist_references(Plan *plan) ...@@ -112,12 +112,12 @@ set_tlist_references(Plan *plan)
static void static void
set_join_tlist_references(Join *join) set_join_tlist_references(Join *join)
{ {
Plan *outer = ((Plan *) join)->lefttree; Plan *outer = join->lefttree;
Plan *inner = ((Plan *) join)->righttree; Plan *inner = join->righttree;
List *outer_tlist = ((outer == NULL) ? NIL : outer->targetlist); List *outer_tlist = ((outer == NULL) ? NIL : outer->targetlist);
List *inner_tlist = ((inner == NULL) ? NIL : inner->targetlist); List *inner_tlist = ((inner == NULL) ? NIL : inner->targetlist);
List *new_join_targetlist = NIL; List *new_join_targetlist = NIL;
List *qptlist = ((Plan *) join)->targetlist; List *qptlist = join->targetlist;
List *entry; List *entry;
foreach(entry, qptlist) foreach(entry, qptlist)
...@@ -130,18 +130,16 @@ set_join_tlist_references(Join *join) ...@@ -130,18 +130,16 @@ set_join_tlist_references(Join *join)
new_join_targetlist = lappend(new_join_targetlist, new_join_targetlist = lappend(new_join_targetlist,
makeTargetEntry(xtl->resdom, joinexpr)); makeTargetEntry(xtl->resdom, joinexpr));
} }
join->targetlist = new_join_targetlist;
((Plan *) join)->targetlist = new_join_targetlist; set_tlist_references(outer);
if (outer != NULL) set_tlist_references(inner);
set_tlist_references(outer);
if (inner != NULL)
set_tlist_references(inner);
} }
/* /*
* set_nonamescan_tlist_references * set_nonamescan_tlist_references
* Modifies the target list of a node that scans a noname relation (i.e., a * 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 * 'nonamescan' is a seqscan node
* *
...@@ -151,10 +149,13 @@ set_join_tlist_references(Join *join) ...@@ -151,10 +149,13 @@ set_join_tlist_references(Join *join)
static void static void
set_nonamescan_tlist_references(SeqScan *nonamescan) 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, nonamescan->plan.targetlist = tlist_noname_references(noname->nonameid,
((Plan *) nonamescan)->targetlist); 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); set_noname_tlist_references(noname);
} }
...@@ -164,7 +165,7 @@ set_nonamescan_tlist_references(SeqScan *nonamescan) ...@@ -164,7 +165,7 @@ set_nonamescan_tlist_references(SeqScan *nonamescan)
* modified version of the target list of the node from which noname node * modified version of the target list of the node from which noname node
* receives its tuples. * 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. * Returns nothing of interest, but modifies internal fields of nodes.
* *
...@@ -172,13 +173,13 @@ set_nonamescan_tlist_references(SeqScan *nonamescan) ...@@ -172,13 +173,13 @@ set_nonamescan_tlist_references(SeqScan *nonamescan)
static void static void
set_noname_tlist_references(Noname *noname) set_noname_tlist_references(Noname *noname)
{ {
Plan *source = ((Plan *) noname)->lefttree; Plan *source = noname->plan.lefttree;
if (source != NULL) if (source != NULL)
{ {
set_tlist_references(source); set_tlist_references(source);
((Plan *) noname)->targetlist = copy_vars(((Plan *) noname)->targetlist, noname->plan.targetlist = copy_vars(noname->plan.targetlist,
(source)->targetlist); source->targetlist);
} }
else else
elog(ERROR, "calling set_noname_tlist_references with empty lefttree"); elog(ERROR, "calling set_noname_tlist_references with empty lefttree");
......
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