index c976f947a02edb19b9a2ba2caa00c83fc05f4269..1c7466c81583317a72112d38330bcc23a7280054 100644 (file)
#include "storage/lmgr.h"
#include "utils/memutils.h"
#include "utils/snapmgr.h"
-#include "utils/tqual.h"
PG_MODULE_MAGIC;
index b2419f0d81123b76d3f444ed5aad9ca99e238fa8..0cffb69c76be42c5bccd9cd1fcece4cac0f1e03c 100644 (file)
#include "commands/seclabel.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
-#include "utils/tqual.h"
+#include "utils/snapmgr.h"
#include "sepgsql.h"
/*
index a4038dfd1b828482b174fda4485a516770d80434..aa12dbe2367836414e334043ec67ad5d0374df67 100644 (file)
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
+#include "utils/snapmgr.h"
#include "utils/syscache.h"
-#include "utils/tqual.h"
#include "sepgsql.h"
index 6842d2a42b764f7379876b6adcf41c1e206c9cec..061527559c1ffcd9f329ec5f4f05e76764cc4ef5 100644 (file)
#include "utils/catcache.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
+#include "utils/snapmgr.h"
#include "utils/syscache.h"
-#include "utils/tqual.h"
#include "sepgsql.h"
index 668d65e70f543c1b622593653b385ebd3c597866..4c4a90f9781eed36fa0d9fc3af1d85bdc1e2626b 100644 (file)
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
-#include "utils/tqual.h"
+#include "utils/snapmgr.h"
#include "sepgsql.h"
index a3e22dd51c321d585117a9350866ba407a82d363..dc398e11867d172d3fcc6ec4cff175f1c34885be 100644 (file)
#include "utils/rel.h"
#include "utils/sortsupport.h"
#include "utils/tuplesort.h"
-#include "utils/tqual.h"
/* Magic numbers for parallel state sharing */
index a9d2621a7eed553974877bfd639036265508ac77..c39da41d2ecbc7d2d5c51c998e53de9ec0dc27aa 100644 (file)
#include "utils/fmgroids.h"
#include "utils/fmgrprotos.h"
#include "utils/rel.h"
+#include "utils/snapmgr.h"
#include "utils/syscache.h"
-#include "utils/tqual.h"
/*
index 45ebe0ad63c98f6b540837b8dadb0c9a415aed5a..0099b8813780cfeee218d02f5cff61a754f78452 100644 (file)
#include "utils/ps_status.h"
#include "utils/snapmgr.h"
#include "utils/timestamp.h"
-#include "utils/tqual.h"
/*
index 66914007ecf9c78d23544af969183386b43595f2..f9ada29af8410eec3a67c59a9077bd3131db96fd 100644 (file)
#include "executor/executor.h"
#include "utils/builtins.h"
#include "utils/rel.h"
-#include "utils/tqual.h"
+#include "utils/snapmgr.h"
/*
index 92ca129858c8ca569462ad1069471499a0dfcb64..fd0520105dc27619e557feecedeba9298c064007 100644 (file)
#include "executor/executor.h"
#include "nodes/nodeFuncs.h"
#include "storage/lmgr.h"
-#include "utils/tqual.h"
+#include "utils/snapmgr.h"
/* waitMode argument to check_exclusion_or_unique_constraint() */
typedef enum
index 7a102a7ad38ace84f86aa760fb7dda492304d9a9..dad2b3d065a02433446dc29073fa0dbe80cb7838 100644 (file)
#include "utils/pg_lsn.h"
#include "utils/rel.h"
#include "utils/syscache.h"
-#include "utils/tqual.h"
+#include "utils/snapmgr.h"
/*
* Replay progress of a single remote node.
index 3e48beaa22f4bc97fc498e9e3bf07c7e5e431fa4..2310e9fafe0a083bfd4a8d4edba63758457db7e7 100644 (file)
#include "utils/memutils.h"
#include "utils/snapshot.h"
#include "utils/snapmgr.h"
-#include "utils/tqual.h"
#include "storage/block.h" /* debugging output */
#include "storage/fd.h"
index bdb7d70827932edbd5ab7386ba3e295f4c504947..dcb35d897520d696c52c40d1c4e273f77d2fa379 100644 (file)
#include "utils/spccache.h"
#include "utils/syscache.h"
#include "utils/timestamp.h"
-#include "utils/tqual.h"
#include "utils/typcache.h"
#include "utils/varlena.h"
index d47d2b3ef7a1d46592700edfba6d446f754400ee..6e02585e10e50f7ae53d0744ff8f88bc9d6fa6a5 100644 (file)
#include <sys/stat.h>
#include <unistd.h>
+#include "access/subtrans.h"
#include "access/transam.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "utils/resowner_private.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
-#include "utils/tqual.h"
/*
@@ -144,6 +144,8 @@ static volatile OldSnapshotControlData *oldSnapshotControl;
static SnapshotData CurrentSnapshotData = {SNAPSHOT_MVCC};
static SnapshotData SecondarySnapshotData = {SNAPSHOT_MVCC};
SnapshotData CatalogSnapshotData = {SNAPSHOT_MVCC};
+SnapshotData SnapshotSelfData = {SNAPSHOT_SELF};
+SnapshotData SnapshotAnyData = {SNAPSHOT_ANY};
/* Pointers to valid snapshots */
static Snapshot CurrentSnapshot = NULL;
@@ -2192,3 +2194,125 @@ RestoreTransactionSnapshot(Snapshot snapshot, void *master_pgproc)
{
SetTransactionSnapshot(snapshot, NULL, InvalidPid, master_pgproc);
}
+
+/*
+ * XidInMVCCSnapshot
+ * Is the given XID still-in-progress according to the snapshot?
+ *
+ * Note: GetSnapshotData never stores either top xid or subxids of our own
+ * backend into a snapshot, so these xids will not be reported as "running"
+ * by this function. This is OK for current uses, because we always check
+ * TransactionIdIsCurrentTransactionId first, except when it's known the
+ * XID could not be ours anyway.
+ */
+bool
+XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
+{
+ uint32 i;
+
+ /*
+ * Make a quick range check to eliminate most XIDs without looking at the
+ * xip arrays. Note that this is OK even if we convert a subxact XID to
+ * its parent below, because a subxact with XID < xmin has surely also got
+ * a parent with XID < xmin, while one with XID >= xmax must belong to a
+ * parent that was not yet committed at the time of this snapshot.
+ */
+
+ /* Any xid < xmin is not in-progress */
+ if (TransactionIdPrecedes(xid, snapshot->xmin))
+ return false;
+ /* Any xid >= xmax is in-progress */
+ if (TransactionIdFollowsOrEquals(xid, snapshot->xmax))
+ return true;
+
+ /*
+ * Snapshot information is stored slightly differently in snapshots taken
+ * during recovery.
+ */
+ if (!snapshot->takenDuringRecovery)
+ {
+ /*
+ * If the snapshot contains full subxact data, the fastest way to
+ * check things is just to compare the given XID against both subxact
+ * XIDs and top-level XIDs. If the snapshot overflowed, we have to
+ * use pg_subtrans to convert a subxact XID to its parent XID, but
+ * then we need only look at top-level XIDs not subxacts.
+ */
+ if (!snapshot->suboverflowed)
+ {
+ /* we have full data, so search subxip */
+ int32 j;
+
+ for (j = 0; j < snapshot->subxcnt; j++)
+ {
+ if (TransactionIdEquals(xid, snapshot->subxip[j]))
+ return true;
+ }
+
+ /* not there, fall through to search xip[] */
+ }
+ else
+ {
+ /*
+ * Snapshot overflowed, so convert xid to top-level. This is safe
+ * because we eliminated too-old XIDs above.
+ */
+ xid = SubTransGetTopmostTransaction(xid);
+
+ /*
+ * If xid was indeed a subxact, we might now have an xid < xmin,
+ * so recheck to avoid an array scan. No point in rechecking
+ * xmax.
+ */
+ if (TransactionIdPrecedes(xid, snapshot->xmin))
+ return false;
+ }
+
+ for (i = 0; i < snapshot->xcnt; i++)
+ {
+ if (TransactionIdEquals(xid, snapshot->xip[i]))
+ return true;
+ }
+ }
+ else
+ {
+ int32 j;
+
+ /*
+ * In recovery we store all xids in the subxact array because it is by
+ * far the bigger array, and we mostly don't know which xids are
+ * top-level and which are subxacts. The xip array is empty.
+ *
+ * We start by searching subtrans, if we overflowed.
+ */
+ if (snapshot->suboverflowed)
+ {
+ /*
+ * Snapshot overflowed, so convert xid to top-level. This is safe
+ * because we eliminated too-old XIDs above.
+ */
+ xid = SubTransGetTopmostTransaction(xid);
+
+ /*
+ * If xid was indeed a subxact, we might now have an xid < xmin,
+ * so recheck to avoid an array scan. No point in rechecking
+ * xmax.
+ */
+ if (TransactionIdPrecedes(xid, snapshot->xmin))
+ return false;
+ }
+
+ /*
+ * We now have either a top-level xid higher than xmin or an
+ * indeterminate xid. We don't know whether it's top level or subxact
+ * but it doesn't matter. If it's present, the xid is visible.
+ */
+ for (j = 0; j < snapshot->subxcnt; j++)
+ {
+ if (TransactionIdEquals(xid, snapshot->subxip[j]))
+ return true;
+ }
+ }
+
+ return false;
+}
index 3a44ccae3c98bbf0cea44d91a468fe31bfb9e33a..71d7e257773592a8f4f1fd7af2c9002bfebd64d5 100644 (file)
#include "utils/tqual.h"
-/* Static variables representing various special snapshot semantics */
-SnapshotData SnapshotSelfData = {SNAPSHOT_SELF};
-SnapshotData SnapshotAnyData = {SNAPSHOT_ANY};
-
-
/*
* SetHintBits()
*
@@ -1452,128 +1447,6 @@ HeapTupleIsSurelyDead(HeapTuple htup, TransactionId OldestXmin)
return TransactionIdPrecedes(HeapTupleHeaderGetRawXmax(tuple), OldestXmin);
}
-/*
- * XidInMVCCSnapshot
- * Is the given XID still-in-progress according to the snapshot?
- *
- * Note: GetSnapshotData never stores either top xid or subxids of our own
- * backend into a snapshot, so these xids will not be reported as "running"
- * by this function. This is OK for current uses, because we always check
- * TransactionIdIsCurrentTransactionId first, except when it's known the
- * XID could not be ours anyway.
- */
-bool
-XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
-{
- uint32 i;
-
- /*
- * Make a quick range check to eliminate most XIDs without looking at the
- * xip arrays. Note that this is OK even if we convert a subxact XID to
- * its parent below, because a subxact with XID < xmin has surely also got
- * a parent with XID < xmin, while one with XID >= xmax must belong to a
- * parent that was not yet committed at the time of this snapshot.
- */
-
- /* Any xid < xmin is not in-progress */
- if (TransactionIdPrecedes(xid, snapshot->xmin))
- return false;
- /* Any xid >= xmax is in-progress */
- if (TransactionIdFollowsOrEquals(xid, snapshot->xmax))
- return true;
-
- /*
- * Snapshot information is stored slightly differently in snapshots taken
- * during recovery.
- */
- if (!snapshot->takenDuringRecovery)
- {
- /*
- * If the snapshot contains full subxact data, the fastest way to
- * check things is just to compare the given XID against both subxact
- * XIDs and top-level XIDs. If the snapshot overflowed, we have to
- * use pg_subtrans to convert a subxact XID to its parent XID, but
- * then we need only look at top-level XIDs not subxacts.
- */
- if (!snapshot->suboverflowed)
- {
- /* we have full data, so search subxip */
- int32 j;
-
- for (j = 0; j < snapshot->subxcnt; j++)
- {
- if (TransactionIdEquals(xid, snapshot->subxip[j]))
- return true;
- }
-
- /* not there, fall through to search xip[] */
- }
- else
- {
- /*
- * Snapshot overflowed, so convert xid to top-level. This is safe
- * because we eliminated too-old XIDs above.
- */
- xid = SubTransGetTopmostTransaction(xid);
-
- /*
- * If xid was indeed a subxact, we might now have an xid < xmin,
- * so recheck to avoid an array scan. No point in rechecking
- * xmax.
- */
- if (TransactionIdPrecedes(xid, snapshot->xmin))
- return false;
- }
-
- for (i = 0; i < snapshot->xcnt; i++)
- {
- if (TransactionIdEquals(xid, snapshot->xip[i]))
- return true;
- }
- }
- else
- {
- int32 j;
-
- /*
- * In recovery we store all xids in the subxact array because it is by
- * far the bigger array, and we mostly don't know which xids are
- * top-level and which are subxacts. The xip array is empty.
- *
- * We start by searching subtrans, if we overflowed.
- */
- if (snapshot->suboverflowed)
- {
- /*
- * Snapshot overflowed, so convert xid to top-level. This is safe
- * because we eliminated too-old XIDs above.
- */
- xid = SubTransGetTopmostTransaction(xid);
-
- /*
- * If xid was indeed a subxact, we might now have an xid < xmin,
- * so recheck to avoid an array scan. No point in rechecking
- * xmax.
- */
- if (TransactionIdPrecedes(xid, snapshot->xmin))
- return false;
- }
-
- /*
- * We now have either a top-level xid higher than xmin or an
- * indeterminate xid. We don't know whether it's top level or subxact
- * but it doesn't matter. If it's present, the xid is visible.
- */
- for (j = 0; j < snapshot->subxcnt; j++)
- {
- if (TransactionIdEquals(xid, snapshot->subxip[j]))
- return true;
- }
- }
-
- return false;
-}
-
/*
* Is the tuple really only locked? That is, is it not updated?
*
index f8308e69259226aad5e392d1b02b7f68c8b6d2e6..c49aceadfb12191dd92f2f6eb98261dc865a2b7a 100644 (file)
@@ -61,6 +61,45 @@ extern PGDLLIMPORT TransactionId RecentXmin;
extern PGDLLIMPORT TransactionId RecentGlobalXmin;
extern PGDLLIMPORT TransactionId RecentGlobalDataXmin;
+/* Variables representing various special snapshot semantics */
+extern PGDLLIMPORT SnapshotData SnapshotSelfData;
+extern PGDLLIMPORT SnapshotData SnapshotAnyData;
+extern PGDLLIMPORT SnapshotData CatalogSnapshotData;
+
+#define SnapshotSelf (&SnapshotSelfData)
+#define SnapshotAny (&SnapshotAnyData)
+
+/*
+ * We don't provide a static SnapshotDirty variable because it would be
+ * non-reentrant. Instead, users of that snapshot type should declare a
+ * local variable of type SnapshotData, and initialize it with this macro.
+ */
+#define InitDirtySnapshot(snapshotdata) \
+ ((snapshotdata).snapshot_type = SNAPSHOT_DIRTY)
+
+/*
+ * Similarly, some initialization is required for a NonVacuumable snapshot.
+ * The caller must supply the xmin horizon to use (e.g., RecentGlobalXmin).
+ */
+#define InitNonVacuumableSnapshot(snapshotdata, xmin_horizon) \
+ ((snapshotdata).snapshot_type = SNAPSHOT_NON_VACUUMABLE, \
+ (snapshotdata).xmin = (xmin_horizon))
+
+/*
+ * Similarly, some initialization is required for SnapshotToast. We need
+ * to set lsn and whenTaken correctly to support snapshot_too_old.
+ */
+#define InitToastSnapshot(snapshotdata, l, w) \
+ ((snapshotdata).snapshot_type = SNAPSHOT_TOAST, \
+ (snapshotdata).lsn = (l), \
+ (snapshotdata).whenTaken = (w))
+
+/* This macro encodes the knowledge of which snapshots are MVCC-safe */
+#define IsMVCCSnapshot(snapshot) \
+ ((snapshot)->snapshot_type == SNAPSHOT_MVCC || \
+ (snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC)
+
+
extern Snapshot GetTransactionSnapshot(void);
extern Snapshot GetLatestSnapshot(void);
extern void SnapshotSetCommandId(CommandId curcid);
@@ -98,6 +137,11 @@ extern void MaintainOldSnapshotTimeMapping(TimestampTz whenTaken,
extern char *ExportSnapshot(Snapshot snapshot);
+/*
+ * Utility functions for implementing visibility routines in table AMs.
+ */
+extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
+
/* Support for catalog timetravel for logical decoding */
struct HTAB;
extern struct HTAB *HistoricSnapshotGetTupleCids(void);
index 049a723a69ac8e1a44bc196e0f2349144e014bcc..de8c799ea5e155831d000fd334f8ccb7b7492e73 100644 (file)
#include "utils/snapshot.h"
-
-/* Static variables representing various special snapshot semantics */
-extern PGDLLIMPORT SnapshotData SnapshotSelfData;
-extern PGDLLIMPORT SnapshotData SnapshotAnyData;
-extern PGDLLIMPORT SnapshotData CatalogSnapshotData;
-
-#define SnapshotSelf (&SnapshotSelfData)
-#define SnapshotAny (&SnapshotAnyData)
-
-/* This macro encodes the knowledge of which snapshots are MVCC-safe */
-#define IsMVCCSnapshot(snapshot) \
- ((snapshot)->snapshot_type == SNAPSHOT_MVCC || \
- (snapshot)->snapshot_type == SNAPSHOT_HISTORIC_MVCC)
-
extern bool HeapTupleSatisfiesVisibility(HeapTuple stup, Snapshot snapshot,
Buffer buffer);
@@ -51,7 +37,6 @@ extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup,
TransactionId OldestXmin, Buffer buffer);
extern bool HeapTupleIsSurelyDead(HeapTuple htup,
TransactionId OldestXmin);
-extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
uint16 infomask, TransactionId xid);
@@ -68,29 +53,4 @@ extern bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data,
Buffer buffer,
CommandId *cmin, CommandId *cmax);
-/*
- * We don't provide a static SnapshotDirty variable because it would be
- * non-reentrant. Instead, users of that snapshot type should declare a
- * local variable of type SnapshotData, and initialize it with this macro.
- */
-#define InitDirtySnapshot(snapshotdata) \
- ((snapshotdata).snapshot_type = SNAPSHOT_DIRTY)
-
-/*
- * Similarly, some initialization is required for a NonVacuumable snapshot.
- * The caller must supply the xmin horizon to use (e.g., RecentGlobalXmin).
- */
-#define InitNonVacuumableSnapshot(snapshotdata, xmin_horizon) \
- ((snapshotdata).snapshot_type = SNAPSHOT_NON_VACUUMABLE, \
- (snapshotdata).xmin = (xmin_horizon))
-
-/*
- * Similarly, some initialization is required for SnapshotToast. We need
- * to set lsn and whenTaken correctly to support snapshot_too_old.
- */
-#define InitToastSnapshot(snapshotdata, l, w) \
- ((snapshotdata).snapshot_type = SNAPSHOT_TOAST, \
- (snapshotdata).lsn = (l), \
- (snapshotdata).whenTaken = (w))
-
#endif /* TQUAL_H */