summaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xact.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-10-08 16:16:36 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-10-08 16:16:36 -0400
commit1145c26b749a73419d32e4c997237e84fbbffa04 (patch)
treecff5a82aff50d6c3fb042ae7743f0b29b3e03f61 /src/backend/access/transam/xact.c
parent8569ef63f4d30d25f950270f62ca7263b56157a3 (diff)
Advance transaction timestamp for intra-procedure transactions.
Per discussion, this behavior seems less astonishing than not doing so. Peter Eisentraut and Tom Lane Discussion: https://postgr.es/m/20180920234040.GC29981@momjian.us
Diffstat (limited to 'src/backend/access/transam/xact.c')
-rw-r--r--src/backend/access/transam/xact.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 88bf1f435ab..09e7e7f9a46 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -1906,20 +1906,26 @@ 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). In a
- * parallel worker, this should already have been provided by a call to
+ * 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 procedures (i.e., nonatomic SPI
+ * contexts), we do need to advance the timestamp. Also, in a parallel
+ * worker, the timestamp should already have been provided by a call to
* SetParallelStartTimestamps().
- *
- * Also, mark xactStopTimestamp as unset.
*/
if (!IsParallelWorker())
- xactStartTimestamp = stmtStartTimestamp;
+ {
+ if (!SPI_inside_nonatomic_context())
+ xactStartTimestamp = stmtStartTimestamp;
+ else
+ xactStartTimestamp = GetCurrentTimestamp();
+ }
else
Assert(xactStartTimestamp != 0);
- xactStopTimestamp = 0;
pgstat_report_xact_timestamp(xactStartTimestamp);
+ /* Mark xactStopTimestamp as unset. */
+ xactStopTimestamp = 0;
/*
* initialize current transaction state fields