diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/access/transam/parallel.c | 11 | ||||
-rw-r--r-- | src/backend/access/transam/xact.c | 36 | ||||
-rw-r--r-- | src/include/access/xact.h | 1 | ||||
-rw-r--r-- | src/include/catalog/catversion.h | 2 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.dat | 12 |
5 files changed, 52 insertions, 10 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index cdaa32e29a4..911da776e80 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -87,6 +87,8 @@ typedef struct FixedParallelState PGPROC *parallel_master_pgproc; pid_t parallel_master_pid; BackendId parallel_master_backend_id; + TimestampTz xact_ts; + TimestampTz stmt_ts; /* Mutex protects remaining fields. */ slock_t mutex; @@ -318,6 +320,8 @@ InitializeParallelDSM(ParallelContext *pcxt) fps->parallel_master_pgproc = MyProc; fps->parallel_master_pid = MyProcPid; fps->parallel_master_backend_id = MyBackendId; + fps->xact_ts = GetCurrentTransactionStartTimestamp(); + fps->stmt_ts = GetCurrentStatementStartTimestamp(); SpinLockInit(&fps->mutex); fps->last_xlog_end = 0; shm_toc_insert(pcxt->toc, PARALLEL_KEY_FIXED, fps); @@ -1312,6 +1316,13 @@ ParallelWorkerMain(Datum main_arg) return; /* + * Restore transaction and statement start-time timestamps. This must + * happen before anything that would start a transaction, else asserts in + * xact.c will fire. + */ + SetParallelStartTimestamps(fps->xact_ts, fps->stmt_ts); + + /* * Identify the entry point to be called. In theory this could result in * loading an additional library, though most likely the entry point is in * the core backend or in a library we just loaded. diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 875be180fe4..e3f668bf6ab 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -675,6 +675,22 @@ GetCurrentCommandId(bool used) } /* + * SetParallelStartTimestamps + * + * In a parallel worker, we should inherit the parent transaction's + * timestamps rather than setting our own. The parallel worker + * infrastructure must call this to provide those values before + * calling StartTransaction() or SetCurrentStatementStartTimestamp(). + */ +void +SetParallelStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts) +{ + Assert(IsParallelWorker()); + xactStartTimestamp = xact_ts; + stmtStartTimestamp = stmt_ts; +} + +/* * GetCurrentTransactionStartTimestamp */ TimestampTz @@ -708,11 +724,17 @@ GetCurrentTransactionStopTimestamp(void) /* * SetCurrentStatementStartTimestamp + * + * In a parallel worker, this should already have been provided by a call + * to SetParallelStartTimestamps(). */ void SetCurrentStatementStartTimestamp(void) { - stmtStartTimestamp = GetCurrentTimestamp(); + if (!IsParallelWorker()) + stmtStartTimestamp = GetCurrentTimestamp(); + else + Assert(stmtStartTimestamp != 0); } /* @@ -1867,10 +1889,16 @@ StartTransaction(void) /* * 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. + * GetCurrentTimestamp() call (which'd be expensive anyway). In a + * parallel worker, this should already have been provided by a call to + * SetParallelStartTimestamps(). + * + * Also, mark xactStopTimestamp as unset. */ - xactStartTimestamp = stmtStartTimestamp; + if (!IsParallelWorker()) + xactStartTimestamp = stmtStartTimestamp; + else + Assert(xactStartTimestamp != 0); xactStopTimestamp = 0; pgstat_report_xact_timestamp(xactStartTimestamp); diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 083e879d5c3..689c57c5926 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -359,6 +359,7 @@ extern SubTransactionId GetCurrentSubTransactionId(void); extern void MarkCurrentTransactionIdLoggedIfAny(void); extern bool SubTransactionIsActive(SubTransactionId subxid); extern CommandId GetCurrentCommandId(bool used); +extern void SetParallelStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts); extern TimestampTz GetCurrentTransactionStartTimestamp(void); extern TimestampTz GetCurrentStatementStartTimestamp(void); extern TimestampTz GetCurrentTransactionStopTimestamp(void); diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 89e2b609165..1e38656fa7c 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201810051 +#define CATALOG_VERSION_NO 201810061 #endif diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 8579822bcd2..963ff6848a9 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -2073,7 +2073,8 @@ { oid => '1365', descr => 'make ACL item', proname => 'makeaclitem', prorettype => 'aclitem', proargtypes => 'oid oid text bool', prosrc => 'makeaclitem' }, -{ oid => '3943', descr => 'show hardwired default privileges, primarily for use by the information schema', +{ oid => '3943', + descr => 'show hardwired default privileges, primarily for use by the information schema', proname => 'acldefault', prorettype => '_aclitem', proargtypes => 'char oid', prosrc => 'acldefault_sql' }, { oid => '1689', @@ -2595,13 +2596,13 @@ proname => 'timetzdate_pl', prolang => '14', prorettype => 'timestamptz', proargtypes => 'timetz date', prosrc => 'select ($2 + $1)' }, { oid => '1299', descr => 'current transaction time', - proname => 'now', provolatile => 's', proparallel => 'r', - prorettype => 'timestamptz', proargtypes => '', prosrc => 'now' }, + proname => 'now', provolatile => 's', prorettype => 'timestamptz', + proargtypes => '', prosrc => 'now' }, { oid => '2647', descr => 'current transaction time', proname => 'transaction_timestamp', provolatile => 's', prorettype => 'timestamptz', proargtypes => '', prosrc => 'now' }, { oid => '2648', descr => 'current statement time', - proname => 'statement_timestamp', provolatile => 's', proparallel => 'r', + proname => 'statement_timestamp', provolatile => 's', prorettype => 'timestamptz', proargtypes => '', prosrc => 'statement_timestamp' }, { oid => '2649', descr => 'current clock time', @@ -10208,7 +10209,8 @@ proname => 'pg_ls_tmpdir', procost => '10', prorows => '20', proretset => 't', provolatile => 'v', prorettype => 'record', proargtypes => 'oid', proallargtypes => '{oid,text,int8,timestamptz}', proargmodes => '{i,o,o,o}', - proargnames => '{tablespace,name,size,modification}', prosrc => 'pg_ls_tmpdir_1arg' }, + proargnames => '{tablespace,name,size,modification}', + prosrc => 'pg_ls_tmpdir_1arg' }, # hash partitioning constraint function { oid => '5028', descr => 'hash partition CHECK constraint', |