postgresql/src/backend
Alvaro Herrera 649dd1b58b Avoid serializability errors when locking a tuple with a committed update
When key-share locking a tuple that has been not-key-updated, and the
update is a committed transaction, in some cases we raised
serializability errors:
    ERROR:  could not serialize access due to concurrent update

Because the key-share doesn't conflict with the update, the error is
unnecessary and inconsistent with the case that the update hasn't
committed yet.  This causes problems for some usage patterns, even if it
can be claimed that it's sufficient to retry the aborted transaction:
given a steady stream of updating transactions and a long locking
transaction, the long transaction can be starved indefinitely despite
multiple retries.

To fix, we recognize that HeapTupleSatisfiesUpdate can return
HeapTupleUpdated when an updating transaction has committed, and that we
need to deal with that case exactly as if it were a non-committed
update: verify whether the two operations conflict, and if not, carry on
normally.  If they do conflict, however, there is a difference: in the
HeapTupleBeingUpdated case we can just sleep until the concurrent
transaction is gone, while in the HeapTupleUpdated case this is not
possible and we must raise an error instead.

Per trouble report from Olivier Dony.

In addition to a couple of test cases that verify the changed behavior,
I added a test case to verify the behavior that remains unchanged,
namely that errors are raised when a update that modifies the key is
used.  That must still generate serializability errors.  One
pre-existing test case changes behavior; per discussion, the new
behavior is actually the desired one.

Discussion: https://www.postgresql.org/message-id/560AA479.4080807@odoo.com
  https://www.postgresql.org/message-id/20151014164844.3019.25750@wrigleys.postgresql.org

Backpatch to 9.3, where the problem appeared.
2016-07-15 14:17:20 -04:00
..
access Avoid serializability errors when locking a tuple with a committed update 2016-07-15 14:17:20 -04:00
bootstrap pgindent run for 9.5 2015-05-23 21:35:49 -04:00
catalog Fix multiple minor infelicities in aclchk.c error reports. 2016-06-13 13:53:10 -04:00
commands Fix CREATE MATVIEW/CREATE TABLE AS ... WITH NO DATA to not plan the query. 2016-06-27 15:57:21 -04:00
executor Fix failure to handle conflicts in non-arbiter exclusion constraints. 2016-07-04 16:09:11 -04:00
foreign Code review for foreign/custom join pushdown patch. 2015-05-10 14:36:36 -04:00
lib Avoid use of float arithmetic in bipartite_match.c. 2015-08-23 13:02:19 -04:00
libpq Distrust external OpenSSL clients; clear err queue 2016-05-06 23:47:42 -04:00
main Avoid crash on old Windows with AVX2-capable CPU for VS2013 builds 2016-03-10 14:10:32 +01:00
nodes Fix CREATE MATVIEW/CREATE TABLE AS ... WITH NO DATA to not plan the query. 2016-06-27 15:57:21 -04:00
optimizer Fix infer_arbiter_indexes() to not barf on system columns. 2016-05-11 17:06:53 -04:00
parser Fix grammar's AND/OR flattening to work with operator_precedence_warning. 2016-06-03 19:12:30 -04:00
po Translation updates 2016-05-09 10:05:46 -04:00
port Support building with Visual Studio 2015 2016-04-29 08:06:25 -04:00
postmaster Make "postgres -C guc" print "" not "(null)" for null-valued GUCs. 2016-06-22 11:55:24 -04:00
regex Suppress compiler warnings about useless comparison of unsigned to zero. 2016-02-15 17:11:52 -05:00
replication Fix typo in ReorderBufferIterTXNInit(). 2016-06-30 12:37:02 -04:00
rewrite Improve error message for rejecting RETURNING clauses with dropped columns. 2016-02-29 19:11:44 -05:00
snowball Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
storage Finish up XLOG_HINT renaming 2016-06-17 18:05:55 -04:00
tcop Be more predictable about reporting "lock timeout" vs "statement timeout". 2016-05-27 10:40:20 -04:00
tsearch Fix possible use of uninitialised value in ts_headline() 2016-04-08 21:25:32 +03:00
utils Fix GiST index build for NaN values in geometric types. 2016-07-14 18:46:00 -04:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile AIX: Link the postgres executable with -Wl,-brtllib. 2015-07-15 21:00:30 -04:00
nls.mk Translation updates 2015-02-01 23:23:40 -05:00