@@ -24,7 +24,7 @@ index bf551b0395..10d2044ae6 100644
2424 bool DefaultXactDeferrable = false;
2525 bool XactDeferrable;
2626diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c
27- index 6b63f93e6d..060146d127 100644
27+ index bdf59a10fc..972453d9a5 100644
2828--- a/src/backend/executor/execExprInterp.c
2929+++ b/src/backend/executor/execExprInterp.c
3030@@ -1799,6 +1799,16 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
@@ -77,7 +77,7 @@ index b3ce4bae53..8f2bb12542 100644
7777 * ResultRelInfos needed by subplans are initialized from scratch when the
7878 * subplans themselves are initialized.
7979diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
80- index 0780554246..a90f3a495d 100644
80+ index 55c430c9ec..21d9e6304a 100644
8181--- a/src/backend/executor/nodeModifyTable.c
8282+++ b/src/backend/executor/nodeModifyTable.c
8383@@ -510,7 +510,7 @@ ExecInitInsertProjection(ModifyTableState *mtstate,
@@ -89,15 +89,15 @@ index 0780554246..a90f3a495d 100644
8989 ExecInitUpdateProjection(ModifyTableState *mtstate,
9090 ResultRelInfo *resultRelInfo)
9191 {
92- @@ -2487 ,6 +2487 ,7 @@ ExecModifyTable(PlanState *pstate)
92+ @@ -2486 ,6 +2486 ,7 @@ ExecModifyTable(PlanState *pstate)
9393 ItemPointerData tuple_ctid;
9494 HeapTupleData oldtupdata;
9595 HeapTuple oldtuple;
9696+ ResultRelInfo *saved_resultRelInfo;
9797
9898 CHECK_FOR_INTERRUPTS();
9999
100- @@ -2524 ,12 +2525 ,23 @@ ExecModifyTable(PlanState *pstate)
100+ @@ -2523 ,12 +2524 ,23 @@ ExecModifyTable(PlanState *pstate)
101101 resultRelInfo = node->resultRelInfo + node->mt_lastResultIndex;
102102 subplanstate = outerPlanState(node);
103103
@@ -121,7 +121,7 @@ index 0780554246..a90f3a495d 100644
121121 /*
122122 * Reset the per-output-tuple exprcontext. This is needed because
123123 * triggers expect to use that context as workspace. It's a bit ugly
124- @@ -2563 ,7 +2575 ,9 @@ ExecModifyTable(PlanState *pstate)
124+ @@ -2562 ,7 +2574 ,9 @@ ExecModifyTable(PlanState *pstate)
125125 bool isNull;
126126 Oid resultoid;
127127
@@ -132,7 +132,7 @@ index 0780554246..a90f3a495d 100644
132132 &isNull);
133133 if (isNull)
134134 elog(ERROR, "tableoid is NULL");
135- @@ -2582 ,6 +2596 ,8 @@ ExecModifyTable(PlanState *pstate)
135+ @@ -2581 ,6 +2595 ,8 @@ ExecModifyTable(PlanState *pstate)
136136 if (resultRelInfo->ri_usesFdwDirectModify)
137137 {
138138 Assert(resultRelInfo->ri_projectReturning);
@@ -141,15 +141,15 @@ index 0780554246..a90f3a495d 100644
141141
142142 /*
143143 * A scan slot containing the data that was actually inserted,
144- @@ -2591 ,6 +2607 ,7 @@ ExecModifyTable(PlanState *pstate)
144+ @@ -2590 ,6 +2606 ,7 @@ ExecModifyTable(PlanState *pstate)
145145 */
146146 slot = ExecProcessReturning(resultRelInfo, NULL, planSlot);
147147
148148+ estate->es_result_relation_info = saved_resultRelInfo;
149149 return slot;
150150 }
151151
152- @@ -2620 ,7 +2637 ,8 @@ ExecModifyTable(PlanState *pstate)
152+ @@ -2619 ,7 +2636 ,8 @@ ExecModifyTable(PlanState *pstate)
153153 {
154154 /* ri_RowIdAttNo refers to a ctid attribute */
155155 Assert(AttributeNumberIsValid(resultRelInfo->ri_RowIdAttNo));
@@ -159,7 +159,7 @@ index 0780554246..a90f3a495d 100644
159159 resultRelInfo->ri_RowIdAttNo,
160160 &isNull);
161161 /* shouldn't ever get a null result... */
162- @@ -2650 ,7 +2668 ,8 @@ ExecModifyTable(PlanState *pstate)
162+ @@ -2649 ,7 +2667 ,8 @@ ExecModifyTable(PlanState *pstate)
163163 */
164164 else if (AttributeNumberIsValid(resultRelInfo->ri_RowIdAttNo))
165165 {
@@ -169,7 +169,7 @@ index 0780554246..a90f3a495d 100644
169169 resultRelInfo->ri_RowIdAttNo,
170170 &isNull);
171171 /* shouldn't ever get a null result... */
172- @@ -2681 ,8 +2700 ,12 @@ ExecModifyTable(PlanState *pstate)
172+ @@ -2680 ,8 +2699 ,12 @@ ExecModifyTable(PlanState *pstate)
173173 /* Initialize projection info if first time for this table */
174174 if (unlikely(!resultRelInfo->ri_projectNewInfoValid))
175175 ExecInitInsertProjection(node, resultRelInfo);
@@ -184,58 +184,25 @@ index 0780554246..a90f3a495d 100644
184184 estate, node->canSetTag);
185185 break;
186186 case CMD_UPDATE:
187- @@ -2690,37 +2713,45 @@ ExecModifyTable(PlanState *pstate)
187+ @@ -2689,6 +2712,13 @@ ExecModifyTable(PlanState *pstate)
188188 if (unlikely(!resultRelInfo->ri_projectNewInfoValid))
189189 ExecInitUpdateProjection(node, resultRelInfo);
190190
191- - /*
192- - * Make the new tuple by combining plan's output tuple with
193- - * the old tuple being updated.
194- - */
195- - oldSlot = resultRelInfo->ri_oldTupleSlot;
196- - if (oldtuple != NULL)
197- - {
198- - /* Use the wholerow junk attr as the old tuple. */
199- - ExecForceStoreHeapTuple(oldtuple, oldSlot, false);
200- - }
201- - else
191+ + /*
192+ + * Do not change the indentation for PostgreSQL code to make it
193+ + * easier to merge new PostgreSQL changes.
194+ + */
202195+ /* Do nothing in case tuple was modified in pg_pathman: */
203196+ if (!estate->es_original_tuple)
204- {
205- - /* Fetch the most recent version of old tuple. */
206- - Relation relation = resultRelInfo->ri_RelationDesc;
207- -
208- - Assert(tupleid != NULL);
209- - if (!table_tuple_fetch_row_version(relation, tupleid,
210- - SnapshotAny,
211- - oldSlot))
212- - elog(ERROR, "failed to fetch tuple being updated");
213- + /*
214- + * Make the new tuple by combining plan's output tuple
215- + * with the old tuple being updated.
216- + */
217- + oldSlot = resultRelInfo->ri_oldTupleSlot;
218- + if (oldtuple != NULL)
219- + {
220- + /* Use the wholerow junk attr as the old tuple. */
221- + ExecForceStoreHeapTuple(oldtuple, oldSlot, false);
222- + }
223- + else
224- + {
225- + /* Fetch the most recent version of old tuple. */
226- + Relation relation = resultRelInfo->ri_RelationDesc;
227- +
228- + Assert(tupleid != NULL);
229- + if (!table_tuple_fetch_row_version(relation, tupleid,
230- + SnapshotAny,
231- + oldSlot))
232- + elog(ERROR, "failed to fetch tuple being updated");
233- + }
234- + slot = ExecGetUpdateNewTuple(resultRelInfo, planSlot,
235- + oldSlot);
197+ + {
198+ /*
199+ * Make the new tuple by combining plan's output tuple with
200+ * the old tuple being updated.
201+ @@ -2712,14 +2742,19 @@ ExecModifyTable(PlanState *pstate)
236202 }
237- - slot = ExecGetUpdateNewTuple(resultRelInfo, planSlot,
238- - oldSlot);
203+ slot = ExecGetUpdateNewTuple(resultRelInfo, planSlot,
204+ oldSlot);
205+ + }
239206
240207 /* Now apply the update. */
241208- slot = ExecUpdate(node, resultRelInfo, tupleid, oldtuple, slot,
@@ -253,7 +220,7 @@ index 0780554246..a90f3a495d 100644
253220 planSlot, &node->mt_epqstate, estate,
254221 true, /* processReturning */
255222 node->canSetTag,
256- @@ -2737 ,7 +2768 ,10 @@ ExecModifyTable(PlanState *pstate)
223+ @@ -2736 ,7 +2771 ,10 @@ ExecModifyTable(PlanState *pstate)
257224 * the work on next call.
258225 */
259226 if (slot)
@@ -264,23 +231,23 @@ index 0780554246..a90f3a495d 100644
264231 }
265232
266233 /*
267- @@ -2753 ,6 +2787 ,7 @@ ExecModifyTable(PlanState *pstate)
234+ @@ -2752 ,6 +2790 ,7 @@ ExecModifyTable(PlanState *pstate)
268235
269236 node->mt_done = true;
270237
271238+ estate->es_result_relation_info = saved_resultRelInfo;
272239 return NULL;
273240 }
274241
275- @@ -2827 ,6 +2862 ,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
242+ @@ -2826 ,6 +2865 ,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
276243 ListCell *l;
277244 int i;
278245 Relation rel;
279246+ ResultRelInfo *saved_resultRelInfo;
280247
281248 /* check for unsupported flags */
282249 Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
283- @@ -2923 ,6 +2959 ,13 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
250+ @@ -2922 ,6 +2962 ,13 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
284251 i++;
285252 }
286253
@@ -294,7 +261,7 @@ index 0780554246..a90f3a495d 100644
294261 /*
295262 * Now we may initialize the subplan.
296263 */
297- @@ -3004 ,6 +3047 ,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
264+ @@ -3002 ,6 +3049 ,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
298265 ExecInitStoredGenerated(resultRelInfo, estate, operation);
299266 }
300267
0 commit comments