postgresql/src
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
..
backend Allow locking updated tuples in tuple_update() and tuple_delete() 2023-03-23 00:26:59 +03:00
bin Fix new test case to work on (some?) big-endian architectures. 2023-03-22 17:14:21 -04:00
common Add SHELL_ERROR and SHELL_EXIT_CODE magic variables to psql. 2023-03-21 13:03:56 -04:00
fe_utils Revert refactoring of restore command code to shell_restore.c 2023-02-06 08:28:42 +09:00
include Allow locking updated tuples in tuple_update() and tuple_delete() 2023-03-23 00:26:59 +03:00
interfaces libpq: Use modern socket flags, if available. 2023-03-17 20:40:34 +13:00
makefiles meson: Make auto the default of the ssl option 2023-03-13 07:04:11 +01:00
pl Fix a couple of typos 2023-03-22 08:44:59 +09:00
port Use nanosleep() to implement pg_usleep(). 2023-03-15 17:57:12 +13:00
template Use unnamed POSIX semaphores on Cygwin. 2023-01-06 10:33:28 +13:00
test Fix a couple of typos 2023-03-22 08:44:59 +09:00
timezone Fix outdated references to guc.c 2023-03-02 13:49:39 +01:00
tools Allow locking updated tuples in tuple_update() and tuple_delete() 2023-03-23 00:26:59 +03:00
tutorial Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
.gitignore
DEVELOPERS
Makefile Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
Makefile.global.in autoconf: Move export_dynamic determination to configure 2022-12-06 18:55:28 -08:00
Makefile.shlib autoconf: Rely on ar supporting index creation 2022-10-07 11:53:39 -07:00
meson.build Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
nls-global.mk Fix for make unportability 2022-07-13 09:15:01 +02:00