From c9ecf8adcf26ea02701e68ce40f150ff23f2ed1a Mon Sep 17 00:00:00 2001
From: David Rowley <dgrowley@gmail.com>
Date: Mon, 20 Mar 2017 20:26:13 +1300
Subject: [PATCH 2/4] Remove bogus code to release locks of subxacts

This code mistakenly assumed that sub transactions could have Access
Exclusive Locks stored in the RecoveryLockList, but
StandbyAcquireAccessExclusiveLock clearly states that the locks are stored
against the top level xid only. LogAccessExclusiveLock() agreed on this.

The code in question was doing no harm other than slowing down the replay of
all transaction commit/abort records of transactions which had any
subtransactions when any running transaction existed which held AELs.

Author: David Rowley
---
 src/backend/storage/ipc/standby.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index 7be8fd4..60b0513 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -670,8 +670,11 @@ StandbyReleaseLocks(TransactionId xid)
 }
 
 /*
- * Release locks for a transaction tree, starting at xid down, from
- * RecoveryLockList.
+ * Release locks for a transaction tree.
+ *
+ * Technically we only track Access Exclusive Locks against the top level
+ * transaction, so all we must do here is release the locks for a single
+ * transaction ID, and ignore any subtransactions.
  *
  * Called during WAL replay of COMMIT/ROLLBACK when in hot standby mode,
  * to remove any AccessExclusiveLocks requested by a transaction.
@@ -679,12 +682,12 @@ StandbyReleaseLocks(TransactionId xid)
 void
 StandbyReleaseLockTree(TransactionId xid, int nsubxids, TransactionId *subxids)
 {
-	int			i;
-
 	StandbyReleaseLocks(xid);
 
-	for (i = 0; i < nsubxids; i++)
-		StandbyReleaseLocks(subxids[i]);
+	/*
+	 * If we ever are to track AELs on the subxact which the lock belongs to
+	 * then here marks the spot of where those should be released.
+	 */
 }
 
 /*
-- 
1.9.5.msysgit.1

