OSDN Git Service

Create a new HeapTupleSatisfiesVacuum() routine in tqual.c that embodies the
[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  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  * $Id: tqual.h,v 1.32 2001/07/12 04:11:13 tgl Exp $
12  *
13  *-------------------------------------------------------------------------
14  */
15 #ifndef TQUAL_H
16 #define TQUAL_H
17
18 #include "access/htup.h"
19 #include "access/xact.h"
20
21
22 typedef struct SnapshotData
23 {
24         TransactionId xmin;                     /* XID < xmin are visible to me */
25         TransactionId xmax;                     /* XID >= xmax are invisible to me */
26         uint32          xcnt;                   /* # of xact ids in xip[] */
27         TransactionId *xip;                     /* array of xact IDs in progress */
28         /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */
29         ItemPointerData tid;            /* required for Dirty snapshot -:( */
30 } SnapshotData;
31
32 typedef SnapshotData *Snapshot;
33
34 #define SnapshotNow                                     ((Snapshot) 0x0)
35 #define SnapshotSelf                            ((Snapshot) 0x1)
36 #define SnapshotAny                                     ((Snapshot) 0x2)
37
38 extern DLLIMPORT Snapshot SnapshotDirty;
39 extern DLLIMPORT Snapshot QuerySnapshot;
40 extern DLLIMPORT Snapshot SerializableSnapshot;
41
42 extern bool ReferentialIntegritySnapshotOverride;
43
44 #define IsSnapshotNow(snapshot)         ((Snapshot) (snapshot) == SnapshotNow)
45 #define IsSnapshotSelf(snapshot)        ((Snapshot) (snapshot) == SnapshotSelf)
46 #define IsSnapshotAny(snapshot)         ((Snapshot) (snapshot) == SnapshotAny)
47 #define IsSnapshotDirty(snapshot)       ((Snapshot) (snapshot) == SnapshotDirty)
48
49
50 /*
51  * HeapTupleSatisfiesVisibility
52  *              True iff heap tuple satsifies a time qual.
53  *
54  * Notes:
55  *              Assumes heap tuple is valid.
56  *              Beware of multiple evaluations of arguments.
57  */
58 #define HeapTupleSatisfiesVisibility(tuple, snapshot) \
59 ( \
60         TransactionIdEquals((tuple)->t_data->t_xmax, AmiTransactionId) ? \
61                 false \
62         : \
63         ( \
64                 IsSnapshotAny(snapshot) ? \
65                         true \
66                 : \
67                         (IsSnapshotSelf(snapshot) ? \
68                                 HeapTupleSatisfiesItself((tuple)->t_data) \
69                         : \
70                                 (IsSnapshotNow(snapshot) ? \
71                                         HeapTupleSatisfiesNow((tuple)->t_data) \
72                                 : \
73                                         (IsSnapshotDirty(snapshot) ? \
74                                                 HeapTupleSatisfiesDirty((tuple)->t_data) \
75                                         : \
76                                                 HeapTupleSatisfiesSnapshot((tuple)->t_data, snapshot) \
77                                         ) \
78                         ) \
79                 ) \
80         ) \
81 )
82
83 /* Result codes for HeapTupleSatisfiesUpdate */
84 #define HeapTupleMayBeUpdated           0
85 #define HeapTupleInvisible                      1
86 #define HeapTupleSelfUpdated            2
87 #define HeapTupleUpdated                        3
88 #define HeapTupleBeingUpdated           4
89
90 /* Result codes for HeapTupleSatisfiesVacuum */
91 typedef enum
92 {
93         HEAPTUPLE_DEAD,                         /* tuple is dead and deletable */
94         HEAPTUPLE_LIVE,                         /* tuple is live (committed, no deleter) */
95         HEAPTUPLE_RECENTLY_DEAD,        /* tuple is dead, but not deletable yet */
96         HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */
97         HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */
98 } HTSV_Result;
99
100 extern bool HeapTupleSatisfiesItself(HeapTupleHeader tuple);
101 extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple);
102 extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple);
103 extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple,
104                                                    Snapshot snapshot);
105 extern int      HeapTupleSatisfiesUpdate(HeapTuple tuple);
106 extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTupleHeader tuple,
107                                                                                         TransactionId XmaxRecent);
108
109 extern Snapshot GetSnapshotData(bool serializable);
110 extern void SetQuerySnapshot(void);
111 extern void FreeXactSnapshot(void);
112
113 #endif   /* TQUAL_H */