Same patch, commit message added.  Adding to commitfest.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>From 2cbe6fe5ac7617e424a63b820a6a2c83b712bab5 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvhe...@alvh.no-ip.org>
Date: Thu, 6 Dec 2018 17:30:58 -0300
Subject: [PATCH] Optimize CancelVirtualTransaction a little bit

When scanning the list of virtual transactions looking for one
particular vxid, we cancel the transaction *and* break out of the loop
only if both backendId and localTransactionId matches us.  The canceling
part is okay, but limiting the break to that case is pointless: if we
found the correct backendId, there cannot be any other entry with the
same backendId.  Rework the loop so that we break out of it if backendId
matches even if the localTransactionId part doesn't.

Discussion: https://postgr.es/m/20180629170512.d6kof6l6uu3qqpd6@alvherre.pgsql
---
 src/backend/storage/ipc/procarray.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index dc7e875680..5ed588d9be 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -2683,18 +2683,20 @@ CancelVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode)
 
 		GET_VXID_FROM_PGPROC(procvxid, *proc);
 
-		if (procvxid.backendId == vxid.backendId &&
-			procvxid.localTransactionId == vxid.localTransactionId)
+		if (procvxid.backendId == vxid.backendId)
 		{
-			proc->recoveryConflictPending = true;
-			pid = proc->pid;
-			if (pid != 0)
+			if (procvxid.localTransactionId == vxid.localTransactionId)
 			{
-				/*
-				 * Kill the pid if it's still here. If not, that's what we
-				 * wanted so ignore any errors.
-				 */
-				(void) SendProcSignal(pid, sigmode, vxid.backendId);
+				proc->recoveryConflictPending = true;
+				pid = proc->pid;
+				if (pid != 0)
+				{
+					/*
+					 * Kill the pid if it's still here. If not, that's what we
+					 * wanted so ignore any errors.
+					 */
+					(void) SendProcSignal(pid, sigmode, vxid.backendId);
+				}
 			}
 			break;
 		}
-- 
2.11.0

Reply via email to