1 /*-------------------------------------------------------------------------
4 * POSTGRES "time qualification" definitions, ie, tuple visibility rules.
6 * Should be moved/renamed... - vadim 07/28/98
8 * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.75 2010/01/02 16:58:10 momjian Exp $
13 *-------------------------------------------------------------------------
18 #include "utils/snapshot.h"
21 /* Static variables representing various special snapshot semantics */
22 extern PGDLLIMPORT SnapshotData SnapshotNowData;
23 extern PGDLLIMPORT SnapshotData SnapshotSelfData;
24 extern PGDLLIMPORT SnapshotData SnapshotAnyData;
25 extern PGDLLIMPORT SnapshotData SnapshotToastData;
27 #define SnapshotNow (&SnapshotNowData)
28 #define SnapshotSelf (&SnapshotSelfData)
29 #define SnapshotAny (&SnapshotAnyData)
30 #define SnapshotToast (&SnapshotToastData)
33 * We don't provide a static SnapshotDirty variable because it would be
34 * non-reentrant. Instead, users of that snapshot type should declare a
35 * local variable of type SnapshotData, and initialize it with this macro.
37 #define InitDirtySnapshot(snapshotdata) \
38 ((snapshotdata).satisfies = HeapTupleSatisfiesDirty)
40 /* This macro encodes the knowledge of which snapshots are MVCC-safe */
41 #define IsMVCCSnapshot(snapshot) \
42 ((snapshot)->satisfies == HeapTupleSatisfiesMVCC)
45 * HeapTupleSatisfiesVisibility
46 * True iff heap tuple satisfies a time qual.
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.
54 #define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer) \
55 ((*(snapshot)->satisfies) ((tuple)->t_data, snapshot, buffer))
57 /* Result codes for HeapTupleSatisfiesVacuum */
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 */
67 /* These are the "satisfies" test routines for the various snapshot types */
68 extern bool HeapTupleSatisfiesMVCC(HeapTupleHeader tuple,
69 Snapshot snapshot, Buffer buffer);
70 extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple,
71 Snapshot snapshot, Buffer buffer);
72 extern bool HeapTupleSatisfiesSelf(HeapTupleHeader tuple,
73 Snapshot snapshot, Buffer buffer);
74 extern bool HeapTupleSatisfiesAny(HeapTupleHeader tuple,
75 Snapshot snapshot, Buffer buffer);
76 extern bool HeapTupleSatisfiesToast(HeapTupleHeader tuple,
77 Snapshot snapshot, Buffer buffer);
78 extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple,
79 Snapshot snapshot, Buffer buffer);
81 /* Special "satisfies" routines with different APIs */
82 extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTupleHeader tuple,
83 CommandId curcid, Buffer buffer);
84 extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTupleHeader tuple,
85 TransactionId OldestXmin, Buffer buffer);
87 extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
88 uint16 infomask, TransactionId xid);