postgresql/src/backend
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
..
access Fix locking a tuple updated by an aborted (sub)transaction 2016-09-09 15:54:29 -03:00
bootstrap Protect against multixact members wraparound 2015-04-28 11:32:53 -03:00
catalog Fix multiple minor infelicities in aclchk.c error reports. 2016-06-13 13:53:10 -04:00
commands Fix VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL 2016-09-09 11:45:16 +01:00
executor Fix improper repetition of previous results from a hashed aggregate. 2016-08-24 14:37:51 -04:00
foreign Arrange to cache FdwRoutine structs in foreign tables' relcache entries. 2013-03-06 23:48:09 -05:00
lib Misc comment typo fixes. 2014-12-16 16:39:33 +02:00
libpq Distrust external OpenSSL clients; clear err queue 2016-05-07 00:10:17 -04:00
main Make fallback implementation of pg_memory_barrier() work in 9.2 and 9.3. 2016-04-16 10:42:07 -04:00
nodes Fix improper repetition of previous results from a hashed aggregate. 2016-08-24 14:37:51 -04:00
optimizer Fix improper repetition of previous results from a hashed aggregate. 2016-08-24 14:37:51 -04:00
parser Improve documentation about CREATE TABLE ... LIKE. 2016-07-28 13:26:59 -04:00
po Translation updates 2016-08-08 10:53:45 -04:00
port Improve TranslateSocketError() to handle more Windows error codes. 2016-04-21 16:59:08 -04:00
postmaster Make "postgres -C guc" print "" not "(null)" for null-valued GUCs. 2016-06-22 11:55:32 -04:00
regex Suppress compiler warnings about useless comparison of unsigned to zero. 2016-02-15 17:11:52 -05:00
replication Fix typos 2016-02-29 18:11:58 -03:00
rewrite Improve error message for rejecting RETURNING clauses with dropped columns. 2016-02-29 19:11:53 -05:00
snowball Fix ancient encoding error in hungarian.stop. 2014-06-10 22:48:39 -04:00
storage Fix mdtruncate() to close fd.c handle of deleted segments. 2016-09-08 16:52:13 -07:00
tcop Be more predictable about reporting "lock timeout" vs "statement timeout". 2016-05-27 10:40:20 -04:00
tsearch Fix misestimation of n_distinct for a nearly-unique column with many nulls. 2016-08-07 18:52:02 -04:00
utils Don't require dynamic timezone abbreviations to match underlying time zone. 2016-09-02 17:29:32 -04:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Call check_keywords.pl in maintainer-check 2012-02-27 13:53:12 +02:00
Makefile AIX: Link the postgres executable with -Wl,-brtllib. 2015-07-15 21:00:30 -04:00
nls.mk xlogreader.c: Fix report_invalid_record translatability flag 2015-01-09 12:34:24 -03:00