From d3adf0be6ac338031223ded04baab2d05cbd0f24 Mon Sep 17 00:00:00 2001 From: Zhao Junwang Date: Wed, 9 Aug 2023 11:43:21 +0800 Subject: [PATCH v3] [BackendXidGetPid] only access allProcs when xid matches In function `BackendXidGetPid`, when looping every proc's TransactionId, there is no need to access its PGPROC since there is shared memory access: `arrayP->pgprocnos[index]`. Though the compiler can optimize this kind of inefficiency, I believe we should ship with better code. Signed-off-by: Zhao Junwang --- src/backend/storage/ipc/procarray.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 2a3da49b8f..016f08b5b4 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -3205,11 +3205,11 @@ BackendXidGetPid(TransactionId xid) for (index = 0; index < arrayP->numProcs; index++) { - int pgprocno = arrayP->pgprocnos[index]; - PGPROC *proc = &allProcs[pgprocno]; - if (other_xids[index] == xid) { + int pgprocno = arrayP->pgprocnos[index]; + PGPROC *proc = &allProcs[pgprocno]; + result = proc->pid; break; } -- 2.41.0