1 /*-------------------------------------------------------------------------
4 * POSTGRES "time qualification" definitions, ie, tuple visibility rules.
6 * Should be moved/renamed... - vadim 07/28/98
8 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/include/utils/tqual.h
13 *-------------------------------------------------------------------------
18 #include "utils/snapshot.h"
21 /* Static variables representing various special snapshot semantics */
22 extern PGDLLIMPORT SnapshotData SnapshotSelfData;
23 extern PGDLLIMPORT SnapshotData SnapshotAnyData;
24 extern PGDLLIMPORT SnapshotData SnapshotToastData;
26 #define SnapshotSelf (&SnapshotSelfData)
27 #define SnapshotAny (&SnapshotAnyData)
28 #define SnapshotToast (&SnapshotToastData)
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.
35 #define InitDirtySnapshot(snapshotdata) \
36 ((snapshotdata).satisfies = HeapTupleSatisfiesDirty)
38 /* This macro encodes the knowledge of which snapshots are MVCC-safe */
39 #define IsMVCCSnapshot(snapshot) \
40 ((snapshot)->satisfies == HeapTupleSatisfiesMVCC)
43 * HeapTupleSatisfiesVisibility
44 * True iff heap tuple satisfies a time qual.
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.
52 #define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer) \
53 ((*(snapshot)->satisfies) (tuple, snapshot, buffer))
55 /* Result codes for HeapTupleSatisfiesVacuum */
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 */
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);
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);
85 extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
86 uint16 infomask, TransactionId xid);
87 extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);