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