>From 09e16466f08705bf1e2fc79a88c4a04e3824a55e Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Mon, 4 Jul 2016 17:58:07 -0400
Subject: [PATCH 2/2] bug fix

---
 src/backend/access/heap/heapam.c                   |  2 +-
 .../isolation/expected/lock-committed-update.out   | 40 +++++++++++++++-------
 src/test/isolation/expected/lock-update-delete.out |  2 +-
 .../isolation/expected/update-locked-tuple.out     |  3 --
 4 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 4822fbb..ec8b090 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -4006,7 +4006,7 @@ l3:
 		UnlockReleaseBuffer(*buffer);
 		elog(ERROR, "attempted to lock invisible tuple");
 	}
-	else if (result == HeapTupleBeingUpdated)
+	else if (result == HeapTupleBeingUpdated || result == HeapTupleUpdated)
 	{
 		TransactionId xwait;
 		uint16		infomask;
diff --git a/src/test/isolation/expected/lock-committed-update.out b/src/test/isolation/expected/lock-committed-update.out
index 2684a69..670621a 100644
--- a/src/test/isolation/expected/lock-committed-update.out
+++ b/src/test/isolation/expected/lock-committed-update.out
@@ -17,7 +17,7 @@ t
 step s2l: <... completed>
 id             value          
 
-1              two            
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -40,7 +40,7 @@ t
 step s2l: <... completed>
 id             value          
 
-1              two            
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -112,7 +112,7 @@ t
 step s2l: <... completed>
 id             value          
 
-1              two            
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -139,7 +139,7 @@ t
 step s2l: <... completed>
 id             value          
 
-1              two            
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -213,7 +213,9 @@ pg_advisory_unlock
 
 t              
 step s2l: <... completed>
-error in steps s1ul s2l: ERROR:  could not serialize access due to concurrent update
+id             value          
+
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -234,7 +236,9 @@ pg_advisory_unlock
 
 t              
 step s2l: <... completed>
-error in steps s1ul s2l: ERROR:  could not serialize access due to concurrent update
+id             value          
+
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -304,7 +308,9 @@ pg_advisory_unlock
 
 t              
 step s2l: <... completed>
-error in steps s1ul s2l: ERROR:  could not serialize access due to concurrent update
+id             value          
+
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -329,7 +335,9 @@ pg_advisory_unlock
 
 t              
 step s2l: <... completed>
-error in steps s1ul s2l: ERROR:  could not serialize access due to concurrent update
+id             value          
+
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -403,7 +411,9 @@ pg_advisory_unlock
 
 t              
 step s2l: <... completed>
-error in steps s1ul s2l: ERROR:  could not serialize access due to concurrent update
+id             value          
+
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -424,7 +434,9 @@ pg_advisory_unlock
 
 t              
 step s2l: <... completed>
-error in steps s1ul s2l: ERROR:  could not serialize access due to concurrent update
+id             value          
+
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -494,7 +506,9 @@ pg_advisory_unlock
 
 t              
 step s2l: <... completed>
-error in steps s1ul s2l: ERROR:  could not serialize access due to concurrent update
+id             value          
+
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
@@ -519,7 +533,9 @@ pg_advisory_unlock
 
 t              
 step s2l: <... completed>
-error in steps s1ul s2l: ERROR:  could not serialize access due to concurrent update
+id             value          
+
+1              one            
 step s2c: COMMIT;
 pg_advisory_unlock_all
 
diff --git a/src/test/isolation/expected/lock-update-delete.out b/src/test/isolation/expected/lock-update-delete.out
index 344a6ec..3aa1253 100644
--- a/src/test/isolation/expected/lock-update-delete.out
+++ b/src/test/isolation/expected/lock-update-delete.out
@@ -156,7 +156,7 @@ t
 step s1l: <... completed>
 key            value          
 
-1              2              
+1              1              
 
 starting permutation: s2b s1l s2u s2_blocker1 s2r s2_unlock
 pg_advisory_lock
diff --git a/src/test/isolation/expected/update-locked-tuple.out b/src/test/isolation/expected/update-locked-tuple.out
index e77a098..1982c75 100644
--- a/src/test/isolation/expected/update-locked-tuple.out
+++ b/src/test/isolation/expected/update-locked-tuple.out
@@ -16,7 +16,6 @@ step s2u: UPDATE users SET sometime = '1830-10-04' WHERE id = 1;
 step s1u1: UPDATE orders SET name = 'order of olivier (2)', user_id = 1 WHERE id = 1;
 step s2c: COMMIT;
 step s1u2: UPDATE orders SET name = 'order of olivier (3)', user_id = 1 WHERE id = 1;
-ERROR:  could not serialize access due to concurrent update
 step s1c: COMMIT;
 
 starting permutation: s1b s2b s1u1 s2u s2c s1u2 s1c
@@ -26,7 +25,6 @@ step s1u1: UPDATE orders SET name = 'order of olivier (2)', user_id = 1 WHERE id
 step s2u: UPDATE users SET sometime = '1830-10-04' WHERE id = 1;
 step s2c: COMMIT;
 step s1u2: UPDATE orders SET name = 'order of olivier (3)', user_id = 1 WHERE id = 1;
-ERROR:  could not serialize access due to concurrent update
 step s1c: COMMIT;
 
 starting permutation: s1b s1u1 s2b s2u s2c s1u2 s1c
@@ -36,7 +34,6 @@ step s2b: BEGIN ISOLATION LEVEL REPEATABLE READ;
 step s2u: UPDATE users SET sometime = '1830-10-04' WHERE id = 1;
 step s2c: COMMIT;
 step s1u2: UPDATE orders SET name = 'order of olivier (3)', user_id = 1 WHERE id = 1;
-ERROR:  could not serialize access due to concurrent update
 step s1c: COMMIT;
 
 starting permutation: s1b s1u1 s2b s1u2 s2u s2c s1c
-- 
2.1.4

