1 /*-------------------------------------------------------------------------
4 * POSTGRES "time" qualification definitions.
6 * Should be moved/renamed... - vadim 07/28/98
8 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Id: tqual.h,v 1.32 2001/07/12 04:11:13 tgl Exp $
13 *-------------------------------------------------------------------------
18 #include "access/htup.h"
19 #include "access/xact.h"
22 typedef struct SnapshotData
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 -:( */
32 typedef SnapshotData *Snapshot;
34 #define SnapshotNow ((Snapshot) 0x0)
35 #define SnapshotSelf ((Snapshot) 0x1)
36 #define SnapshotAny ((Snapshot) 0x2)
38 extern DLLIMPORT Snapshot SnapshotDirty;
39 extern DLLIMPORT Snapshot QuerySnapshot;
40 extern DLLIMPORT Snapshot SerializableSnapshot;
42 extern bool ReferentialIntegritySnapshotOverride;
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)
51 * HeapTupleSatisfiesVisibility
52 * True iff heap tuple satsifies a time qual.
55 * Assumes heap tuple is valid.
56 * Beware of multiple evaluations of arguments.
58 #define HeapTupleSatisfiesVisibility(tuple, snapshot) \
60 TransactionIdEquals((tuple)->t_data->t_xmax, AmiTransactionId) ? \
64 IsSnapshotAny(snapshot) ? \
67 (IsSnapshotSelf(snapshot) ? \
68 HeapTupleSatisfiesItself((tuple)->t_data) \
70 (IsSnapshotNow(snapshot) ? \
71 HeapTupleSatisfiesNow((tuple)->t_data) \
73 (IsSnapshotDirty(snapshot) ? \
74 HeapTupleSatisfiesDirty((tuple)->t_data) \
76 HeapTupleSatisfiesSnapshot((tuple)->t_data, snapshot) \
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
90 /* Result codes for HeapTupleSatisfiesVacuum */
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 */
100 extern bool HeapTupleSatisfiesItself(HeapTupleHeader tuple);
101 extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple);
102 extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple);
103 extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple,
105 extern int HeapTupleSatisfiesUpdate(HeapTuple tuple);
106 extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTupleHeader tuple,
107 TransactionId XmaxRecent);
109 extern Snapshot GetSnapshotData(bool serializable);
110 extern void SetQuerySnapshot(void);
111 extern void FreeXactSnapshot(void);