postgresql/src/backend/access
Alvaro Herrera dfe7121dfb Fix locking a tuple updated by an aborted (sub)transaction
When heap_lock_tuple decides to follow the update chain, it tried to
also lock any version of the tuple that was created by an update that
was subsequently rolled back.  This is pointless, since for all intents
and purposes that tuple exists no more; and moreover it causes
misbehavior, as reported independently by Marko Tiikkaja and Marti
Raudsepp: some SELECT FOR UPDATE/SHARE queries may fail to return
the tuples, and assertion-enabled builds crash.

Fix by having heap_lock_updated_tuple test the xmin and return success
immediately if the tuple was created by an aborted transaction.

The condition where tuples become invisible occurs when an updated tuple
chain is followed by heap_lock_updated_tuple, which reports the problem
as HeapTupleSelfUpdated to its caller heap_lock_tuple, which in turn
propagates that code outwards possibly leading the calling code
(ExecLockRows) to believe that the tuple exists no longer.

Backpatch to 9.3.  Only on 9.5 and newer this leads to a visible
failure, because of commit 27846f02c176; before that, heap_lock_tuple
skips the whole dance when the tuple is already locked by the same
transaction, because of the ancient HeapTupleSatisfiesUpdate behavior.
Still, the buggy condition may also exist in more convoluted scenarios
involving concurrent transactions, so it seems safer to fix the bug in
the old branches too.

Discussion:
	https://www.postgresql.org/message-id/CABRT9RC81YUf1=jsmWopcKJEro=VoeG2ou6sPwyOUTx_qteRsg@mail.gmail.com
	https://www.postgresql.org/message-id/48d3eade-98d3-8b9a-477e-1a8dc32a724d@joh.to
2016-09-09 15:54:29 -03:00
..
common Re-Align *_freeze_max_age reloption limits with corresponding GUC limits. 2015-10-05 11:57:11 +02:00
gin Make GIN's cleanup pending list process interruptable 2015-09-07 17:18:10 +03:00
gist Fix GiST index build for NaN values in geometric types. 2016-07-14 18:46:00 -04:00
hash Remove unnecessary variables in _hash_splitbucket(). 2015-04-03 16:49:11 -04:00
heap Fix locking a tuple updated by an aborted (sub)transaction 2016-09-09 15:54:29 -03:00
index Fix BuildIndexValueDescription for expressions 2015-01-29 21:59:51 -05:00
nbtree Fix incorrect handling of NULL index entries in indexed ROW() comparisons. 2016-03-09 14:51:01 -05:00
rmgrdesc Rework tuple freezing protocol 2013-12-16 11:29:51 -03:00
spgist Fix overly-strict assertions in spgtextproc.c. 2016-01-02 16:25:07 -05:00
transam Prevent starting a standalone backend with standby_mode on. 2016-08-31 08:52:13 -04:00
Makefile Split out rmgr rm_desc functions into their own files 2012-11-28 13:01:15 -03:00