summaryrefslogtreecommitdiff
path: root/src/include/access/valid.h
blob: e16a392a24365dfe05c3178f2bbbfd49d75d5b96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*-------------------------------------------------------------------------
 *
 * valid.h
 *	  POSTGRES tuple qualification validity definitions.
 *
 *
 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * $Id: valid.h,v 1.32 2003/11/09 21:30:37 tgl Exp $
 *
 *-------------------------------------------------------------------------
 */
#ifndef VALID_H
#define VALID_H

/* ----------------
 *		HeapKeyTest
 *
 *		Test a heap tuple with respect to a scan key.
 * ----------------
 */

#define HeapKeyTest(tuple, \
					tupdesc, \
					nkeys, \
					keys, \
					result) \
do \
{ \
/* We use underscores to protect the variable passed in as parameters */ \
/* We use two underscore here because this macro is included in the \
   macro below */ \
	int			__cur_nkeys = (nkeys); \
	ScanKey		__cur_keys = (keys); \
 \
	(result) = true; /* may change */ \
	for (; __cur_nkeys--; __cur_keys++) \
	{ \
		Datum	__atp; \
		bool	__isnull; \
		Datum	__test; \
 \
		__atp = heap_getattr((tuple), \
							 __cur_keys->sk_attno, \
							 (tupdesc), \
							 &__isnull); \
 \
		if (__isnull) \
		{ \
			/* XXX eventually should check if SK_ISNULL */ \
			(result) = false; \
			break; \
		} \
 \
		if (__cur_keys->sk_flags & SK_ISNULL) \
		{ \
			(result) = false; \
			break; \
		} \
 \
		__test = FunctionCall2(&__cur_keys->sk_func, \
							   __atp, __cur_keys->sk_argument); \
 \
		if (!DatumGetBool(__test)) \
		{ \
			(result) = false; \
			break; \
		} \
	} \
} while (0)

/* ----------------
 *		HeapTupleSatisfies
 *
 *	res is set TRUE if the HeapTuple satisfies the timequal and keytest,
 *	otherwise it is set FALSE.	Note that the hint bits in the HeapTuple's
 *	t_infomask may be updated as a side effect.
 *
 *	on 8/21/92 mao says:  i rearranged the tests here to do keytest before
 *	SatisfiesTimeQual.	profiling indicated that even for vacuumed relations,
 *	time qual checking was more expensive than key testing.  time qual is
 *	least likely to fail, too.	we should really add the time qual test to
 *	the restriction and optimize it in the normal way.	this has interactions
 *	with joey's expensive function work.
 * ----------------
 */
#define HeapTupleSatisfies(tuple, \
						   relation, \
						   buffer, \
						   disk_page, \
						   snapshot, \
						   nKeys, \
						   key, \
						   res) \
do \
{ \
/* We use underscores to protect the variable passed in as parameters */ \
	if ((key) != NULL) \
		HeapKeyTest(tuple, RelationGetDescr(relation), \
						   (nKeys), (key), (res)); \
	else \
		(res) = true; \
 \
	if (res) \
	{ \
		if ((relation)->rd_rel->relkind != RELKIND_UNCATALOGED) \
		{ \
			uint16	_infomask = (tuple)->t_data->t_infomask; \
			\
			(res) = HeapTupleSatisfiesVisibility((tuple), (snapshot)); \
			if ((tuple)->t_data->t_infomask != _infomask) \
				SetBufferCommitInfoNeedsSave(buffer); \
		} \
	} \
} while (0)

#endif   /* VALID_H */