OSDN Git Service

pgindent run over code.
[pg-rex/syncrep.git] / src / include / utils / tqual.h
1 /*-------------------------------------------------------------------------
2  *
3  * tqual.h
4  *        POSTGRES "time" qualification definitions.
5  *
6  *        Should be moved/renamed...    - vadim 07/28/98
7  *
8  * Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: tqual.h,v 1.21 1999/05/25 16:14:58 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef TQUAL_H
15 #define TQUAL_H
16
17 #include <access/htup.h>
18
19 typedef struct SnapshotData
20 {
21         TransactionId xmin;                     /* XID < xmin are visible to me */
22         TransactionId xmax;                     /* XID >= xmax are invisible to me */
23         uint32          xcnt;                   /* # of xact below */
24         TransactionId *xip;                     /* array of xacts in progress */
25         ItemPointerData tid;            /* required for Dirty snapshot -:( */
26 }                       SnapshotData;
27
28 typedef SnapshotData *Snapshot;
29
30 #define SnapshotNow                                     ((Snapshot) 0x0)
31 #define SnapshotSelf                            ((Snapshot) 0x1)
32
33 extern Snapshot SnapshotDirty;
34 extern Snapshot QuerySnapshot;
35 extern Snapshot SerializableSnapshot;
36
37 #define IsSnapshotNow(snapshot)         ((Snapshot) snapshot == SnapshotNow)
38 #define IsSnapshotSelf(snapshot)        ((Snapshot) snapshot == SnapshotSelf)
39 #define IsSnapshotDirty(snapshot)       ((Snapshot) snapshot == SnapshotDirty)
40
41 extern TransactionId HeapSpecialTransactionId;
42 extern CommandId HeapSpecialCommandId;
43
44 /*
45  * HeapTupleSatisfiesVisibility
46  *              True iff heap tuple satsifies a time qual.
47  *
48  * Note:
49  *              Assumes heap tuple is valid.
50  */
51 #define HeapTupleSatisfiesVisibility(tuple, snapshot) \
52 ( \
53         TransactionIdEquals((tuple)->t_data->t_xmax, AmiTransactionId) ? \
54                 false \
55         : \
56         ( \
57                 (IsSnapshotSelf(snapshot) || heapisoverride()) ? \
58                         HeapTupleSatisfiesItself((tuple)->t_data) \
59                 : \
60                         ((IsSnapshotDirty(snapshot)) ? \
61                                 HeapTupleSatisfiesDirty((tuple)->t_data) \
62                         : \
63                                 ((IsSnapshotNow(snapshot)) ? \
64                                         HeapTupleSatisfiesNow((tuple)->t_data) \
65                                 : \
66                                         HeapTupleSatisfiesSnapshot((tuple)->t_data, snapshot) \
67                                 ) \
68                         ) \
69         ) \
70 )
71
72 #define heapisoverride() \
73 ( \
74         (!TransactionIdIsValid(HeapSpecialTransactionId)) ? \
75                 false \
76         : \
77         ( \
78                 (!TransactionIdEquals(GetCurrentTransactionId(), \
79                                                          HeapSpecialTransactionId) || \
80                  GetCurrentCommandId() != HeapSpecialCommandId) ? \
81                 ( \
82                         HeapSpecialTransactionId = InvalidTransactionId, \
83                         false \
84                 ) \
85                 : \
86                         true \
87         ) \
88 )
89
90 #define HeapTupleMayBeUpdated           0
91 #define HeapTupleInvisible                      1
92 #define HeapTupleSelfUpdated            2
93 #define HeapTupleUpdated                        3
94 #define HeapTupleBeingUpdated           4
95
96 extern bool HeapTupleSatisfiesItself(HeapTupleHeader tuple);
97 extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple);
98 extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple);
99 extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot);
100 extern int      HeapTupleSatisfiesUpdate(HeapTuple tuple);
101
102 extern void setheapoverride(bool on);
103
104 extern Snapshot GetSnapshotData(bool serializable);
105 extern void SetQuerySnapshot(void);
106 extern void FreeXactSnapshot(void);
107
108 #endif   /* TQUAL_H */