postgresql/src/include
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
..
access Allow locking updated tuples in tuple_update() and tuple_delete() 2023-03-23 00:26:59 +03:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Update copyright for 2023 2023-01-02 15:00:37 -05:00
bootstrap Update copyright for 2023 2023-01-02 15:00:37 -05:00
catalog Add functions to do timestamptz arithmetic in a non-default timezone. 2023-03-18 14:12:16 -04:00
commands Add a DEFAULT option to COPY FROM 2023-03-13 10:01:56 -04:00
common Revise pg_pwrite_zeros() 2023-03-06 13:21:33 +09:00
datatype Code review for commit 05a7be935. 2023-01-26 12:51:00 -05:00
executor Allow locking updated tuples in tuple_update() and tuple_delete() 2023-03-23 00:26:59 +03:00
fe_utils Update copyright for 2023 2023-01-02 15:00:37 -05:00
foreign Update copyright for 2023 2023-01-02 15:00:37 -05:00
jit Update copyright for 2023 2023-01-02 15:00:37 -05:00
lib Fix various typos in code and tests 2023-02-09 14:43:53 +09:00
libpq libpq: Remove code for SCM credential authentication 2023-03-17 10:52:26 +09:00
mb Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodes Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
optimizer Fix mis-handling of outer join quals generated by EquivalenceClasses. 2023-02-23 11:05:58 -05:00
parser Support [NO] INDENT option in XMLSERIALIZE(). 2023-03-15 16:59:09 -04:00
partitioning Fix various typos in code and tests 2023-02-09 14:43:53 +09:00
pch Update copyright for 2023 2023-01-02 15:00:37 -05:00
port Don't leak descriptors into subprograms. 2023-03-03 10:43:33 +13:00
portability instr_time: Represent time as an int64 on all platforms 2023-01-20 21:16:47 -08:00
postmaster Redesign archive modules 2023-02-17 14:26:42 +09:00
regex Update copyright for 2023 2023-01-02 15:00:37 -05:00
replication Add macros for ReorderBufferTXN toptxn. 2023-03-17 08:29:41 +05:30
rewrite Make Vars be outer-join-aware. 2023-01-30 13:16:20 -05:00
snowball Update copyright for 2023 2023-01-02 15:00:37 -05:00
statistics Update copyright for 2023 2023-01-02 15:00:37 -05:00
storage Update types in smgr API 2023-02-27 07:47:46 +01:00
tcop Update copyright for 2023 2023-01-02 15:00:37 -05:00
tsearch Fix ts_headline() to handle ORs and phrase queries more honestly. 2023-01-19 16:21:44 -05:00
utils Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
Makefile Include headers of archive/ in installation 2023-03-10 20:08:10 +09:00
c.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
fmgr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
funcapi.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
getopt_long.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
meson.build Include headers of archive/ in installation 2023-03-10 20:08:10 +09:00
miscadmin.h Fix outdated references to guc.c 2023-03-02 13:49:39 +01:00
pg_config.h.in libpq: Remove code for SCM credential authentication 2023-03-17 10:52:26 +09:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.meson meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
pg_config_manual.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_getopt.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_trace.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pgstat.h Remove PgStat_BackendFunctionEntry 2023-03-16 14:22:34 +09:00
pgtar.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pgtime.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
port.h Add SHELL_ERROR and SHELL_EXIT_CODE magic variables to psql. 2023-03-21 13:03:56 -04:00
postgres.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
postgres_ext.h Move RelFileNumber declarations to common/relpath.h. 2022-09-27 12:01:57 -04:00
postgres_fe.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
varatt.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
windowapi.h Update copyright for 2023 2023-01-02 15:00:37 -05:00