@@ -1559,22 +1559,6 @@ ExecDelete(ModifyTableContext *context,
15591559 {
15601560 case TM_Ok :
15611561 Assert (context -> tmfd .traversed );
1562-
1563- /*
1564- * Save locked tuple for further processing of
1565- * RETURNING clause.
1566- */
1567- if (processReturning &&
1568- resultRelInfo -> ri_projectReturning &&
1569- !resultRelInfo -> ri_FdwRoutine )
1570- {
1571- TupleTableSlot * returningSlot ;
1572-
1573- returningSlot = ExecGetReturningSlot (estate , resultRelInfo );
1574- ExecCopySlot (returningSlot , inputslot );
1575- ExecMaterializeSlot (returningSlot );
1576- }
1577-
15781562 epqslot = EvalPlanQual (context -> epqstate ,
15791563 resultRelationDesc ,
15801564 resultRelInfo -> ri_RangeTableIndex ,
@@ -1689,17 +1673,12 @@ ExecDelete(ModifyTableContext *context,
16891673 }
16901674 else
16911675 {
1692- /*
1693- * Tuple can be already fetched to the returning slot in case
1694- * we've previously locked it. Fetch the tuple only if the slot
1695- * is empty.
1696- */
16971676 slot = ExecGetReturningSlot (estate , resultRelInfo );
16981677 if (oldtuple != NULL )
16991678 {
17001679 ExecForceStoreHeapTuple (oldtuple , slot , false);
17011680 }
1702- else if ( TupIsNull ( slot ))
1681+ else
17031682 {
17041683 if (!table_tuple_fetch_row_version (resultRelationDesc , tupleid ,
17051684 SnapshotAny , slot ))
@@ -2414,19 +2393,6 @@ ExecUpdate(ModifyTableContext *context, ResultRelInfo *resultRelInfo,
24142393 case TM_Ok :
24152394 Assert (context -> tmfd .traversed );
24162395
2417- /* Make sure ri_oldTupleSlot is initialized. */
2418- if (unlikely (!resultRelInfo -> ri_projectNewInfoValid ))
2419- ExecInitUpdateProjection (context -> mtstate ,
2420- resultRelInfo );
2421-
2422- /*
2423- * Save the locked tuple for further calculation
2424- * of the new tuple.
2425- */
2426- oldSlot = resultRelInfo -> ri_oldTupleSlot ;
2427- ExecCopySlot (oldSlot , inputslot );
2428- ExecMaterializeSlot (oldSlot );
2429-
24302396 epqslot = EvalPlanQual (context -> epqstate ,
24312397 resultRelationDesc ,
24322398 resultRelInfo -> ri_RangeTableIndex ,
@@ -2435,6 +2401,18 @@ ExecUpdate(ModifyTableContext *context, ResultRelInfo *resultRelInfo,
24352401 /* Tuple not passing quals anymore, exiting... */
24362402 return NULL ;
24372403
2404+ /* Make sure ri_oldTupleSlot is initialized. */
2405+ if (unlikely (!resultRelInfo -> ri_projectNewInfoValid ))
2406+ ExecInitUpdateProjection (context -> mtstate ,
2407+ resultRelInfo );
2408+
2409+ /* Fetch the most recent version of old tuple. */
2410+ oldSlot = resultRelInfo -> ri_oldTupleSlot ;
2411+ if (!table_tuple_fetch_row_version (resultRelationDesc ,
2412+ tupleid ,
2413+ SnapshotAny ,
2414+ oldSlot ))
2415+ elog (ERROR , "failed to fetch tuple being updated" );
24382416 slot = ExecGetUpdateNewTuple (resultRelInfo ,
24392417 epqslot , oldSlot );
24402418 goto redo_act ;
0 commit comments