diff options
author | Dean Rasheed <dean.a.rasheed@gmail.com> | 2024-03-30 10:00:26 +0000 |
---|---|---|
committer | Dean Rasheed <dean.a.rasheed@gmail.com> | 2024-03-30 10:00:26 +0000 |
commit | 0294df2f1f842dfb0eed79007b21016f486a3c6c (patch) | |
tree | d01da8c03b91a25a438f05dd7dccdb95d13f8f92 /src/backend/executor/execPartition.c | |
parent | 46e5441fa536b89c1123f270fdfeeb72c320b901 (diff) | |
download | postgresql-0294df2f1f842dfb0eed79007b21016f486a3c6c.tar.gz postgresql-0294df2f1f842dfb0eed79007b21016f486a3c6c.zip |
Add support for MERGE ... WHEN NOT MATCHED BY SOURCE.
This allows MERGE commands to include WHEN NOT MATCHED BY SOURCE
actions, which operate on rows that exist in the target relation, but
not in the data source. These actions can execute UPDATE, DELETE, or
DO NOTHING sub-commands.
This is in contrast to already-supported WHEN NOT MATCHED actions,
which operate on rows that exist in the data source, but not in the
target relation. To make this distinction clearer, such actions may
now be written as WHEN NOT MATCHED BY TARGET.
Writing WHEN NOT MATCHED without specifying BY SOURCE or BY TARGET is
equivalent to writing WHEN NOT MATCHED BY TARGET.
Dean Rasheed, reviewed by Alvaro Herrera, Ted Yu and Vik Fearing.
Discussion: https://postgr.es/m/CAEZATCWqnKGc57Y_JanUBHQXNKcXd7r=0R4NEZUVwP+syRkWbA@mail.gmail.com
Diffstat (limited to 'src/backend/executor/execPartition.c')
-rw-r--r-- | src/backend/executor/execPartition.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index 64fcb012dbe..bb14dcbe6fa 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -880,6 +880,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate, List *firstMergeActionList = linitial(node->mergeActionLists); ListCell *lc; ExprContext *econtext = mtstate->ps.ps_ExprContext; + Node *joinCondition; if (part_attmap == NULL) part_attmap = @@ -890,23 +891,31 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate, if (unlikely(!leaf_part_rri->ri_projectNewInfoValid)) ExecInitMergeTupleSlots(mtstate, leaf_part_rri); + /* Initialize state for join condition checking. */ + joinCondition = + map_variable_attnos(linitial(node->mergeJoinConditions), + firstVarno, 0, + part_attmap, + RelationGetForm(partrel)->reltype, + &found_whole_row); + /* We ignore the value of found_whole_row. */ + leaf_part_rri->ri_MergeJoinCondition = + ExecInitQual((List *) joinCondition, &mtstate->ps); + foreach(lc, firstMergeActionList) { /* Make a copy for this relation to be safe. */ MergeAction *action = copyObject(lfirst(lc)); MergeActionState *action_state; - List **list; /* Generate the action's state for this relation */ action_state = makeNode(MergeActionState); action_state->mas_action = action; /* And put the action in the appropriate list */ - if (action->matched) - list = &leaf_part_rri->ri_matchedMergeAction; - else - list = &leaf_part_rri->ri_notMatchedMergeAction; - *list = lappend(*list, action_state); + leaf_part_rri->ri_MergeActions[action->matchKind] = + lappend(leaf_part_rri->ri_MergeActions[action->matchKind], + action_state); switch (action->commandType) { |