postgresql/src/include/access/valid.h

119 lines
2.9 KiB
C
Raw Normal View History

/*-------------------------------------------------------------------------
*
* valid.h
* POSTGRES tuple qualification validity definitions.
*
*
2004-08-29 06:13:13 +02:00
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
2004-08-29 06:13:13 +02:00
* $PostgreSQL: pgsql/src/include/access/valid.h,v 1.34 2004/08/29 04:13:04 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef VALID_H
#define VALID_H
1997-09-18 16:21:02 +02:00
/* ----------------
* 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); \
1997-09-18 16:21:02 +02:00
\
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); \
1997-09-18 16:21:02 +02:00
\
if (!DatumGetBool(__test)) \
1997-09-18 16:21:02 +02:00
{ \
(result) = false; \
break; \
} \
} \
} while (0)
1997-09-18 16:21:02 +02:00
/* ----------------
* HeapTupleSatisfies
*
* res is set TRUE if the HeapTuple satisfies the timequal and keytest,
2002-09-04 22:31:48 +02:00
* otherwise it is set FALSE. Note that the hint bits in the HeapTuple's
* t_infomask may be updated as a side effect.
1997-09-18 16:21:02 +02:00
*
* 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.
* ----------------
*/
1998-11-27 20:33:35 +01:00
#define HeapTupleSatisfies(tuple, \
1997-09-18 16:21:02 +02:00
relation, \
buffer, \
disk_page, \
snapshot, \
1997-09-18 16:21:02 +02:00
nKeys, \
key, \
res) \
1997-09-18 16:21:02 +02:00
do \
{ \
/* We use underscores to protect the variable passed in as parameters */ \
1998-11-27 20:33:35 +01:00
if ((key) != NULL) \
HeapKeyTest(tuple, RelationGetDescr(relation), \
(nKeys), (key), (res)); \
1997-09-18 16:21:02 +02:00
else \
(res) = true; \
1997-09-18 16:21:02 +02:00
\
if (res) \
1998-11-27 20:33:35 +01:00
{ \
if ((relation)->rd_rel->relkind != RELKIND_UNCATALOGED) \
1997-09-18 16:21:02 +02:00
{ \
1998-11-27 20:33:35 +01:00
uint16 _infomask = (tuple)->t_data->t_infomask; \
\
(res) = HeapTupleSatisfiesVisibility((tuple), (snapshot)); \
1998-11-27 20:33:35 +01:00
if ((tuple)->t_data->t_infomask != _infomask) \
SetBufferCommitInfoNeedsSave(buffer); \
1997-09-18 16:21:02 +02:00
} \
} \
} while (0)
#endif /* VALID_H */