postgresql/src/include/executor
Alexander Korotkov 11470f544e Allow locking updated tuples in tuple_update() and tuple_delete()
Currently, in read committed transaction isolation mode (default), we have the
following sequence of actions when tuple_update()/tuple_delete() finds
the tuple updated by concurrent transaction.

1. Attempt to update/delete tuple with tuple_update()/tuple_delete(), which
   returns TM_Updated.
2. Lock tuple with tuple_lock().
3. Re-evaluate plan qual (recheck if we still need to update/delete and
   calculate the new tuple for update).
4. Second attempt to update/delete tuple with tuple_update()/tuple_delete().
   This attempt should be successful, since the tuple was previously locked.

This patch eliminates step 2 by taking the lock during first
tuple_update()/tuple_delete() call.  Heap table access method saves some
efforts by checking the updated tuple once instead of twice.  Future
undo-based table access methods, which will start from the latest row version,
can immediately place a lock there.

The code in nodeModifyTable.c is simplified by removing the nested switch/case.

Discussion: https://postgr.es/m/CAPpHfdua-YFw3XTprfutzGp28xXLigFtzNbuFY8yPhqeq6X5kg%40mail.gmail.com
Reviewed-by: Aleksander Alekseev, Pavel Borisov, Vignesh C, Mason Sharp
Reviewed-by: Andres Freund, Chris Travers
2023-03-23 00:26:59 +03:00
..
execAsync.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
execExpr.h Add static assertion ensuring sizeof(ExprEvalStep) <= 64 bytes 2023-02-22 14:30:39 -08:00
execParallel.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
execPartition.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
execdebug.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
execdesc.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
executor.h Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
functions.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
hashjoin.h Fix race in parallel hash join batch cleanup, take II. 2023-03-21 14:29:34 +13:00
instrument.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeAgg.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeAppend.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeBitmapAnd.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeBitmapHeapscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeBitmapIndexscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeBitmapOr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeCtescan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeCustom.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeForeignscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeFunctionscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeGather.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeGatherMerge.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeGroup.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeHash.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeHashjoin.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeIncrementalSort.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeIndexonlyscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeIndexscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeLimit.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeLockRows.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeMaterial.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeMemoize.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeMergeAppend.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeMergejoin.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeModifyTable.h Make new GENERATED-expressions code more bulletproof. 2023-01-15 13:14:52 -05:00
nodeNamedtuplestorescan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeNestloop.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeProjectSet.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeRecursiveunion.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeResult.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeSamplescan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeSeqscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeSetOp.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeSort.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeSubplan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeSubqueryscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeTableFuncscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeTidrangescan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeTidscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeUnique.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeValuesscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeWindowAgg.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeWorktablescan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
spi.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
spi_priv.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tablefunc.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tqueue.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tstoreReceiver.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tuptable.h Allow locking updated tuples in tuple_update() and tuple_delete() 2023-03-23 00:26:59 +03:00