1996-08-27 23:50:29 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* tupmacs.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* Tuple macros used by both index tuples and heap tuples.
|
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-03-17 03:36:41 +01:00
|
|
|
* $Id: tupmacs.h,v 1.14 2000/03/17 02:36:37 tgl Exp $
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef TUPMACS_H
|
|
|
|
#define TUPMACS_H
|
|
|
|
|
1999-07-15 17:21:54 +02:00
|
|
|
#include "utils/memutils.h"
|
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
/*
|
|
|
|
* check to see if the ATT'th bit of an array of 8-bit bytes is set.
|
|
|
|
*/
|
|
|
|
#define att_isnull(ATT, BITS) (!((BITS)[(ATT) >> 3] & (1 << ((ATT) & 0x07))))
|
|
|
|
|
|
|
|
/*
|
1998-09-01 05:29:17 +02:00
|
|
|
* given a Form_pg_attribute and a pointer into a tuple's data
|
1996-08-27 23:50:29 +02:00
|
|
|
* area, return the correct value or pointer.
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* We return a 4 byte (char *) value in all cases. If the attribute has
|
1996-08-27 23:50:29 +02:00
|
|
|
* "byval" false or has variable length, we return the same pointer
|
|
|
|
* into the tuple data area that we're passed. Otherwise, we return
|
|
|
|
* the 1, 2, or 4 bytes pointed to by it, properly extended to 4
|
|
|
|
* bytes, depending on the length of the attribute.
|
|
|
|
*
|
|
|
|
* note that T must already be properly LONGALIGN/SHORTALIGN'd for
|
|
|
|
* this to work correctly.
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* the double-cast is to stop gcc from (correctly) complaining about
|
1996-08-27 23:50:29 +02:00
|
|
|
* casting integer types with size < sizeof(char *) to (char *).
|
|
|
|
* sign-extension may get weird if you use an integer type that
|
|
|
|
* isn't the same size as (char *) for the first cast. (on the other
|
|
|
|
* hand, it's safe to use another type for the (foo *)(T).)
|
|
|
|
*
|
|
|
|
* attbyval seems to be fairly redundant. We have to return a pointer if
|
|
|
|
* the value is longer than 4 bytes or has variable length; returning the
|
1997-09-07 07:04:48 +02:00
|
|
|
* value would be useless. In fact, for at least the variable length case,
|
1996-08-27 23:50:29 +02:00
|
|
|
* the caller assumes we return a pointer regardless of attbyval.
|
|
|
|
* I would eliminate attbyval altogether, but I don't know how. -BRYANH.
|
|
|
|
*/
|
|
|
|
#define fetchatt(A, T) \
|
1998-02-01 06:38:40 +01:00
|
|
|
( \
|
|
|
|
(*(A))->attbyval && (*(A))->attlen != -1 ? \
|
|
|
|
( \
|
2000-03-17 03:36:41 +01:00
|
|
|
(*(A))->attlen > (int) sizeof(int16) ? \
|
1998-02-01 06:38:40 +01:00
|
|
|
( \
|
|
|
|
(char *) (long) *((int32 *)(T)) \
|
|
|
|
) \
|
1998-02-26 05:46:47 +01:00
|
|
|
: \
|
1998-02-01 06:38:40 +01:00
|
|
|
( \
|
2000-03-17 03:36:41 +01:00
|
|
|
(*(A))->attlen < (int) sizeof(int16) ? \
|
1998-02-01 06:38:40 +01:00
|
|
|
(char *) (long) *((char *)(T)) \
|
|
|
|
: \
|
|
|
|
(char *) (long) *((int16 *)(T))) \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
(char *) (T) \
|
|
|
|
)
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-03-25 04:49:34 +01:00
|
|
|
/* att_align aligns the given offset as needed for a datum of length attlen
|
1999-05-25 18:15:34 +02:00
|
|
|
* and alignment requirement attalign. In practice we don't need the length.
|
1999-03-25 04:49:34 +01:00
|
|
|
* The attalign cases are tested in what is hopefully something like their
|
|
|
|
* frequency of occurrence.
|
|
|
|
*/
|
1998-09-07 07:35:48 +02:00
|
|
|
#define att_align(cur_offset, attlen, attalign) \
|
|
|
|
( \
|
1999-03-25 04:49:34 +01:00
|
|
|
((attalign) == 'i') ? INTALIGN(cur_offset) : \
|
|
|
|
(((attalign) == 'c') ? ((long)(cur_offset)) : \
|
|
|
|
(((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
|
1998-09-07 07:35:48 +02:00
|
|
|
( \
|
1999-03-25 04:49:34 +01:00
|
|
|
AssertMacro((attalign) == 's'), \
|
|
|
|
SHORTALIGN(cur_offset) \
|
|
|
|
))) \
|
1998-09-07 07:35:48 +02:00
|
|
|
)
|
1999-03-25 04:49:34 +01:00
|
|
|
|
1998-09-07 07:35:48 +02:00
|
|
|
#define att_addlength(cur_offset, attlen, attval) \
|
|
|
|
( \
|
|
|
|
((attlen) != -1) ? \
|
|
|
|
( \
|
|
|
|
(cur_offset) + (attlen) \
|
|
|
|
) \
|
|
|
|
: \
|
|
|
|
( \
|
1999-12-21 01:06:44 +01:00
|
|
|
(cur_offset) + VARATT_SIZE(DatumGetPointer(attval)) \
|
1998-09-07 07:35:48 +02:00
|
|
|
) \
|
|
|
|
)
|
1999-05-25 18:15:34 +02:00
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
#endif
|