aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/subselect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/plan/subselect.c')
-rw-r--r--src/backend/optimizer/plan/subselect.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index eaaf8c1b49a..8230cbea3c3 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -354,17 +354,19 @@ build_subplan(PlannerInfo *root, Plan *plan, Path *path,
Node *arg = pitem->item;
/*
- * The Var, PlaceHolderVar, Aggref or GroupingFunc has already been
- * adjusted to have the correct varlevelsup, phlevelsup, or
- * agglevelsup.
+ * The Var, PlaceHolderVar, Aggref, GroupingFunc, or ReturningExpr has
+ * already been adjusted to have the correct varlevelsup, phlevelsup,
+ * agglevelsup, or retlevelsup.
*
- * If it's a PlaceHolderVar, Aggref or GroupingFunc, its arguments
- * might contain SubLinks, which have not yet been processed (see the
- * comments for SS_replace_correlation_vars). Do that now.
+ * If it's a PlaceHolderVar, Aggref, GroupingFunc, or ReturningExpr,
+ * its arguments might contain SubLinks, which have not yet been
+ * processed (see the comments for SS_replace_correlation_vars). Do
+ * that now.
*/
if (IsA(arg, PlaceHolderVar) ||
IsA(arg, Aggref) ||
- IsA(arg, GroupingFunc))
+ IsA(arg, GroupingFunc) ||
+ IsA(arg, ReturningExpr))
arg = SS_process_sublinks(root, arg, false);
splan->parParam = lappend_int(splan->parParam, pitem->paramId);
@@ -1863,8 +1865,8 @@ convert_EXISTS_to_ANY(PlannerInfo *root, Query *subselect,
/*
* Replace correlation vars (uplevel vars) with Params.
*
- * Uplevel PlaceHolderVars, aggregates, GROUPING() expressions, and
- * MergeSupportFuncs are replaced, too.
+ * Uplevel PlaceHolderVars, aggregates, GROUPING() expressions,
+ * MergeSupportFuncs, and ReturningExprs are replaced, too.
*
* Note: it is critical that this runs immediately after SS_process_sublinks.
* Since we do not recurse into the arguments of uplevel PHVs and aggregates,
@@ -1924,6 +1926,12 @@ replace_correlation_vars_mutator(Node *node, PlannerInfo *root)
return (Node *) replace_outer_merge_support(root,
(MergeSupportFunc *) node);
}
+ if (IsA(node, ReturningExpr))
+ {
+ if (((ReturningExpr *) node)->retlevelsup > 0)
+ return (Node *) replace_outer_returning(root,
+ (ReturningExpr *) node);
+ }
return expression_tree_mutator(node, replace_correlation_vars_mutator, root);
}
@@ -1977,11 +1985,11 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
}
/*
- * Don't recurse into the arguments of an outer PHV, Aggref or
- * GroupingFunc here. Any SubLinks in the arguments have to be dealt with
- * at the outer query level; they'll be handled when build_subplan
- * collects the PHV, Aggref or GroupingFunc into the arguments to be
- * passed down to the current subplan.
+ * Don't recurse into the arguments of an outer PHV, Aggref, GroupingFunc,
+ * or ReturningExpr here. Any SubLinks in the arguments have to be dealt
+ * with at the outer query level; they'll be handled when build_subplan
+ * collects the PHV, Aggref, GroupingFunc, or ReturningExpr into the
+ * arguments to be passed down to the current subplan.
*/
if (IsA(node, PlaceHolderVar))
{
@@ -1998,6 +2006,11 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
if (((GroupingFunc *) node)->agglevelsup > 0)
return node;
}
+ else if (IsA(node, ReturningExpr))
+ {
+ if (((ReturningExpr *) node)->retlevelsup > 0)
+ return node;
+ }
/*
* We should never see a SubPlan expression in the input (since this is
@@ -2110,7 +2123,9 @@ SS_identify_outer_params(PlannerInfo *root)
outer_params = NULL;
for (proot = root->parent_root; proot != NULL; proot = proot->parent_root)
{
- /* Include ordinary Var/PHV/Aggref/GroupingFunc params */
+ /*
+ * Include ordinary Var/PHV/Aggref/GroupingFunc/ReturningExpr params.
+ */
foreach(l, proot->plan_params)
{
PlannerParamItem *pitem = (PlannerParamItem *) lfirst(l);