1 /*-------------------------------------------------------------------------
4 * POSTGRES snapshot definition
6 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/utils/snapshot.h
11 *-------------------------------------------------------------------------
16 #include "access/htup.h"
17 #include "storage/buf.h"
20 typedef struct SnapshotData *Snapshot;
22 #define InvalidSnapshot ((Snapshot) NULL)
25 * We use SnapshotData structures to represent both "regular" (MVCC)
26 * snapshots and "special" snapshots that have non-MVCC semantics.
27 * The specific semantics of a snapshot are encoded by the "satisfies"
30 typedef bool (*SnapshotSatisfiesFunc) (HeapTuple htup,
31 Snapshot snapshot, Buffer buffer);
34 * Struct representing all kind of possible snapshots.
36 * There are several different kinds of snapshots:
37 * * Normal MVCC snapshots
38 * * MVCC snapshots taken during recovery (in Hot-Standby mode)
39 * * Historic MVCC snapshots used during logical decoding
40 * * snapshots passed to HeapTupleSatisfiesDirty()
41 * * snapshots used for SatisfiesAny, Toast, Self where no members are
44 * TODO: It's probably a good idea to split this struct using a NodeTag
45 * similar to how parser and executor nodes are handled, with one type for
46 * each different kind of snapshot to avoid overloading the meaning of
49 typedef struct SnapshotData
51 SnapshotSatisfiesFunc satisfies; /* tuple test function */
54 * The remaining fields are used only for MVCC snapshots, and are normally
55 * just zeroes in special snapshots. (But xmin and xmax are used
56 * specially by HeapTupleSatisfiesDirty.)
58 * An MVCC snapshot can never see the effects of XIDs >= xmax. It can see
59 * the effects of all older XIDs except those listed in the snapshot. xmin
60 * is stored as an optimization to avoid needing to search the XID arrays
63 TransactionId xmin; /* all XID < xmin are visible to me */
64 TransactionId xmax; /* all XID >= xmax are invisible to me */
67 * For normal MVCC snapshot this contains the all xact IDs that are in
68 * progress, unless the snapshot was taken during recovery in which case
69 * it's empty. For historic MVCC snapshots, the meaning is inverted, i.e.
70 * it contains *committed* transactions between xmin and xmax.
73 uint32 xcnt; /* # of xact ids in xip[] */
74 /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */
75 int32 subxcnt; /* # of xact ids in subxip[] */
78 * For non-historic MVCC snapshots, this contains subxact IDs that are in
79 * progress (and other transactions that are in progress if taken during
80 * recovery). For historic snapshot it contains *all* xids assigned to the
81 * replayed transaction, including the toplevel xid.
83 TransactionId *subxip;
84 bool suboverflowed; /* has the subxip array overflowed? */
85 bool takenDuringRecovery; /* recovery-shaped snapshot? */
86 bool copied; /* false if it's a static snapshot */
89 * note: all ids in subxip[] are >= xmin, but we don't bother filtering
90 * out any that are >= xmax
92 CommandId curcid; /* in my xact, CID < curcid are visible */
93 uint32 active_count; /* refcount on ActiveSnapshot stack */
94 uint32 regd_count; /* refcount on RegisteredSnapshotList */
98 * Result codes for HeapTupleSatisfiesUpdate. This should really be in
99 * tqual.h, but we want to avoid including that file elsewhere.
103 HeapTupleMayBeUpdated,
105 HeapTupleSelfUpdated,
107 HeapTupleBeingUpdated
110 #endif /* SNAPSHOT_H */