1996-08-27 23:50:29 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* valid.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES tuple qualification validity definitions.
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*
|
2004-08-29 06:13:13 +02:00
|
|
|
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
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 $
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef VALID_H
|
1996-08-27 23:50:29 +02:00
|
|
|
#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++) \
|
|
|
|
{ \
|
2003-11-09 22:30:38 +01:00
|
|
|
Datum __atp; \
|
|
|
|
bool __isnull; \
|
|
|
|
Datum __test; \
|
|
|
|
\
|
1998-01-31 05:39:26 +01:00
|
|
|
__atp = heap_getattr((tuple), \
|
2000-05-30 06:25:00 +02:00
|
|
|
__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; \
|
|
|
|
} \
|
|
|
|
\
|
2003-11-09 22:30:38 +01:00
|
|
|
__test = FunctionCall2(&__cur_keys->sk_func, \
|
|
|
|
__atp, __cur_keys->sk_argument); \
|
1997-09-18 16:21:02 +02:00
|
|
|
\
|
2003-11-09 22:30:38 +01:00
|
|
|
if (!DatumGetBool(__test)) \
|
1997-09-18 16:21:02 +02:00
|
|
|
{ \
|
|
|
|
(result) = false; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1997-09-18 16:21:02 +02:00
|
|
|
/* ----------------
|
|
|
|
* HeapTupleSatisfies
|
|
|
|
*
|
2002-05-24 20:57:57 +02:00
|
|
|
* 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
|
2002-05-24 20:57:57 +02:00
|
|
|
* 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, \
|
2003-09-25 20:58:36 +02:00
|
|
|
snapshot, \
|
1997-09-18 16:21:02 +02:00
|
|
|
nKeys, \
|
2002-05-24 20:57:57 +02:00
|
|
|
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), \
|
2002-05-24 20:57:57 +02:00
|
|
|
(nKeys), (key), (res)); \
|
1997-09-18 16:21:02 +02:00
|
|
|
else \
|
2002-05-24 20:57:57 +02:00
|
|
|
(res) = true; \
|
1997-09-18 16:21:02 +02:00
|
|
|
\
|
2002-05-24 20:57:57 +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; \
|
|
|
|
\
|
2003-09-25 20:58:36 +02:00
|
|
|
(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)
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* VALID_H */
|