postgresql/src/backend/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
..
brin Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
common Revert "Add eager and lazy freezing strategies to VACUUM." 2023-01-25 22:22:27 -08:00
gin Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
gist Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
hash Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
heap Allow locking updated tuples in tuple_update() and tuple_delete() 2023-03-23 00:26:59 +03:00
index Update copyright for 2023 2023-01-02 15:00:37 -05:00
nbtree Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
rmgrdesc Update copyright for 2023 2023-01-02 15:00:37 -05:00
spgist Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
table Allow locking updated tuples in tuple_update() and tuple_delete() 2023-03-23 00:26:59 +03:00
tablesample Update copyright for 2023 2023-01-02 15:00:37 -05:00
transam Revise pg_pwrite_zeros() 2023-03-06 13:21:33 +09:00
Makefile Introduce access/{table.h, relation.h}, for generic functions from heapam.h. 2019-01-21 10:51:36 -08:00
meson.build Update copyright for 2023 2023-01-02 15:00:37 -05:00