tqual.h 2.71 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * tqual.h
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
4
 *	  POSTGRES "time" qualification definitions.
5
 *
6
 *	  Should be moved/renamed...	- vadim 07/28/98
7 8 9
 *
 * Copyright (c) 1994, Regents of the University of California
 *
10
 * $Id: tqual.h,v 1.27 2000/01/17 23:57:48 tgl Exp $
11 12 13
 *
 *-------------------------------------------------------------------------
 */
14
#ifndef TQUAL_H
15 16
#define TQUAL_H

17 18
#include "access/htup.h"
#include "access/xact.h"
19

20

21 22
typedef struct SnapshotData
{
23 24 25 26 27
	TransactionId	xmin;		/* XID < xmin are visible to me */
	TransactionId	xmax;		/* XID >= xmax are invisible to me */
	uint32			xcnt;		/* # of xact below */
	TransactionId  *xip;		/* array of xacts in progress */
	ItemPointerData	tid;		/* required for Dirty snapshot -:( */
28
} SnapshotData;
29

30
typedef SnapshotData *Snapshot;
31

32 33
#define SnapshotNow					((Snapshot) 0x0)
#define SnapshotSelf				((Snapshot) 0x1)
34
#define SnapshotAny					((Snapshot) 0x2)
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
35

Bruce Momjian's avatar
Bruce Momjian committed
36 37 38
extern Snapshot SnapshotDirty;
extern Snapshot QuerySnapshot;
extern Snapshot SerializableSnapshot;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
39

40 41
extern bool ReferentialIntegritySnapshotOverride;

42 43 44 45
#define IsSnapshotNow(snapshot)		((Snapshot) (snapshot) == SnapshotNow)
#define IsSnapshotSelf(snapshot)	((Snapshot) (snapshot) == SnapshotSelf)
#define IsSnapshotAny(snapshot)		((Snapshot) (snapshot) == SnapshotAny)
#define IsSnapshotDirty(snapshot)	((Snapshot) (snapshot) == SnapshotDirty)
46

47

48
/*
Bruce Momjian's avatar
Bruce Momjian committed
49
 * HeapTupleSatisfiesVisibility
50 51
 *		True iff heap tuple satsifies a time qual.
 *
52
 * Notes:
53
 *		Assumes heap tuple is valid.
54
 *		Beware of multiple evaluations of arguments.
55
 */
56
#define HeapTupleSatisfiesVisibility(tuple, snapshot) \
57
( \
58
	TransactionIdEquals((tuple)->t_data->t_xmax, AmiTransactionId) ? \
59 60 61
		false \
	: \
	( \
62
		IsSnapshotAny(snapshot) ? \
63
			true \
64
		: \
65
			(IsSnapshotSelf(snapshot) ? \
66
				HeapTupleSatisfiesItself((tuple)->t_data) \
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
67
			: \
68
				(IsSnapshotDirty(snapshot) ? \
69
					HeapTupleSatisfiesDirty((tuple)->t_data) \
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
70
				: \
71
					(IsSnapshotNow(snapshot) ? \
72 73 74 75
						HeapTupleSatisfiesNow((tuple)->t_data) \
					: \
						HeapTupleSatisfiesSnapshot((tuple)->t_data, snapshot) \
					) \
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
76
			) \
77
		) \
78 79
	) \
)
80

Bruce Momjian's avatar
Bruce Momjian committed
81 82
#define HeapTupleMayBeUpdated		0
#define HeapTupleInvisible			1
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
83 84 85
#define HeapTupleSelfUpdated		2
#define HeapTupleUpdated			3
#define HeapTupleBeingUpdated		4
86

Bruce Momjian's avatar
Bruce Momjian committed
87 88 89
extern bool HeapTupleSatisfiesItself(HeapTupleHeader tuple);
extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple);
extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple);
90 91
extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple,
									   Snapshot snapshot);
Bruce Momjian's avatar
Bruce Momjian committed
92
extern int	HeapTupleSatisfiesUpdate(HeapTuple tuple);
93

94
extern Snapshot GetSnapshotData(bool serializable);
Bruce Momjian's avatar
Bruce Momjian committed
95 96
extern void SetQuerySnapshot(void);
extern void FreeXactSnapshot(void);
97

98
#endif	 /* TQUAL_H */