0001-Advance-transaction-timestamp-in-intra-procedure-tra.patch

text/plain

Filename: 0001-Advance-transaction-timestamp-in-intra-procedure-tra.patch
Type: text/plain
Part: 0
Message: Re: transction_timestamp() inside of procedures

Patch

Format: format-patch
Series: patch 0001
Subject: Advance transaction timestamp in intra-procedure transactions
File+
src/backend/access/transam/xact.c 12 7
From 2a8c214479adb4b98c8b6c95875d8bebd88cb940 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Fri, 28 Sep 2018 09:33:24 +0200
Subject: [PATCH] Advance transaction timestamp in intra-procedure transactions

---
 src/backend/access/transam/xact.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 9aa63c8792..245735420c 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -1884,14 +1884,19 @@ StartTransaction(void)
 	TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
 
 	/*
-	 * set transaction_timestamp() (a/k/a now()).  We want this to be the same
-	 * as the first command's statement_timestamp(), so don't do a fresh
-	 * GetCurrentTimestamp() call (which'd be expensive anyway).  Also, mark
-	 * xactStopTimestamp as unset.
-	 */
-	xactStartTimestamp = stmtStartTimestamp;
-	xactStopTimestamp = 0;
+	 * set transaction_timestamp() (a/k/a now()).  Normally, we want this to
+	 * be the same as the first command's statement_timestamp(), so don't do a
+	 * fresh GetCurrentTimestamp() call (which'd be expensive anyway).  But
+	 * for transactions started inside statements (e.g., procedure calls), we
+	 * want to advance the timestamp.
+	 */
+	if (xactStartTimestamp < stmtStartTimestamp)
+		xactStartTimestamp = stmtStartTimestamp;
+	else
+		xactStartTimestamp = GetCurrentTimestamp();
 	pgstat_report_xact_timestamp(xactStartTimestamp);
+	/* Mark xactStopTimestamp as unset. */
+	xactStopTimestamp = 0;
 
 	/*
 	 * initialize current transaction state fields
-- 
2.19.0