*** a/src/backend/optimizer/plan/createplan.c --- b/src/backend/optimizer/plan/createplan.c *************** *** 4715,4724 **** make_result(PlannerInfo *root, */ ModifyTable * make_modifytable(PlannerInfo *root, - CmdType operation, bool canSetTag, List *resultRelations, ! List *subplans, List *returningLists, ! List *rowMarks, int epqParam) { ModifyTable *node = makeNode(ModifyTable); Plan *plan = &node->plan; --- 4715,4722 ---- */ ModifyTable * make_modifytable(PlannerInfo *root, List *resultRelations, ! List *subplans, List *returningLists) { ModifyTable *node = makeNode(ModifyTable); Plan *plan = &node->plan; *************** *** 4726,4731 **** make_modifytable(PlannerInfo *root, --- 4724,4743 ---- ListCell *subnode; ListCell *resultRel; List *fdw_priv_list = NIL; + CmdType operation = root->parse->commandType; + bool canSetTag = root->parse->canSetTag; + List *rowMarks; + int epqParam = SS_assign_special_param(root); + + /* + * If there was a FOR [KEY] UPDATE/SHARE clause, the LockRows node will + * have dealt with fetching non-locked marked rows, else we need + * to have ModifyTable do that. + */ + if (root->parse->rowMarks) + rowMarks = NIL; + else + rowMarks = root->rowMarks; Assert(list_length(resultRelations) == list_length(subplans)); Assert(returningLists == NIL || *** a/src/backend/optimizer/plan/planner.c --- b/src/backend/optimizer/plan/planner.c *************** *** 551,557 **** subquery_planner(PlannerGlobal *glob, Query *parse, if (parse->commandType != CMD_SELECT) { List *returningLists; - List *rowMarks; /* * Set up the RETURNING list-of-lists, if needed. --- 551,556 ---- *************** *** 561,584 **** subquery_planner(PlannerGlobal *glob, Query *parse, else returningLists = NIL; ! /* ! * If there was a FOR [KEY] UPDATE/SHARE clause, the LockRows node will ! * have dealt with fetching non-locked marked rows, else we need ! * to have ModifyTable do that. ! */ ! if (parse->rowMarks) ! rowMarks = NIL; ! else ! rowMarks = root->rowMarks; ! plan = (Plan *) make_modifytable(root, - parse->commandType, - parse->canSetTag, list_make1_int(parse->resultRelation), list_make1(plan), ! returningLists, ! rowMarks, ! SS_assign_special_param(root)); } } --- 560,571 ---- else returningLists = NIL; ! Assert(parse->commandType == root->parse->commandType); ! Assert(parse->canSetTag == root->parse->canSetTag); plan = (Plan *) make_modifytable(root, list_make1_int(parse->resultRelation), list_make1(plan), ! returningLists); } } *************** *** 762,768 **** inheritance_planner(PlannerInfo *root) List *subplans = NIL; List *resultRelations = NIL; List *returningLists = NIL; - List *rowMarks; ListCell *lc; /* --- 749,754 ---- *************** *** 954,978 **** inheritance_planner(PlannerInfo *root) root->simple_rel_array_size = save_rel_array_size; root->simple_rel_array = save_rel_array; - /* - * If there was a FOR [KEY] UPDATE/SHARE clause, the LockRows node will have - * dealt with fetching non-locked marked rows, else we need to have - * ModifyTable do that. - */ - if (parse->rowMarks) - rowMarks = NIL; - else - rowMarks = root->rowMarks; - /* And last, tack on a ModifyTable node to do the UPDATE/DELETE work */ return (Plan *) make_modifytable(root, - parse->commandType, - parse->canSetTag, resultRelations, subplans, ! returningLists, ! rowMarks, ! SS_assign_special_param(root)); } /*-------------------- --- 940,952 ---- root->simple_rel_array_size = save_rel_array_size; root->simple_rel_array = save_rel_array; /* And last, tack on a ModifyTable node to do the UPDATE/DELETE work */ + Assert(parse->commandType == root->parse->commandType); + Assert(parse->canSetTag == root->parse->canSetTag); return (Plan *) make_modifytable(root, resultRelations, subplans, ! returningLists); } /*-------------------- *** a/src/include/optimizer/planmain.h --- b/src/include/optimizer/planmain.h *************** *** 80,88 **** extern SetOp *make_setop(SetOpCmd cmd, SetOpStrategy strategy, Plan *lefttree, extern Result *make_result(PlannerInfo *root, List *tlist, Node *resconstantqual, Plan *subplan); extern ModifyTable *make_modifytable(PlannerInfo *root, ! CmdType operation, bool canSetTag, ! List *resultRelations, List *subplans, List *returningLists, ! List *rowMarks, int epqParam); extern bool is_projection_capable_plan(Plan *plan); /* --- 80,86 ---- extern Result *make_result(PlannerInfo *root, List *tlist, Node *resconstantqual, Plan *subplan); extern ModifyTable *make_modifytable(PlannerInfo *root, ! List *resultRelations, List *subplans, List *returningLists); extern bool is_projection_capable_plan(Plan *plan); /*