*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
/*
* 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
{
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);
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;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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);
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)
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
*
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);
}
* 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.
*
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");