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
|
|
|
*
|
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
2000-05-28 19:56:29 +02:00
|
|
|
* $Id: valid.h,v 1.21 2000/05/28 17:56:14 tgl 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 */ \
|
|
|
|
bool __isnull; \
|
|
|
|
Datum __atp; \
|
|
|
|
int __test; \
|
|
|
|
int __cur_nkeys = (nkeys); \
|
|
|
|
ScanKey __cur_keys = (keys); \
|
|
|
|
\
|
|
|
|
(result) = true; /* may change */ \
|
|
|
|
for (; __cur_nkeys--; __cur_keys++) \
|
|
|
|
{ \
|
1998-01-31 05:39:26 +01:00
|
|
|
__atp = heap_getattr((tuple), \
|
1997-09-18 16:21:02 +02:00
|
|
|
__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; \
|
|
|
|
} \
|
|
|
|
\
|
2000-05-28 19:56:29 +02:00
|
|
|
if (__cur_keys->sk_func.fn_addr == (PGFunction) oideq) /* optimization */ \
|
1997-09-18 16:21:02 +02:00
|
|
|
__test = (__cur_keys->sk_argument == __atp); \
|
|
|
|
else if (__cur_keys->sk_flags & SK_COMMUTE) \
|
1998-01-15 20:46:37 +01:00
|
|
|
__test = (long) FMGR_PTR2(&__cur_keys->sk_func, \
|
1997-09-18 16:21:02 +02:00
|
|
|
__cur_keys->sk_argument, __atp); \
|
|
|
|
else \
|
1998-01-15 20:46:37 +01:00
|
|
|
__test = (long) FMGR_PTR2(&__cur_keys->sk_func, \
|
1997-09-18 16:21:02 +02:00
|
|
|
__atp, __cur_keys->sk_argument); \
|
|
|
|
\
|
|
|
|
if (!__test == !(__cur_keys->sk_flags & SK_NEGATE)) \
|
|
|
|
{ \
|
|
|
|
/* XXX eventually should check if SK_ISNULL */ \
|
|
|
|
(result) = false; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1997-09-18 16:21:02 +02:00
|
|
|
/* ----------------
|
|
|
|
* HeapTupleSatisfies
|
|
|
|
*
|
|
|
|
* Returns a valid HeapTuple if it satisfies the timequal and keytest.
|
|
|
|
* Returns NULL otherwise. Used to be heap_satisifies (sic) which
|
|
|
|
* returned a boolean. It now returns a tuple so that we can avoid doing two
|
|
|
|
* PageGetItem's per tuple.
|
|
|
|
*
|
|
|
|
* Complete check of validity including LP_CTUP and keytest.
|
|
|
|
* This should perhaps be combined with valid somehow in the
|
|
|
|
* future. (Also, additional rule tests/time range tests.)
|
|
|
|
*
|
|
|
|
* 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, \
|
1997-11-21 00:24:03 +01:00
|
|
|
seeself, \
|
1997-09-18 16:21:02 +02:00
|
|
|
nKeys, \
|
1998-11-27 20:33:35 +01:00
|
|
|
key) \
|
1997-09-18 16:21:02 +02:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
/* We use underscores to protect the variable passed in as parameters */ \
|
|
|
|
bool _res; \
|
|
|
|
\
|
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 \
|
1998-11-27 20:33:35 +01:00
|
|
|
_res = TRUE; \
|
1997-09-18 16:21:02 +02:00
|
|
|
\
|
1998-11-27 20:33:35 +01:00
|
|
|
if (_res) \
|
|
|
|
{ \
|
|
|
|
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), (seeself)); \
|
|
|
|
if ((tuple)->t_data->t_infomask != _infomask) \
|
|
|
|
SetBufferCommitInfoNeedsSave(buffer); \
|
|
|
|
if (!_res) \
|
|
|
|
(tuple)->t_data = NULL; \
|
1997-09-18 16:21:02 +02:00
|
|
|
} \
|
|
|
|
} \
|
1998-11-27 20:33:35 +01:00
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
(tuple)->t_data = NULL; \
|
|
|
|
} \
|
1997-09-18 16:21:02 +02:00
|
|
|
} while (0)
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* VALID_H */
|