postgresql/src/include/access
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
..
amapi.h Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
amvalidate.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
attmap.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
attnum.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
brin.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
brin_internal.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
brin_page.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
brin_pageops.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
brin_revmap.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
brin_tuple.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
brin_xlog.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
bufmask.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
clog.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
commit_ts.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
detoast.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
genam.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
generic_xlog.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
gin.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
gin_private.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
ginblock.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
ginxlog.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
gist.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
gist_private.h Remove function declarations from headers for some undefined functions 2023-01-11 11:54:55 +09:00
gistscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
gistxlog.h Update some incorrect comments about xlog records. 2023-03-03 12:52:04 -05:00
hash.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
hash_xlog.h Change xl_hash_vacuum_one_page.ntuples from int to uint16. 2023-02-27 08:32:45 +05:30
heapam.h Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
heapam_xlog.h Update some incorrect comments about xlog records. 2023-03-03 12:52:04 -05:00
heaptoast.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
hio.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
htup.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
htup_details.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
itup.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
multixact.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nbtree.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
nbtxlog.h Update some incorrect comments about xlog records. 2023-03-03 12:52:04 -05:00
parallel.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
printsimple.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
printtup.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
relation.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
reloptions.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
relscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
rewriteheap.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
rmgr.h Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
rmgrlist.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
sdir.h Remove dead NoMovementScanDirection code 2023-02-01 10:52:41 +13:00
session.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
skey.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
slru.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
spgist.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
spgist_private.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
spgxlog.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
stratnum.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
subtrans.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
syncscan.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
sysattr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
table.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tableam.h Allow locking updated tuples in tuple_update() and tuple_delete() 2023-03-23 00:26:59 +03:00
timeline.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
toast_compression.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
toast_helper.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
toast_internals.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
transam.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tsmapi.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tupconvert.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tupdesc.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tupdesc_details.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
tupmacs.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
twophase.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
twophase_rmgr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
valid.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
visibilitymap.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
visibilitymapdefs.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xact.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xlog.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xlog_internal.h Change xl_hash_vacuum_one_page.ntuples from int to uint16. 2023-02-27 08:32:45 +05:30
xlogarchive.h Revert refactoring of restore command code to shell_restore.c 2023-02-06 08:28:42 +09:00
xlogbackup.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xlogdefs.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xloginsert.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xlogprefetcher.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xlogreader.h Remove function declarations from headers for some undefined functions 2023-01-11 11:54:55 +09:00
xlogrecord.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xlogrecovery.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xlogstats.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
xlogutils.h Update copyright for 2023 2023-01-02 15:00:37 -05:00