diff options
Diffstat (limited to 'src/backend/optimizer/util/paramassign.c')
-rw-r--r-- | src/backend/optimizer/util/paramassign.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/backend/optimizer/util/paramassign.c b/src/backend/optimizer/util/paramassign.c index a58da7c57ea..f461fedf194 100644 --- a/src/backend/optimizer/util/paramassign.c +++ b/src/backend/optimizer/util/paramassign.c @@ -308,6 +308,57 @@ replace_outer_grouping(PlannerInfo *root, GroupingFunc *grp) } /* + * Generate a Param node to replace the given MergeSupportFunc expression + * which is expected to be in the RETURNING list of an upper-level MERGE + * query. Record the need for the MergeSupportFunc in the proper upper-level + * root->plan_params. + */ +Param * +replace_outer_merge_support(PlannerInfo *root, MergeSupportFunc *msf) +{ + Param *retval; + PlannerParamItem *pitem; + Oid ptype = exprType((Node *) msf); + + Assert(root->parse->commandType != CMD_MERGE); + + /* + * The parser should have ensured that the MergeSupportFunc is in the + * RETURNING list of an upper-level MERGE query, so find that query. + */ + do + { + root = root->parent_root; + if (root == NULL) + elog(ERROR, "MergeSupportFunc found outside MERGE"); + } while (root->parse->commandType != CMD_MERGE); + + /* + * It does not seem worthwhile to try to de-duplicate references to outer + * MergeSupportFunc expressions. Just make a new slot every time. + */ + msf = copyObject(msf); + + pitem = makeNode(PlannerParamItem); + pitem->item = (Node *) msf; + pitem->paramId = list_length(root->glob->paramExecTypes); + root->glob->paramExecTypes = lappend_oid(root->glob->paramExecTypes, + ptype); + + root->plan_params = lappend(root->plan_params, pitem); + + retval = makeNode(Param); + retval->paramkind = PARAM_EXEC; + retval->paramid = pitem->paramId; + retval->paramtype = ptype; + retval->paramtypmod = -1; + retval->paramcollid = InvalidOid; + retval->location = msf->location; + + return retval; +} + +/* * Generate a Param node to replace the given Var, * which is expected to come from some upper NestLoop plan node. * Record the need for the Var in root->curOuterParams. |