From a54d84a3ce30266693da1010fa281a4e174f0343 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 2 Nov 2016 18:44:29 +0200 Subject: [PATCH] Avoid assigning an XID to DTX_CONTEXT_QE_AUTO_COMMIT_IMPLICIT queries. This avoids a lot of overhead for short read-only queries. We still don't do lazy assignment for most transactions, like PostgreSQL 8.3 does, but this is a step in the right direction. --- src/backend/access/transam/xact.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index ab2dc60788..f892faf96b 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2984,6 +2984,7 @@ StartTransaction(void) QEDtxContextInfo.distributedTimeStamp, QEDtxContextInfo.distributedXid, &s->transactionId); + XactLockTableInsert(s->transactionId); s->distribXid = QEDtxContextInfo.distributedXid; @@ -2996,15 +2997,13 @@ StartTransaction(void) /* * We don't use the distributed xid map since this may be one of funny * distributed queries the executor uses behind the scenes for estimation - * work. This transaction will auto-commit, and then we will follow it with the - * real user command. - * - * Generate a new transaction id. + * work. We also don't need a local XID right now - we let it be assigned + * lazily, as on a local transaction. This transaction will auto-commit, and + * then we will follow it with the real user command. */ Assert(DistributedTransactionContext == DTX_CONTEXT_QE_AUTO_COMMIT_IMPLICIT); - s->transactionId = GetNewTransactionId(false, true); } - + /* * now() and statement_timestamp() should be the same time */ @@ -3034,7 +3033,7 @@ StartTransaction(void) * * Generate a new transaction id */ - s->transactionId = GetNewTransactionId(false, true); + AssignTransactionId(s); elog((Debug_print_full_dtm ? LOG : DEBUG5), "Not tied to distributed transaction id, but still coordinated " @@ -3042,11 +3041,6 @@ StartTransaction(void) s->transactionId); } - /* - * Common. - */ - XactLockTableInsert(s->transactionId); - PG_TRACE1(transaction__start, s->transactionId); } -- GitLab