postgresql/src/backend
Alvaro Herrera 533e9c6b06 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
catalog Rename pg_stat_wal_receiver.conn_info to conninfo. 2016-07-07 12:59:39 +09:00
commands Print a given subplan only once in EXPLAIN. 2016-07-11 18:14:29 -04:00
executor Fix failure to handle conflicts in non-arbiter exclusion constraints. 2016-07-04 16:09:11 -04:00
foreign
lib
libpq Fix several mistakes around parallel workers and client_encoding. 2016-06-30 18:35:32 -04:00
main
nodes Fix typo in comment. 2016-07-07 16:13:37 -04:00
optimizer Adjust spellings of forms of "cancel" 2016-07-14 22:48:26 -04:00
parser Rethink node-level representation of partial-aggregation modes. 2016-06-26 14:33:38 -04:00
po Translation updates 2016-06-20 09:48:08 -04:00
port
postmaster Make "postgres -C guc" print "" not "(null)" for null-valued GUCs. 2016-06-22 11:55:18 -04:00
regex
replication walreceiver: tweak pg_stat_wal_receiver behavior 2016-07-01 13:53:46 -04:00
rewrite
snowball
storage Adjust spellings of forms of "cancel" 2016-07-14 22:48:26 -04:00
tcop Revert "Add some temporary code to record stack usage at server process exit." 2016-07-10 12:44:20 -04:00
tsearch Add serial comma and quoting to message 2016-07-12 18:37:34 -04:00
utils Fix parsing NOT sequence in tsquery 2016-07-15 20:01:41 +03:00
.gitignore
Makefile Provide and use a makefile target to build all generated headers. 2016-07-01 15:09:02 -04:00
common.mk
nls.mk