mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Remove planner's private fields from Query struct, and put them into
a new PlannerInfo struct, which is passed around instead of the bare Query in all the planning code. This commit is essentially just a code-beautification exercise, but it does open the door to making larger changes to the planner data structures without having to muck with the widely-known Query struct.
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.28 2005/06/04 19:19:41 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.29 2005/06/05 22:32:56 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -50,7 +50,7 @@ static void resolvenew_in_jointree(Node *jtnode, int varno,
|
||||
static reduce_outer_joins_state *reduce_outer_joins_pass1(Node *jtnode);
|
||||
static void reduce_outer_joins_pass2(Node *jtnode,
|
||||
reduce_outer_joins_state *state,
|
||||
Query *parse,
|
||||
PlannerInfo *root,
|
||||
Relids nonnullable_rels);
|
||||
static Relids find_nonnullable_rels(Node *node, bool top_level);
|
||||
static void fix_in_clause_relids(List *in_info_list, int varno,
|
||||
@@ -79,7 +79,7 @@ static Node *find_jointree_node_for_rel(Node *jtnode, int relid);
|
||||
* Returns the possibly-modified version of the given qual-tree node.
|
||||
*/
|
||||
Node *
|
||||
pull_up_IN_clauses(Query *parse, Node *node)
|
||||
pull_up_IN_clauses(PlannerInfo *root, Node *node)
|
||||
{
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
@@ -89,7 +89,7 @@ pull_up_IN_clauses(Query *parse, Node *node)
|
||||
Node *subst;
|
||||
|
||||
/* Is it a convertible IN clause? If not, return it as-is */
|
||||
subst = convert_IN_to_join(parse, sublink);
|
||||
subst = convert_IN_to_join(root, sublink);
|
||||
if (subst == NULL)
|
||||
return node;
|
||||
return subst;
|
||||
@@ -104,8 +104,7 @@ pull_up_IN_clauses(Query *parse, Node *node)
|
||||
Node *oldclause = (Node *) lfirst(l);
|
||||
|
||||
newclauses = lappend(newclauses,
|
||||
pull_up_IN_clauses(parse,
|
||||
oldclause));
|
||||
pull_up_IN_clauses(root, oldclause));
|
||||
}
|
||||
return (Node *) make_andclause(newclauses);
|
||||
}
|
||||
@@ -132,13 +131,14 @@ pull_up_IN_clauses(Query *parse, Node *node)
|
||||
* copy of the tree; we have to invoke it just on the quals, instead.
|
||||
*/
|
||||
Node *
|
||||
pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
pull_up_subqueries(PlannerInfo *root, Node *jtnode, bool below_outer_join)
|
||||
{
|
||||
if (jtnode == NULL)
|
||||
return NULL;
|
||||
if (IsA(jtnode, RangeTblRef))
|
||||
{
|
||||
int varno = ((RangeTblRef *) jtnode)->rtindex;
|
||||
Query *parse = root->parse;
|
||||
RangeTblEntry *rte = rt_fetch(varno, parse->rtable);
|
||||
Query *subquery = rte->subquery;
|
||||
|
||||
@@ -160,6 +160,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
is_simple_subquery(subquery) &&
|
||||
(!below_outer_join || has_nullable_targetlist(subquery)))
|
||||
{
|
||||
PlannerInfo *subroot;
|
||||
int rtoffset;
|
||||
List *subtlist;
|
||||
ListCell *rt;
|
||||
@@ -173,12 +174,23 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
*/
|
||||
subquery = copyObject(subquery);
|
||||
|
||||
/*
|
||||
* Create a PlannerInfo data structure for this subquery.
|
||||
*
|
||||
* NOTE: the next few steps should match the first processing
|
||||
* in subquery_planner(). Can we refactor to avoid code
|
||||
* duplication, or would that just make things uglier?
|
||||
*/
|
||||
subroot = makeNode(PlannerInfo);
|
||||
subroot->parse = subquery;
|
||||
|
||||
/*
|
||||
* Pull up any IN clauses within the subquery's WHERE, so that
|
||||
* we don't leave unoptimized INs behind.
|
||||
*/
|
||||
subroot->in_info_list = NIL;
|
||||
if (subquery->hasSubLinks)
|
||||
subquery->jointree->quals = pull_up_IN_clauses(subquery,
|
||||
subquery->jointree->quals = pull_up_IN_clauses(subroot,
|
||||
subquery->jointree->quals);
|
||||
|
||||
/*
|
||||
@@ -191,7 +203,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
* clean slate for outer-join semantics.
|
||||
*/
|
||||
subquery->jointree = (FromExpr *)
|
||||
pull_up_subqueries(subquery, (Node *) subquery->jointree,
|
||||
pull_up_subqueries(subroot, (Node *) subquery->jointree,
|
||||
false);
|
||||
|
||||
/*
|
||||
@@ -222,16 +234,19 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
|
||||
/*
|
||||
* Adjust level-0 varnos in subquery so that we can append its
|
||||
* rangetable to upper query's.
|
||||
* rangetable to upper query's. We have to fix the subquery's
|
||||
* in_info_list, as well.
|
||||
*/
|
||||
rtoffset = list_length(parse->rtable);
|
||||
OffsetVarNodes((Node *) subquery, rtoffset, 0);
|
||||
OffsetVarNodes((Node *) subroot->in_info_list, rtoffset, 0);
|
||||
|
||||
/*
|
||||
* Upper-level vars in subquery are now one level closer to
|
||||
* their parent than before.
|
||||
*/
|
||||
IncrementVarSublevelsUp((Node *) subquery, -1, 1);
|
||||
IncrementVarSublevelsUp((Node *) subroot->in_info_list, -1, 1);
|
||||
|
||||
/*
|
||||
* Replace all of the top query's references to the subquery's
|
||||
@@ -252,8 +267,8 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
ResolveNew(parse->havingQual,
|
||||
varno, 0, rte,
|
||||
subtlist, CMD_SELECT, 0);
|
||||
parse->in_info_list = (List *)
|
||||
ResolveNew((Node *) parse->in_info_list,
|
||||
root->in_info_list = (List *)
|
||||
ResolveNew((Node *) root->in_info_list,
|
||||
varno, 0, rte,
|
||||
subtlist, CMD_SELECT, 0);
|
||||
|
||||
@@ -299,19 +314,19 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
* ResolveNew, but it would clutter that routine's API
|
||||
* unreasonably.)
|
||||
*/
|
||||
if (parse->in_info_list)
|
||||
if (root->in_info_list)
|
||||
{
|
||||
Relids subrelids;
|
||||
|
||||
subrelids = get_relids_in_jointree((Node *) subquery->jointree);
|
||||
fix_in_clause_relids(parse->in_info_list, varno, subrelids);
|
||||
fix_in_clause_relids(root->in_info_list, varno, subrelids);
|
||||
}
|
||||
|
||||
/*
|
||||
* And now append any subquery InClauseInfos to our list.
|
||||
*/
|
||||
parse->in_info_list = list_concat(parse->in_info_list,
|
||||
subquery->in_info_list);
|
||||
root->in_info_list = list_concat(root->in_info_list,
|
||||
subroot->in_info_list);
|
||||
|
||||
/*
|
||||
* Miscellaneous housekeeping.
|
||||
@@ -332,7 +347,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
ListCell *l;
|
||||
|
||||
foreach(l, f->fromlist)
|
||||
lfirst(l) = pull_up_subqueries(parse, lfirst(l),
|
||||
lfirst(l) = pull_up_subqueries(root, lfirst(l),
|
||||
below_outer_join);
|
||||
}
|
||||
else if (IsA(jtnode, JoinExpr))
|
||||
@@ -343,27 +358,27 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
switch (j->jointype)
|
||||
{
|
||||
case JOIN_INNER:
|
||||
j->larg = pull_up_subqueries(parse, j->larg,
|
||||
j->larg = pull_up_subqueries(root, j->larg,
|
||||
below_outer_join);
|
||||
j->rarg = pull_up_subqueries(parse, j->rarg,
|
||||
j->rarg = pull_up_subqueries(root, j->rarg,
|
||||
below_outer_join);
|
||||
break;
|
||||
case JOIN_LEFT:
|
||||
j->larg = pull_up_subqueries(parse, j->larg,
|
||||
j->larg = pull_up_subqueries(root, j->larg,
|
||||
below_outer_join);
|
||||
j->rarg = pull_up_subqueries(parse, j->rarg,
|
||||
j->rarg = pull_up_subqueries(root, j->rarg,
|
||||
true);
|
||||
break;
|
||||
case JOIN_FULL:
|
||||
j->larg = pull_up_subqueries(parse, j->larg,
|
||||
j->larg = pull_up_subqueries(root, j->larg,
|
||||
true);
|
||||
j->rarg = pull_up_subqueries(parse, j->rarg,
|
||||
j->rarg = pull_up_subqueries(root, j->rarg,
|
||||
true);
|
||||
break;
|
||||
case JOIN_RIGHT:
|
||||
j->larg = pull_up_subqueries(parse, j->larg,
|
||||
j->larg = pull_up_subqueries(root, j->larg,
|
||||
true);
|
||||
j->rarg = pull_up_subqueries(parse, j->rarg,
|
||||
j->rarg = pull_up_subqueries(root, j->rarg,
|
||||
below_outer_join);
|
||||
break;
|
||||
case JOIN_UNION:
|
||||
@@ -555,7 +570,7 @@ resolvenew_in_jointree(Node *jtnode, int varno,
|
||||
* alias-var expansion).
|
||||
*/
|
||||
void
|
||||
reduce_outer_joins(Query *parse)
|
||||
reduce_outer_joins(PlannerInfo *root)
|
||||
{
|
||||
reduce_outer_joins_state *state;
|
||||
|
||||
@@ -569,13 +584,14 @@ reduce_outer_joins(Query *parse)
|
||||
* clause. The second pass examines qual clauses and changes join
|
||||
* types as it descends the tree.
|
||||
*/
|
||||
state = reduce_outer_joins_pass1((Node *) parse->jointree);
|
||||
state = reduce_outer_joins_pass1((Node *) root->parse->jointree);
|
||||
|
||||
/* planner.c shouldn't have called me if no outer joins */
|
||||
if (state == NULL || !state->contains_outer)
|
||||
elog(ERROR, "so where are the outer joins?");
|
||||
|
||||
reduce_outer_joins_pass2((Node *) parse->jointree, state, parse, NULL);
|
||||
reduce_outer_joins_pass2((Node *) root->parse->jointree,
|
||||
state, root, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -650,13 +666,13 @@ reduce_outer_joins_pass1(Node *jtnode)
|
||||
*
|
||||
* jtnode: current jointree node
|
||||
* state: state data collected by phase 1 for this node
|
||||
* parse: toplevel Query
|
||||
* root: toplevel planner state
|
||||
* nonnullable_rels: set of base relids forced non-null by upper quals
|
||||
*/
|
||||
static void
|
||||
reduce_outer_joins_pass2(Node *jtnode,
|
||||
reduce_outer_joins_state *state,
|
||||
Query *parse,
|
||||
PlannerInfo *root,
|
||||
Relids nonnullable_rels)
|
||||
{
|
||||
/*
|
||||
@@ -685,7 +701,7 @@ reduce_outer_joins_pass2(Node *jtnode,
|
||||
reduce_outer_joins_state *sub_state = lfirst(s);
|
||||
|
||||
if (sub_state->contains_outer)
|
||||
reduce_outer_joins_pass2(lfirst(l), sub_state, parse,
|
||||
reduce_outer_joins_pass2(lfirst(l), sub_state, root,
|
||||
pass_nonnullable);
|
||||
}
|
||||
bms_free(pass_nonnullable);
|
||||
@@ -729,7 +745,7 @@ reduce_outer_joins_pass2(Node *jtnode,
|
||||
if (jointype != j->jointype)
|
||||
{
|
||||
/* apply the change to both jointree node and RTE */
|
||||
RangeTblEntry *rte = rt_fetch(rtindex, parse->rtable);
|
||||
RangeTblEntry *rte = rt_fetch(rtindex, root->parse->rtable);
|
||||
|
||||
Assert(rte->rtekind == RTE_JOIN);
|
||||
Assert(rte->jointype == j->jointype);
|
||||
@@ -767,7 +783,7 @@ reduce_outer_joins_pass2(Node *jtnode,
|
||||
pass_nonnullable = local_nonnullable;
|
||||
else
|
||||
pass_nonnullable = nonnullable_rels;
|
||||
reduce_outer_joins_pass2(j->larg, left_state, parse,
|
||||
reduce_outer_joins_pass2(j->larg, left_state, root,
|
||||
pass_nonnullable);
|
||||
}
|
||||
if (right_state->contains_outer)
|
||||
@@ -776,7 +792,7 @@ reduce_outer_joins_pass2(Node *jtnode,
|
||||
pass_nonnullable = local_nonnullable;
|
||||
else
|
||||
pass_nonnullable = nonnullable_rels;
|
||||
reduce_outer_joins_pass2(j->rarg, right_state, parse,
|
||||
reduce_outer_joins_pass2(j->rarg, right_state, root,
|
||||
pass_nonnullable);
|
||||
}
|
||||
bms_free(local_nonnullable);
|
||||
@@ -909,7 +925,7 @@ find_nonnullable_rels(Node *node, bool top_level)
|
||||
* work reliably --- see comments for pull_up_subqueries().
|
||||
*/
|
||||
Node *
|
||||
simplify_jointree(Query *parse, Node *jtnode)
|
||||
simplify_jointree(PlannerInfo *root, Node *jtnode)
|
||||
{
|
||||
if (jtnode == NULL)
|
||||
return NULL;
|
||||
@@ -931,7 +947,7 @@ simplify_jointree(Query *parse, Node *jtnode)
|
||||
|
||||
children_remaining--;
|
||||
/* Recursively simplify this child... */
|
||||
child = simplify_jointree(parse, child);
|
||||
child = simplify_jointree(root, child);
|
||||
/* Now, is it a FromExpr? */
|
||||
if (child && IsA(child, FromExpr))
|
||||
{
|
||||
@@ -972,8 +988,8 @@ simplify_jointree(Query *parse, Node *jtnode)
|
||||
JoinExpr *j = (JoinExpr *) jtnode;
|
||||
|
||||
/* Recursively simplify the children... */
|
||||
j->larg = simplify_jointree(parse, j->larg);
|
||||
j->rarg = simplify_jointree(parse, j->rarg);
|
||||
j->larg = simplify_jointree(root, j->larg);
|
||||
j->rarg = simplify_jointree(root, j->rarg);
|
||||
|
||||
/*
|
||||
* If it is an outer join, we must not flatten it. An inner join
|
||||
@@ -1115,11 +1131,12 @@ get_relids_in_jointree(Node *jtnode)
|
||||
* since that may eliminate join nodes from the jointree.
|
||||
*/
|
||||
Relids
|
||||
get_relids_for_join(Query *parse, int joinrelid)
|
||||
get_relids_for_join(PlannerInfo *root, int joinrelid)
|
||||
{
|
||||
Node *jtnode;
|
||||
|
||||
jtnode = find_jointree_node_for_rel((Node *) parse->jointree, joinrelid);
|
||||
jtnode = find_jointree_node_for_rel((Node *) root->parse->jointree,
|
||||
joinrelid);
|
||||
if (!jtnode)
|
||||
elog(ERROR, "could not find join node %d", joinrelid);
|
||||
return get_relids_in_jointree(jtnode);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.76 2005/05/23 03:01:13 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.77 2005/06/05 22:32:56 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -43,8 +43,9 @@ static List *expand_targetlist(List *tlist, int command_type,
|
||||
* Returns the new targetlist.
|
||||
*/
|
||||
List *
|
||||
preprocess_targetlist(Query *parse, List *tlist)
|
||||
preprocess_targetlist(PlannerInfo *root, List *tlist)
|
||||
{
|
||||
Query *parse = root->parse;
|
||||
int result_relation = parse->resultRelation;
|
||||
List *range_table = parse->rtable;
|
||||
CmdType command_type = parse->commandType;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.121 2005/05/22 22:30:19 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.122 2005/06/05 22:32:56 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -49,15 +49,15 @@ typedef struct
|
||||
char *new_rel_name;
|
||||
} adjust_inherited_attrs_context;
|
||||
|
||||
static Plan *recurse_set_operations(Node *setOp, Query *parse,
|
||||
static Plan *recurse_set_operations(Node *setOp, PlannerInfo *root,
|
||||
List *colTypes, bool junkOK,
|
||||
int flag, List *refnames_tlist,
|
||||
List **sortClauses);
|
||||
static Plan *generate_union_plan(SetOperationStmt *op, Query *parse,
|
||||
static Plan *generate_union_plan(SetOperationStmt *op, PlannerInfo *root,
|
||||
List *refnames_tlist, List **sortClauses);
|
||||
static Plan *generate_nonunion_plan(SetOperationStmt *op, Query *parse,
|
||||
static Plan *generate_nonunion_plan(SetOperationStmt *op, PlannerInfo *root,
|
||||
List *refnames_tlist, List **sortClauses);
|
||||
static List *recurse_union_children(Node *setOp, Query *parse,
|
||||
static List *recurse_union_children(Node *setOp, PlannerInfo *root,
|
||||
SetOperationStmt *top_union,
|
||||
List *refnames_tlist);
|
||||
static List *generate_setop_tlist(List *colTypes, int flag,
|
||||
@@ -82,15 +82,16 @@ static List *adjust_inherited_tlist(List *tlist,
|
||||
* Plans the queries for a tree of set operations (UNION/INTERSECT/EXCEPT)
|
||||
*
|
||||
* This routine only deals with the setOperations tree of the given query.
|
||||
* Any top-level ORDER BY requested in parse->sortClause will be added
|
||||
* Any top-level ORDER BY requested in root->parse->sortClause will be added
|
||||
* when we return to grouping_planner.
|
||||
*
|
||||
* *sortClauses is an output argument: it is set to a list of SortClauses
|
||||
* representing the result ordering of the topmost set operation.
|
||||
*/
|
||||
Plan *
|
||||
plan_set_operations(Query *parse, List **sortClauses)
|
||||
plan_set_operations(PlannerInfo *root, List **sortClauses)
|
||||
{
|
||||
Query *parse = root->parse;
|
||||
SetOperationStmt *topop = (SetOperationStmt *) parse->setOperations;
|
||||
Node *node;
|
||||
Query *leftmostQuery;
|
||||
@@ -123,7 +124,7 @@ plan_set_operations(Query *parse, List **sortClauses)
|
||||
* output from the top-level node, plus possibly resjunk working
|
||||
* columns (we can rely on upper-level nodes to deal with that).
|
||||
*/
|
||||
return recurse_set_operations((Node *) topop, parse,
|
||||
return recurse_set_operations((Node *) topop, root,
|
||||
topop->colTypes, true, -1,
|
||||
leftmostQuery->targetList,
|
||||
sortClauses);
|
||||
@@ -140,7 +141,7 @@ plan_set_operations(Query *parse, List **sortClauses)
|
||||
* *sortClauses: receives list of SortClauses for result plan, if any
|
||||
*/
|
||||
static Plan *
|
||||
recurse_set_operations(Node *setOp, Query *parse,
|
||||
recurse_set_operations(Node *setOp, PlannerInfo *root,
|
||||
List *colTypes, bool junkOK,
|
||||
int flag, List *refnames_tlist,
|
||||
List **sortClauses)
|
||||
@@ -148,7 +149,7 @@ recurse_set_operations(Node *setOp, Query *parse,
|
||||
if (IsA(setOp, RangeTblRef))
|
||||
{
|
||||
RangeTblRef *rtr = (RangeTblRef *) setOp;
|
||||
RangeTblEntry *rte = rt_fetch(rtr->rtindex, parse->rtable);
|
||||
RangeTblEntry *rte = rt_fetch(rtr->rtindex, root->parse->rtable);
|
||||
Query *subquery = rte->subquery;
|
||||
Plan *subplan,
|
||||
*plan;
|
||||
@@ -158,7 +159,7 @@ recurse_set_operations(Node *setOp, Query *parse,
|
||||
/*
|
||||
* Generate plan for primitive subquery
|
||||
*/
|
||||
subplan = subquery_planner(subquery, 0.0 /* default case */ );
|
||||
subplan = subquery_planner(subquery, 0.0 /* default case */, NULL);
|
||||
|
||||
/*
|
||||
* Add a SubqueryScan with the caller-requested targetlist
|
||||
@@ -188,10 +189,10 @@ recurse_set_operations(Node *setOp, Query *parse,
|
||||
|
||||
/* UNIONs are much different from INTERSECT/EXCEPT */
|
||||
if (op->op == SETOP_UNION)
|
||||
plan = generate_union_plan(op, parse, refnames_tlist,
|
||||
plan = generate_union_plan(op, root, refnames_tlist,
|
||||
sortClauses);
|
||||
else
|
||||
plan = generate_nonunion_plan(op, parse, refnames_tlist,
|
||||
plan = generate_nonunion_plan(op, root, refnames_tlist,
|
||||
sortClauses);
|
||||
|
||||
/*
|
||||
@@ -233,7 +234,7 @@ recurse_set_operations(Node *setOp, Query *parse,
|
||||
* Generate plan for a UNION or UNION ALL node
|
||||
*/
|
||||
static Plan *
|
||||
generate_union_plan(SetOperationStmt *op, Query *parse,
|
||||
generate_union_plan(SetOperationStmt *op, PlannerInfo *root,
|
||||
List *refnames_tlist,
|
||||
List **sortClauses)
|
||||
{
|
||||
@@ -247,9 +248,9 @@ generate_union_plan(SetOperationStmt *op, Query *parse,
|
||||
* generate only one Append and Sort for the lot. Recurse to find
|
||||
* such nodes and compute their children's plans.
|
||||
*/
|
||||
planlist = list_concat(recurse_union_children(op->larg, parse,
|
||||
planlist = list_concat(recurse_union_children(op->larg, root,
|
||||
op, refnames_tlist),
|
||||
recurse_union_children(op->rarg, parse,
|
||||
recurse_union_children(op->rarg, root,
|
||||
op, refnames_tlist));
|
||||
|
||||
/*
|
||||
@@ -278,7 +279,7 @@ generate_union_plan(SetOperationStmt *op, Query *parse,
|
||||
sortList = addAllTargetsToSortList(NULL, NIL, tlist, false);
|
||||
if (sortList)
|
||||
{
|
||||
plan = (Plan *) make_sort_from_sortclauses(parse, sortList, plan);
|
||||
plan = (Plan *) make_sort_from_sortclauses(root, sortList, plan);
|
||||
plan = (Plan *) make_unique(plan, sortList);
|
||||
}
|
||||
*sortClauses = sortList;
|
||||
@@ -293,7 +294,7 @@ generate_union_plan(SetOperationStmt *op, Query *parse,
|
||||
* Generate plan for an INTERSECT, INTERSECT ALL, EXCEPT, or EXCEPT ALL node
|
||||
*/
|
||||
static Plan *
|
||||
generate_nonunion_plan(SetOperationStmt *op, Query *parse,
|
||||
generate_nonunion_plan(SetOperationStmt *op, PlannerInfo *root,
|
||||
List *refnames_tlist,
|
||||
List **sortClauses)
|
||||
{
|
||||
@@ -307,11 +308,11 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
|
||||
SetOpCmd cmd;
|
||||
|
||||
/* Recurse on children, ensuring their outputs are marked */
|
||||
lplan = recurse_set_operations(op->larg, parse,
|
||||
lplan = recurse_set_operations(op->larg, root,
|
||||
op->colTypes, false, 0,
|
||||
refnames_tlist,
|
||||
&child_sortclauses);
|
||||
rplan = recurse_set_operations(op->rarg, parse,
|
||||
rplan = recurse_set_operations(op->rarg, root,
|
||||
op->colTypes, false, 1,
|
||||
refnames_tlist,
|
||||
&child_sortclauses);
|
||||
@@ -346,7 +347,7 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
|
||||
return plan;
|
||||
}
|
||||
|
||||
plan = (Plan *) make_sort_from_sortclauses(parse, sortList, plan);
|
||||
plan = (Plan *) make_sort_from_sortclauses(root, sortList, plan);
|
||||
switch (op->op)
|
||||
{
|
||||
case SETOP_INTERSECT:
|
||||
@@ -375,7 +376,7 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
|
||||
* output rows will be lost anyway.
|
||||
*/
|
||||
static List *
|
||||
recurse_union_children(Node *setOp, Query *parse,
|
||||
recurse_union_children(Node *setOp, PlannerInfo *root,
|
||||
SetOperationStmt *top_union,
|
||||
List *refnames_tlist)
|
||||
{
|
||||
@@ -390,10 +391,10 @@ recurse_union_children(Node *setOp, Query *parse,
|
||||
equal(op->colTypes, top_union->colTypes))
|
||||
{
|
||||
/* Same UNION, so fold children into parent's subplan list */
|
||||
return list_concat(recurse_union_children(op->larg, parse,
|
||||
return list_concat(recurse_union_children(op->larg, root,
|
||||
top_union,
|
||||
refnames_tlist),
|
||||
recurse_union_children(op->rarg, parse,
|
||||
recurse_union_children(op->rarg, root,
|
||||
top_union,
|
||||
refnames_tlist));
|
||||
}
|
||||
@@ -409,7 +410,7 @@ recurse_union_children(Node *setOp, Query *parse,
|
||||
* we have an EXCEPT or INTERSECT as child, else there won't be
|
||||
* resjunk anyway.
|
||||
*/
|
||||
return list_make1(recurse_set_operations(setOp, parse,
|
||||
return list_make1(recurse_set_operations(setOp, root,
|
||||
top_union->colTypes, false,
|
||||
-1, refnames_tlist,
|
||||
&child_sortclauses));
|
||||
@@ -724,8 +725,9 @@ find_all_inheritors(Oid parentrel)
|
||||
* trying to avoid.
|
||||
*/
|
||||
List *
|
||||
expand_inherited_rtentry(Query *parse, Index rti)
|
||||
expand_inherited_rtentry(PlannerInfo *root, Index rti)
|
||||
{
|
||||
Query *parse = root->parse;
|
||||
RangeTblEntry *rte = rt_fetch(rti, parse->rtable);
|
||||
Oid parentOID;
|
||||
List *inhOIDs;
|
||||
|
||||
Reference in New Issue
Block a user