diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c new file mode 100644 index 4c5647a..28ace59 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -3467,7 +3467,27 @@ lmerge_matched: /* Switch lists, if necessary */ if (!*matched) + { actionStates = mergeActions[MERGE_WHEN_NOT_MATCHED_BY_SOURCE]; + + /* + * If we have both NOT MATCHED BY SOURCE + * and NOT MATCHED BY TARGET actions (a + * full join between the source and target + * relations), the single previously + * matched tuple from the outer plan node + * is treated as two not matched tuples, + * in the same way as if they had not + * matched to start with. Therefore, we + * must adjust the outer plan node's tuple + * count, if we're instrumenting the + * query. + */ + if (outerPlanState(mtstate)->instrument && + mergeActions[MERGE_WHEN_NOT_MATCHED_BY_SOURCE] && + mergeActions[MERGE_WHEN_NOT_MATCHED_BY_TARGET]) + InstrUpdateTupleCount(outerPlanState(mtstate)->instrument, 1.0); + } } /*