PostgreSQL Source Code  git master
tqual.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * tqual.h
4  * POSTGRES "time qualification" definitions, ie, tuple visibility rules.
5  *
6  * Should be moved/renamed... - vadim 07/28/98
7  *
8  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  * src/include/utils/tqual.h
12  *
13  *-------------------------------------------------------------------------
14  */
15 #ifndef TQUAL_H
16 #define TQUAL_H
17 
18 #include "utils/snapshot.h"
19 #include "access/xlogdefs.h"
20 
21 
22 /* Static variables representing various special snapshot semantics */
26 
27 #define SnapshotSelf (&SnapshotSelfData)
28 #define SnapshotAny (&SnapshotAnyData)
29 
30 /* This macro encodes the knowledge of which snapshots are MVCC-safe */
31 #define IsMVCCSnapshot(snapshot) \
32  ((snapshot)->satisfies == HeapTupleSatisfiesMVCC || \
33  (snapshot)->satisfies == HeapTupleSatisfiesHistoricMVCC)
34 
35 /*
36  * HeapTupleSatisfiesVisibility
37  * True iff heap tuple satisfies a time qual.
38  *
39  * Notes:
40  * Assumes heap tuple is valid.
41  * Beware of multiple evaluations of snapshot argument.
42  * Hint bits in the HeapTuple's t_infomask may be updated as a side effect;
43  * if so, the indicated buffer is marked dirty.
44  */
45 #define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer) \
46  ((*(snapshot)->satisfies) (tuple, snapshot, buffer))
47 
48 /* Result codes for HeapTupleSatisfiesVacuum */
49 typedef enum
50 {
51  HEAPTUPLE_DEAD, /* tuple is dead and deletable */
52  HEAPTUPLE_LIVE, /* tuple is live (committed, no deleter) */
53  HEAPTUPLE_RECENTLY_DEAD, /* tuple is dead, but not deletable yet */
54  HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */
55  HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */
56 } HTSV_Result;
57 
58 /* These are the "satisfies" test routines for the various snapshot types */
59 extern bool HeapTupleSatisfiesMVCC(HeapTuple htup,
60  Snapshot snapshot, Buffer buffer);
61 extern bool HeapTupleSatisfiesSelf(HeapTuple htup,
62  Snapshot snapshot, Buffer buffer);
63 extern bool HeapTupleSatisfiesAny(HeapTuple htup,
64  Snapshot snapshot, Buffer buffer);
65 extern bool HeapTupleSatisfiesToast(HeapTuple htup,
66  Snapshot snapshot, Buffer buffer);
67 extern bool HeapTupleSatisfiesDirty(HeapTuple htup,
68  Snapshot snapshot, Buffer buffer);
70  Snapshot snapshot, Buffer buffer);
72  Snapshot snapshot, Buffer buffer);
73 
74 /* Special "satisfies" routines with different APIs */
76  CommandId curcid, Buffer buffer);
79 extern bool HeapTupleIsSurelyDead(HeapTuple htup,
81 extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
82 
84  uint16 infomask, TransactionId xid);
86 
87 /*
88  * To avoid leaking too much knowledge about reorderbuffer implementation
89  * details this is implemented in reorderbuffer.c not tqual.c.
90  */
91 struct HTAB;
93  Snapshot snapshot,
94  HeapTuple htup,
95  Buffer buffer,
96  CommandId *cmin, CommandId *cmax);
97 
98 /*
99  * We don't provide a static SnapshotDirty variable because it would be
100  * non-reentrant. Instead, users of that snapshot type should declare a
101  * local variable of type SnapshotData, and initialize it with this macro.
102  */
103 #define InitDirtySnapshot(snapshotdata) \
104  ((snapshotdata).satisfies = HeapTupleSatisfiesDirty)
105 
106 /*
107  * Similarly, some initialization is required for a NonVacuumable snapshot.
108  * The caller must supply the xmin horizon to use (e.g., RecentGlobalXmin).
109  */
110 #define InitNonVacuumableSnapshot(snapshotdata, xmin_horizon) \
111  ((snapshotdata).satisfies = HeapTupleSatisfiesNonVacuumable, \
112  (snapshotdata).xmin = (xmin_horizon))
113 
114 /*
115  * Similarly, some initialization is required for SnapshotToast. We need
116  * to set lsn and whenTaken correctly to support snapshot_too_old.
117  */
118 #define InitToastSnapshot(snapshotdata, l, w) \
119  ((snapshotdata).satisfies = HeapTupleSatisfiesToast, \
120  (snapshotdata).lsn = (l), \
121  (snapshotdata).whenTaken = (w))
122 
123 #endif /* TQUAL_H */
uint32 CommandId
Definition: c.h:459
PGDLLIMPORT SnapshotData CatalogSnapshotData
Definition: snapmgr.c:146
PGDLLIMPORT SnapshotData SnapshotAnyData
Definition: tqual.c:82
uint32 TransactionId
Definition: c.h:445
bool HeapTupleSatisfiesNonVacuumable(HeapTuple htup, Snapshot snapshot, Buffer buffer)
Definition: tqual.c:1407
bool HeapTupleIsSurelyDead(HeapTuple htup, TransactionId OldestXmin)
Definition: tqual.c:1429
bool HeapTupleSatisfiesDirty(HeapTuple htup, Snapshot snapshot, Buffer buffer)
Definition: tqual.c:739
bool HeapTupleSatisfiesAny(HeapTuple htup, Snapshot snapshot, Buffer buffer)
Definition: tqual.c:346
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
Definition: tqual.c:1484
bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data, Snapshot snapshot, HeapTuple htup, Buffer buffer, CommandId *cmin, CommandId *cmax)
void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer, uint16 infomask, TransactionId xid)
Definition: tqual.c:144
HTSV_Result
Definition: tqual.h:49
#define PGDLLIMPORT
Definition: c.h:1050
HTSU_Result HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid, Buffer buffer)
Definition: tqual.c:460
Definition: dynahash.c:208
unsigned short uint16
Definition: c.h:295
bool HeapTupleSatisfiesToast(HeapTuple htup, Snapshot snapshot, Buffer buffer)
Definition: tqual.c:366
bool HeapTupleSatisfiesHistoricMVCC(HeapTuple htup, Snapshot snapshot, Buffer buffer)
Definition: tqual.c:1672
HTSU_Result
Definition: snapshot.h:121
static TransactionId OldestXmin
Definition: vacuumlazy.c:138
static HTAB * tuplecid_data
Definition: snapmgr.c:170
HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin, Buffer buffer)
Definition: tqual.c:1164
bool HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot, Buffer buffer)
Definition: tqual.c:963
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
bool HeapTupleSatisfiesSelf(HeapTuple htup, Snapshot snapshot, Buffer buffer)
Definition: tqual.c:176
PGDLLIMPORT SnapshotData SnapshotSelfData
Definition: tqual.c:81
bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple)
Definition: tqual.c:1605
int Buffer
Definition: buf.h:23