postgresql/src/backend
Alexander Korotkov 87985cc925 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 the 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 commit eliminates step 2 by taking the lock during the first
tuple_update()/tuple_delete() call.  The heap table access method saves some
effort 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.

Also, this commit makes tuple_update()/tuple_delete() optionally save the old
tuple into the dedicated slot.  That saves efforts on re-fetching tuples in
certain cases.

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
2024-03-26 01:27:56 +02:00
..
access Allow locking updated tuples in tuple_update() and tuple_delete() 2024-03-26 01:27:56 +02:00
archive Add macro for customizing an archiving WARNING message. 2024-03-04 15:41:42 -06:00
backup Revert "Temporary patch to help debug pg_walsummary test failures." 2024-03-20 11:34:00 -05:00
bootstrap Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
catalog Track last_inactive_time in pg_replication_slots. 2024-03-25 16:34:33 +05:30
commands Allow locking updated tuples in tuple_update() and tuple_delete() 2024-03-26 01:27:56 +02:00
executor Allow locking updated tuples in tuple_update() and tuple_delete() 2024-03-26 01:27:56 +02:00
foreign Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
jit Add SQL/JSON query functions 2024-03-21 17:07:03 +09:00
lib Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
libpq Revert "Add notBefore and notAfter to SSL cert info display" 2024-03-22 22:58:41 +01:00
main Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
nodes Do not output actual value of location fields in node serialization by default 2024-03-22 09:49:12 +01:00
optimizer Refactor predicate_{implied,refuted}_by_simple_clause. 2024-03-25 17:45:15 -04:00
parser Allow planner to use Merge Append to efficiently implement UNION 2024-03-25 14:31:14 +13:00
partitioning Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
po Update copyright for 2024 2024-01-03 20:49:05 -05:00
port Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
postmaster Avoid overflow in MaybeRemoveOldWalSummaries(). 2024-03-20 13:31:58 -05:00
regex Support C.UTF-8 locale in the new builtin collation provider. 2024-03-19 15:24:41 -07:00
replication Fix indentation from a11f330b5 2024-03-25 14:18:33 +01:00
rewrite Add RETURNING support to MERGE. 2024-03-17 13:58:59 +00:00
snowball Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
statistics Make stxstattarget nullable 2024-03-17 12:26:26 +01:00
storage Rework lwlocknames.txt to become lwlocklist.h 2024-03-20 11:55:20 +01:00
tcop Do not output actual value of location fields in node serialization by default 2024-03-22 09:49:12 +01:00
tsearch Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
utils Clarify comment for LogicalTapeSetBlocks(). 2024-03-25 11:51:44 -07:00
.gitignore
Makefile Rework lwlocknames.txt to become lwlocklist.h 2024-03-20 11:55:20 +01:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build Remove AIX support 2024-02-28 15:17:23 +04:00
nls.mk Remove distprep 2023-11-06 15:18:04 +01:00