Hello guys.
In the previous discussion [1] we find out that while we are in
transaction function definition is not invalidated if it was redefined
in another session. Here is a patch to fix this. Also, I did a small
perfomance impact measurement (test.sh in attachment) on my home PC
with Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz. The result is (each
transaction is a 10 million calls to functions):

- without patch
latency average = 37087.639 ms
tps = 0.026963

- with patch
latency average = 38793.125 ms
tps = 0.025778

What do you think about it, guys?

[1] 
https://www.postgresql.org/message-id/flat/1205251664297977%40mail.yandex.ru



From 2a9bd029dcb180b01e0274ae6ef18faf647ff777 Mon Sep 17 00:00:00 2001
From: Miha <m7o...@yandex.com>
Date: Thu, 6 Oct 2022 19:13:26 +0300
Subject: [PATCH] Check system cache invalidations before each command in
 transaction

---
 src/backend/access/transam/xact.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index c1ffbd89b8..c7593b6c55 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -2939,14 +2939,22 @@ StartTransactionCommand(void)

 			/*
 			 * We are somewhere in a transaction block or subtransaction and
-			 * about to start a new command.  For now we do nothing, but
-			 * someday we may do command-local resource initialization. (Note
-			 * that any needed CommandCounterIncrement was done by the
-			 * previous CommitTransactionCommand.)
+			 * about to start a new command. (Note that any needed
+			 * CommandCounterIncrement was done by the previous
+			 * CommitTransactionCommand.)
 			 */
 		case TBLOCK_INPROGRESS:
-		case TBLOCK_IMPLICIT_INPROGRESS:
 		case TBLOCK_SUBINPROGRESS:
+			AcceptInvalidationMessages();
+			break;
+
+			/*
+			 * We are somewhere in implicit transaction block. For now we do
+			 * nothing, but someday we may do command-local resource
+			 * initialization. (Note that any needed  CommandCounterIncrement
+			 * was done by the previous CommitTransactionCommand.)
+			 */
+		case TBLOCK_IMPLICIT_INPROGRESS:
 			break;

 			/*
--
2.25.1

Attachment: test.sh
Description: application/shellscript

Reply via email to