mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Turn the rangetable used by the executor into a flat list, and avoid storing
useless substructure for its RangeTblEntry nodes. (I chose to keep using the same struct node type and just zero out the link fields for unneeded info, rather than making a separate ExecRangeTblEntry type --- it seemed too fragile to have two different rangetable representations.) Along the way, put subplans into a list in the toplevel PlannedStmt node, and have SubPlan nodes refer to them by list index instead of direct pointers. Vadim wanted to do that years ago, but I never understood what he was on about until now. It makes things a *whole* lot more robust, because we can stop worrying about duplicate processing of subplans during expression tree traversals. That's been a constant source of bugs, and it's finally gone. There are some consequent simplifications yet to be made, like not using a separate EState for subplans in the executor, but I'll tackle that later.
This commit is contained in:
@ -22,7 +22,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.138 2007/02/19 07:03:30 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.139 2007/02/22 22:00:24 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -169,6 +169,7 @@ recurse_set_operations(Node *setOp, PlannerInfo *root,
|
||||
RangeTblRef *rtr = (RangeTblRef *) setOp;
|
||||
RangeTblEntry *rte = rt_fetch(rtr->rtindex, root->parse->rtable);
|
||||
Query *subquery = rte->subquery;
|
||||
PlannerInfo *subroot;
|
||||
Plan *subplan,
|
||||
*plan;
|
||||
|
||||
@ -180,7 +181,7 @@ recurse_set_operations(Node *setOp, PlannerInfo *root,
|
||||
subplan = subquery_planner(root->glob, subquery,
|
||||
root->query_level + 1,
|
||||
tuple_fraction,
|
||||
NULL);
|
||||
&subroot);
|
||||
|
||||
/*
|
||||
* Add a SubqueryScan with the caller-requested targetlist
|
||||
@ -193,7 +194,8 @@ recurse_set_operations(Node *setOp, PlannerInfo *root,
|
||||
refnames_tlist),
|
||||
NIL,
|
||||
rtr->rtindex,
|
||||
subplan);
|
||||
subplan,
|
||||
subroot->parse->rtable);
|
||||
|
||||
/*
|
||||
* We don't bother to determine the subquery's output ordering since
|
||||
@ -223,7 +225,7 @@ recurse_set_operations(Node *setOp, PlannerInfo *root,
|
||||
* output columns.
|
||||
*
|
||||
* XXX you don't really want to know about this: setrefs.c will apply
|
||||
* replace_vars_with_subplan_refs() to the Result node's tlist. This
|
||||
* fix_upper_expr() to the Result node's tlist. This
|
||||
* would fail if the Vars generated by generate_setop_tlist() were not
|
||||
* exactly equal() to the corresponding tlist entries of the subplan.
|
||||
* However, since the subplan was generated by generate_union_plan()
|
||||
@ -235,7 +237,8 @@ recurse_set_operations(Node *setOp, PlannerInfo *root,
|
||||
!tlist_same_datatypes(plan->targetlist, colTypes, junkOK))
|
||||
{
|
||||
plan = (Plan *)
|
||||
make_result(generate_setop_tlist(colTypes, flag,
|
||||
make_result(root,
|
||||
generate_setop_tlist(colTypes, flag,
|
||||
0,
|
||||
false,
|
||||
plan->targetlist,
|
||||
@ -1216,28 +1219,6 @@ adjust_appendrel_attrs_mutator(Node *node, AppendRelInfo *context)
|
||||
Assert(!IsA(node, SubLink));
|
||||
Assert(!IsA(node, Query));
|
||||
|
||||
/*
|
||||
* BUT: although we don't need to recurse into subplans, we do need to
|
||||
* make sure that they are copied, not just referenced as
|
||||
* expression_tree_mutator will do by default. Otherwise we'll have the
|
||||
* same subplan node referenced from each arm of the finished APPEND plan,
|
||||
* which will cause trouble in the executor. This is a kluge that should
|
||||
* go away when we redesign querytrees.
|
||||
*/
|
||||
if (is_subplan(node))
|
||||
{
|
||||
SubPlan *subplan;
|
||||
|
||||
/* Copy the node and process subplan args */
|
||||
node = expression_tree_mutator(node, adjust_appendrel_attrs_mutator,
|
||||
(void *) context);
|
||||
/* Make sure we have separate copies of subplan and its rtable */
|
||||
subplan = (SubPlan *) node;
|
||||
subplan->plan = copyObject(subplan->plan);
|
||||
subplan->rtable = copyObject(subplan->rtable);
|
||||
return node;
|
||||
}
|
||||
|
||||
return expression_tree_mutator(node, adjust_appendrel_attrs_mutator,
|
||||
(void *) context);
|
||||
}
|
||||
|
Reference in New Issue
Block a user