diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2018-04-02 21:12:47 +0100 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2018-04-02 21:12:47 +0100 |
commit | 354f13855e6381d288dfaa52bcd4f2cb0fd4a5eb (patch) | |
tree | 92710660450acee59be62dea485cc26ab147f332 /src/backend/optimizer/prep/preptlist.c | |
parent | e6597dc3533946b98acba7871bd4ca1f7a3d4c1d (diff) | |
download | postgresql-354f13855e6381d288dfaa52bcd4f2cb0fd4a5eb.tar.gz postgresql-354f13855e6381d288dfaa52bcd4f2cb0fd4a5eb.zip |
Modified files for MERGE
Diffstat (limited to 'src/backend/optimizer/prep/preptlist.c')
-rw-r--r-- | src/backend/optimizer/prep/preptlist.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c index 8603feef2b8..8a87cfd14ae 100644 --- a/src/backend/optimizer/prep/preptlist.c +++ b/src/backend/optimizer/prep/preptlist.c @@ -118,6 +118,46 @@ preprocess_targetlist(PlannerInfo *root) tlist = expand_targetlist(tlist, command_type, result_relation, target_relation); + if (command_type == CMD_MERGE) + { + ListCell *l; + + /* + * For MERGE, add any junk column(s) needed to allow the executor to + * identify the rows to be updated or deleted, with different + * handling for partitioned tables. + */ + rewriteTargetListMerge(parse, target_relation); + + /* + * For MERGE command, handle targetlist of each MergeAction separately. + * Give the same treatment to MergeAction->targetList as we would have + * given to a regular INSERT/UPDATE/DELETE. + */ + foreach(l, parse->mergeActionList) + { + MergeAction *action = (MergeAction *) lfirst(l); + + switch (action->commandType) + { + case CMD_INSERT: + case CMD_UPDATE: + action->targetList = expand_targetlist(action->targetList, + action->commandType, + result_relation, + target_relation); + break; + case CMD_DELETE: + break; + case CMD_NOTHING: + break; + default: + elog(ERROR, "unknown action in MERGE WHEN clause"); + + } + } + } + /* * Add necessary junk columns for rowmarked rels. These values are needed * for locking of rels selected FOR UPDATE/SHARE, and to do EvalPlanQual @@ -348,6 +388,7 @@ expand_targetlist(List *tlist, int command_type, true /* byval */ ); } break; + case CMD_MERGE: case CMD_UPDATE: if (!att_tup->attisdropped) { |