It looks to me like we're missing a trick in CancelVirtualTransaction -- there's a loop to compare all VXIDs, and we break as soon as find a perfect match in (backendid, localTransactionId). However, once we've found the backendId that matches, it's not possible for there to be another entry with the same backendId, so we might as well just quit the loop, even if we don't send a signal.
No, I don't know if this shows in profiles. I just noticed while reading code. Attached patch (git diff --ignore-space-change; needs reindent) illustrates. This was added by commit efc16ea52067 (Dec 2009) and seems unchanged since then. -- Álvaro Herrera Developer, https://www.PostgreSQL.org/
commit 9082e3f85bdc076c9187e6120d5fb94e53c4403a[m Author: Alvaro Herrera <alvhe...@alvh.no-ip.org> AuthorDate: Fri Jun 29 12:59:28 2018 -0400 CommitDate: Fri Jun 29 12:59:28 2018 -0400 fixup CancelVirtualTransaction diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 7f293d989b..2f776cf5c3 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -2658,8 +2658,9 @@ 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) + { + if (procvxid.localTransactionId == vxid.localTransactionId) { proc->recoveryConflictPending = true; pid = proc->pid; @@ -2671,6 +2672,7 @@ CancelVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode) */ (void) SendProcSignal(pid, sigmode, vxid.backendId); } + } break; } }