8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.73 2004/09/06 23:33:35 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.74 2004/09/16 18:35:21 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -521,7 +521,8 @@ TransactionIdIsInProgress(TransactionId xid)
521
521
bool locked ;
522
522
523
523
/*
524
- * Don't bother checking a very old transaction.
524
+ * Don't bother checking a transaction older than RecentXmin; it
525
+ * could not possibly still be running.
525
526
*/
526
527
if (TransactionIdPrecedes (xid , RecentXmin ))
527
528
{
@@ -732,10 +733,19 @@ GetOldestXmin(bool allDbs)
732
733
* This ensures that the set of transactions seen as "running" by the
733
734
* current xact will not change after it takes the snapshot.
734
735
*
735
- * We also compute the current global xmin (oldest xmin across all running
736
- * transactions) and save it in RecentGlobalXmin. This is the same
737
- * computation done by GetOldestXmin(TRUE). The xmin value is also stored
738
- * into RecentXmin.
736
+ * Note that only top-level XIDs are included in the snapshot. We can
737
+ * still apply the xmin and xmax limits to subtransaction XIDs, but we
738
+ * need to work a bit harder to see if XIDs in [xmin..xmax) are running.
739
+ *
740
+ * We also update the following backend-global variables:
741
+ * TransactionXmin: the oldest xmin of any snapshot in use in the
742
+ * current transaction (this is the same as MyProc->xmin). This
743
+ * is just the xmin computed for the first, serializable snapshot.
744
+ * RecentXmin: the xmin computed for the most recent snapshot. XIDs
745
+ * older than this are known not running any more.
746
+ * RecentGlobalXmin: the global xmin (oldest TransactionXmin across all
747
+ * running transactions). This is the same computation done by
748
+ * GetOldestXmin(TRUE).
739
749
*----------
740
750
*/
741
751
Snapshot
@@ -751,6 +761,11 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
751
761
752
762
Assert (snapshot != NULL );
753
763
764
+ /* Serializable snapshot must be computed before any other... */
765
+ Assert (serializable ?
766
+ !TransactionIdIsValid (MyProc -> xmin ) :
767
+ TransactionIdIsValid (MyProc -> xmin ));
768
+
754
769
/*
755
770
* Allocating space for MaxBackends xids is usually overkill;
756
771
* lastBackend would be sufficient. But it seems better to do the
@@ -850,13 +865,10 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
850
865
}
851
866
852
867
if (serializable )
853
- MyProc -> xmin = xmin ;
868
+ MyProc -> xmin = TransactionXmin = xmin ;
854
869
855
870
LWLockRelease (SInvalLock );
856
871
857
- /* Serializable snapshot must be computed before any other... */
858
- Assert (TransactionIdIsValid (MyProc -> xmin ));
859
-
860
872
/*
861
873
* Update globalxmin to include actual process xids. This is a
862
874
* slightly different way of computing it than GetOldestXmin uses, but
@@ -865,7 +877,7 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
865
877
if (TransactionIdPrecedes (xmin , globalxmin ))
866
878
globalxmin = xmin ;
867
879
868
- /* Update globals for use by VACUUM */
880
+ /* Update global variables too */
869
881
RecentGlobalXmin = globalxmin ;
870
882
RecentXmin = xmin ;
871
883
0 commit comments