aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/time/snapmgr.c
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2017-03-24 14:20:59 +0000
committerSimon Riggs <simon@2ndQuadrant.com>2017-03-24 14:20:59 +0000
commit42b4b0b2413b9b472aaf2112a3bbfd80a6ab4dc5 (patch)
tree3e40c73b0fcbc2faac1d468e21001514572bd3b1 /src/backend/utils/time/snapmgr.c
parent8398c836892fde2b99139cc4711e57b7e59582b6 (diff)
downloadpostgresql-42b4b0b2413b9b472aaf2112a3bbfd80a6ab4dc5.tar.gz
postgresql-42b4b0b2413b9b472aaf2112a3bbfd80a6ab4dc5.zip
Avoid SnapshotResetXmin() during AtEOXact_Snapshot()
For normal commits and aborts we already reset PgXact->xmin Avoiding touching highly contented shmem improves concurrent performance. Simon Riggs Discussion: CANP8+jJdXE9b+b9F8CQT-LuxxO0PBCB-SZFfMVAdp+akqo4zfg@mail.gmail.com
Diffstat (limited to 'src/backend/utils/time/snapmgr.c')
-rw-r--r--src/backend/utils/time/snapmgr.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c
index ecc32cb3fe7..67f3e2d667d 100644
--- a/src/backend/utils/time/snapmgr.c
+++ b/src/backend/utils/time/snapmgr.c
@@ -954,7 +954,12 @@ xmin_cmp(const pairingheap_node *a, const pairingheap_node *b, void *arg)
*
* If there are no more snapshots, we can reset our PGXACT->xmin to InvalidXid.
* Note we can do this without locking because we assume that storing an Xid
- * is atomic.
+ * is atomic. We do this because it will allow multi-statement transactions to
+ * reset their xmin and prevent us from holding back removal of dead rows;
+ * this has little purpose when we are dealing with very fast statements in
+ * read committed mode since the xmin will advance quickly anyway. It has no
+ * use at all when we are running single statement transactions since the xmin
+ * is reset as part of end of transaction anyway.
*
* Even if there are some remaining snapshots, we may be able to advance our
* PGXACT->xmin to some degree. This typically happens when a portal is
@@ -1051,7 +1056,7 @@ AtSubAbort_Snapshot(int level)
* Snapshot manager's cleanup function for end of transaction
*/
void
-AtEOXact_Snapshot(bool isCommit)
+AtEOXact_Snapshot(bool isCommit, bool isPrepare)
{
/*
* In transaction-snapshot mode we must release our privately-managed
@@ -1136,7 +1141,17 @@ AtEOXact_Snapshot(bool isCommit)
FirstSnapshotSet = false;
- SnapshotResetXmin();
+ /*
+ * During normal commit and abort processing, we call
+ * ProcArrayEndTransaction() or ProcArrayClearTransaction() to
+ * reset the PgXact->xmin. That call happens prior to the call to
+ * AtEOXact_Snapshot(), so we need not touch xmin here at all,
+ * accept when we are preparing a transaction.
+ */
+ if (isPrepare)
+ SnapshotResetXmin();
+
+ Assert(MyPgXact->xmin == 0);
}