]> granicus.if.org Git - postgresql/blob - src/include/utils/tqual.h
Fix typo in comment.
[postgresql] / src / include / utils / tqual.h
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-2015, 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
20
21 /* Static variables representing various special snapshot semantics */
22 extern PGDLLIMPORT SnapshotData SnapshotSelfData;
23 extern PGDLLIMPORT SnapshotData SnapshotAnyData;
24 extern PGDLLIMPORT SnapshotData SnapshotToastData;
25 extern PGDLLIMPORT SnapshotData CatalogSnapshotData;
26
27 #define SnapshotSelf            (&SnapshotSelfData)
28 #define SnapshotAny                     (&SnapshotAnyData)
29 #define SnapshotToast           (&SnapshotToastData)
30
31 /*
32  * We don't provide a static SnapshotDirty variable because it would be
33  * non-reentrant.  Instead, users of that snapshot type should declare a
34  * local variable of type SnapshotData, and initialize it with this macro.
35  */
36 #define InitDirtySnapshot(snapshotdata)  \
37         ((snapshotdata).satisfies = HeapTupleSatisfiesDirty)
38
39 /* This macro encodes the knowledge of which snapshots are MVCC-safe */
40 #define IsMVCCSnapshot(snapshot)  \
41         ((snapshot)->satisfies == HeapTupleSatisfiesMVCC || \
42          (snapshot)->satisfies == HeapTupleSatisfiesHistoricMVCC)
43
44 /*
45  * HeapTupleSatisfiesVisibility
46  *              True iff heap tuple satisfies a time qual.
47  *
48  * Notes:
49  *      Assumes heap tuple is valid.
50  *      Beware of multiple evaluations of snapshot argument.
51  *      Hint bits in the HeapTuple's t_infomask may be updated as a side effect;
52  *      if so, the indicated buffer is marked dirty.
53  */
54 #define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer) \
55         ((*(snapshot)->satisfies) (tuple, snapshot, buffer))
56
57 /* Result codes for HeapTupleSatisfiesVacuum */
58 typedef enum
59 {
60         HEAPTUPLE_DEAD,                         /* tuple is dead and deletable */
61         HEAPTUPLE_LIVE,                         /* tuple is live (committed, no deleter) */
62         HEAPTUPLE_RECENTLY_DEAD,        /* tuple is dead, but not deletable yet */
63         HEAPTUPLE_INSERT_IN_PROGRESS,           /* inserting xact is still in progress */
64         HEAPTUPLE_DELETE_IN_PROGRESS    /* deleting xact is still in progress */
65 } HTSV_Result;
66
67 /* These are the "satisfies" test routines for the various snapshot types */
68 extern bool HeapTupleSatisfiesMVCC(HeapTuple htup,
69                                            Snapshot snapshot, Buffer buffer);
70 extern bool HeapTupleSatisfiesSelf(HeapTuple htup,
71                                            Snapshot snapshot, Buffer buffer);
72 extern bool HeapTupleSatisfiesAny(HeapTuple htup,
73                                           Snapshot snapshot, Buffer buffer);
74 extern bool HeapTupleSatisfiesToast(HeapTuple htup,
75                                                 Snapshot snapshot, Buffer buffer);
76 extern bool HeapTupleSatisfiesDirty(HeapTuple htup,
77                                                 Snapshot snapshot, Buffer buffer);
78 extern bool HeapTupleSatisfiesHistoricMVCC(HeapTuple htup,
79                                                            Snapshot snapshot, Buffer buffer);
80
81 /* Special "satisfies" routines with different APIs */
82 extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTuple htup,
83                                                  CommandId curcid, Buffer buffer);
84 extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup,
85                                                  TransactionId OldestXmin, Buffer buffer);
86 extern bool HeapTupleIsSurelyDead(HeapTuple htup,
87                                           TransactionId OldestXmin);
88
89 extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
90                                          uint16 infomask, TransactionId xid);
91 extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
92
93 /*
94  * To avoid leaking too much knowledge about reorderbuffer implementation
95  * details this is implemented in reorderbuffer.c not tqual.c.
96  */
97 extern bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data,
98                                                           Snapshot snapshot,
99                                                           HeapTuple htup,
100                                                           Buffer buffer,
101                                                           CommandId *cmin, CommandId *cmax);
102 #endif   /* TQUAL_H */