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;
25 extern PGDLLIMPORT SnapshotData CatalogSnapshotData;
27 #define SnapshotSelf (&SnapshotSelfData)
28 #define SnapshotAny (&SnapshotAnyData)
29 #define SnapshotToast (&SnapshotToastData)
32 * We don't provide a static SnapshotDirty variable because it would be
33 * non-reentrant. Instead, users of that snapshot type should declare a
34 * local variable of type SnapshotData, and initialize it with this macro.
36 #define InitDirtySnapshot(snapshotdata) \
37 ((snapshotdata).satisfies = HeapTupleSatisfiesDirty)
39 /* This macro encodes the knowledge of which snapshots are MVCC-safe */
40 #define IsMVCCSnapshot(snapshot) \
41 ((snapshot)->satisfies == HeapTupleSatisfiesMVCC || \
42 (snapshot)->satisfies == HeapTupleSatisfiesHistoricMVCC)
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, 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(HeapTuple htup,
69 Snapshot snapshot, Buffer buffer);
70 extern bool HeapTupleSatisfiesSelf(HeapTuple htup,
71 Snapshot snapshot, Buffer buffer);
72 extern bool HeapTupleSatisfiesAny(HeapTuple htup,
73 Snapshot snapshot, Buffer buffer);
74 extern bool HeapTupleSatisfiesToast(HeapTuple htup,
75 Snapshot snapshot, Buffer buffer);
76 extern bool HeapTupleSatisfiesDirty(HeapTuple htup,
77 Snapshot snapshot, Buffer buffer);
78 extern bool HeapTupleSatisfiesHistoricMVCC(HeapTuple htup,
79 Snapshot snapshot, Buffer buffer);
81 /* Special "satisfies" routines with different APIs */
82 extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTuple htup,
83 CommandId curcid, Buffer buffer);
84 extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup,
85 TransactionId OldestXmin, Buffer buffer);
86 extern bool HeapTupleIsSurelyDead(HeapTuple htup,
87 TransactionId OldestXmin);
89 extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
90 uint16 infomask, TransactionId xid);
91 extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
94 * To avoid leaking to much knowledge about reorderbuffer implementation
95 * details this is implemented in reorderbuffer.c not tqual.c.
97 extern bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data,
101 CommandId *cmin, CommandId *cmax);