const char *operation;
const char *foperation;
bool labeltargets;
+ bool nopruning;
int j;
List *idxNames = NIL;
ListCell *lst;
if (labeltargets)
ExplainOpenGroup("Target Tables", "Target Tables", false, es);
+ /*
+ * node->fdwPrivLists is parallel to node->resultRelations, in the
+ * original pre-pruning order. If no result relations were pruned, the
+ * entries in mtstate->resultRelInfo[] are in that same order and can be
+ * matched to fdwPrivLists positionally; otherwise we have to look each
+ * one up by range table index below. This test is loop-invariant, so
+ * compute it once here.
+ */
+ nopruning = (list_length(node->resultRelations) == mtstate->mt_nrels);
+
for (j = 0; j < mtstate->mt_nrels; j++)
{
ResultRelInfo *resultRelInfo = mtstate->resultRelInfo + j;
fdwroutine != NULL &&
fdwroutine->ExplainForeignModify != NULL)
{
- List *fdw_private = (List *) list_nth(mtstate->mt_fdwPrivLists, j);
+ List *fdw_private;
+
+ /*
+ * Find this relation's fdw_private: index fdwPrivLists directly
+ * when nothing was pruned, else match by range table index.
+ */
+ if (nopruning)
+ fdw_private = (List *) list_nth(node->fdwPrivLists, j);
+ else
+ {
+ Index rti = resultRelInfo->ri_RangeTableIndex;
+ ListCell *lc1;
+ ListCell *lc2;
+
+ fdw_private = NIL;
+ forboth(lc1, node->resultRelations, lc2, node->fdwPrivLists)
+ {
+ if (lfirst_int(lc1) == (int) rti)
+ {
+ fdw_private = (List *) lfirst(lc2);
+ break;
+ }
+ }
+ }
fdwroutine->ExplainForeignModify(mtstate,
resultRelInfo,
mtstate->mt_updateColnosLists = updateColnosLists;
mtstate->mt_mergeActionLists = mergeActionLists;
mtstate->mt_mergeJoinConditions = mergeJoinConditions;
- mtstate->mt_fdwPrivLists = fdwPrivLists;
/*----------
* Resolve the target relation. This is the same as:
double mt_merge_deleted;
/*
- * Lists of valid updateColnosLists, mergeActionLists,
- * mergeJoinConditions, and fdwPrivLists. These contain only entries for
- * unpruned relations, filtered from the corresponding lists in
- * ModifyTable.
+ * Lists of valid updateColnosLists, mergeActionLists, and
+ * mergeJoinConditions. These contain only entries for unpruned
+ * relations, filtered from the corresponding lists in ModifyTable.
*/
List *mt_updateColnosLists;
List *mt_mergeActionLists;
List *mt_mergeJoinConditions;
- List *mt_fdwPrivLists;
} ModifyTableState;
/* ----------------