nattr field, and rename the field.
Heikki Linnakangas
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.113 2007/01/05 22:19:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.114 2007/01/09 22:00:59 momjian Exp $
*
*-------------------------------------------------------------------------
*/
bool
heap_attisnull(HeapTuple tup, int attnum)
{
- if (attnum > (int) tup->t_data->t_natts)
+ if (attnum > (int) HeapTupleHeaderGetNatts(tup->t_data))
return true;
if (attnum > 0)
{
int j = 1;
long off;
+ int natts = HeapTupleHeaderGetNatts(tup);
/*
* need to set cache for some atts
for (; j <= attnum ||
/* Can we compute more? We will probably need them */
- (j < tup->t_natts &&
+ (j < natts &&
att[j]->attcacheoff == -1 &&
(HeapTupleNoNulls(tuple) || !att_isnull(j, bp)) &&
(HeapTupleAllFixed(tuple) || att[j]->attlen > 0)); j++)
HeapTupleHeaderSetTypeId(td, tupleDescriptor->tdtypeid);
HeapTupleHeaderSetTypMod(td, tupleDescriptor->tdtypmod);
- td->t_natts = numberOfAttributes;
+ HeapTupleHeaderSetNatts(td, numberOfAttributes);
td->t_hoff = hoff;
if (tupleDescriptor->tdhasoid) /* else leave infomask = 0 */
HeapTupleHeaderSetTypeId(td, tupleDescriptor->tdtypeid);
HeapTupleHeaderSetTypMod(td, tupleDescriptor->tdtypmod);
- td->t_natts = numberOfAttributes;
+ HeapTupleHeaderSetNatts(td, numberOfAttributes);
td->t_hoff = hoff;
if (tupleDescriptor->tdhasoid) /* else leave infomask = 0 */
bits8 *bp = tup->t_bits; /* ptr to null bitmap in tuple */
bool slow = false; /* can we use/set attcacheoff? */
- natts = tup->t_natts;
+ natts = HeapTupleHeaderGetNatts(tup);
/*
* In inheritance situations, it is possible that the given tuple actually
bits8 *bp = tup->t_bits; /* ptr to null bitmap in tuple */
bool slow = false; /* can we use/set attcacheoff? */
- natts = tup->t_natts;
+ natts = HeapTupleHeaderGetNatts(tup);
/*
* In inheritance situations, it is possible that the given tuple actually
* than the tupdesc.)
*/
tup = tuple->t_data;
- if (attnum > tup->t_natts)
+ if (attnum > HeapTupleHeaderGetNatts(tup))
{
*isnull = true;
return (Datum) 0;
/*
* load up any slots available from physical tuple
*/
- attnum = tuple->t_data->t_natts;
+ attnum = HeapTupleHeaderGetNatts(tuple->t_data);
attnum = Min(attnum, tdesc_natts);
slot_deform_tuple(slot, attnum);
/*
* load up any slots available from physical tuple
*/
- attno = tuple->t_data->t_natts;
+ attno = HeapTupleHeaderGetNatts(tuple->t_data);
attno = Min(attno, attnum);
slot_deform_tuple(slot, attno);
* And fill in the information.
*/
tuple->t_len = len;
- tuple->t_natts = numberOfAttributes;
+ HeapTupleHeaderSetNatts(tuple, numberOfAttributes);
tuple->t_hoff = hoff + MINIMAL_TUPLE_OFFSET;
if (tupleDescriptor->tdhasoid) /* else leave infomask = 0 */
result->t_tableOid = InvalidOid;
result->t_data = (HeapTupleHeader) ((char *) result + HEAPTUPLESIZE);
memcpy((char *) result->t_data + MINIMAL_TUPLE_OFFSET, mtup, mtup->t_len);
- memset(result->t_data, 0, offsetof(HeapTupleHeaderData, t_natts));
+ memset(result->t_data, 0, offsetof(HeapTupleHeaderData, t_infomask2));
return result;
}
/* we don't bother to fill the Datum fields */
- td->t_natts = natts;
+ HeapTupleHeaderSetNatts(td, natts);
td->t_hoff = hoff;
if (withoid) /* else leave infomask = 0 */
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.223 2007/01/05 22:19:22 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.224 2007/01/09 22:00:59 momjian Exp $
*
*
* INTERFACE ROUTINES
rdata[0].buffer = InvalidBuffer;
rdata[0].next = &(rdata[1]);
- xlhdr.t_natts = heaptup->t_data->t_natts;
+ xlhdr.t_infomask2 = heaptup->t_data->t_infomask2;
xlhdr.t_infomask = heaptup->t_data->t_infomask;
xlhdr.t_hoff = heaptup->t_data->t_hoff;
rdata[1].buffer_std = true;
rdata[1].next = &(rdata[2]);
- xlhdr.hdr.t_natts = newtup->t_data->t_natts;
+ xlhdr.hdr.t_infomask2 = newtup->t_data->t_infomask2;
xlhdr.hdr.t_infomask = newtup->t_data->t_infomask;
xlhdr.hdr.t_hoff = newtup->t_data->t_hoff;
if (move) /* remember xmax & xmin */
(char *) xlrec + SizeOfHeapInsert + SizeOfHeapHeader,
newlen);
newlen += offsetof(HeapTupleHeaderData, t_bits);
- htup->t_natts = xlhdr.t_natts;
+ htup->t_infomask2 = xlhdr.t_infomask2;
htup->t_infomask = xlhdr.t_infomask;
htup->t_hoff = xlhdr.t_hoff;
HeapTupleHeaderSetXmin(htup, record->xl_xid);
(char *) xlrec + hsize,
newlen);
newlen += offsetof(HeapTupleHeaderData, t_bits);
- htup->t_natts = xlhdr.t_natts;
+ htup->t_infomask2 = xlhdr.t_infomask2;
htup->t_infomask = xlhdr.t_infomask;
htup->t_hoff = xlhdr.t_hoff;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.168 2007/01/05 22:19:29 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.169 2007/01/09 22:00:59 momjian Exp $
*
*-------------------------------------------------------------------------
*/
SPI_result = 0;
- if (fnumber > tuple->t_data->t_natts || fnumber == 0 ||
+ if (fnumber > HeapTupleHeaderGetNatts(tuple->t_data) || fnumber == 0 ||
fnumber <= FirstLowInvalidHeapAttributeNumber)
{
SPI_result = SPI_ERROR_NOATTRIBUTE;
{
SPI_result = 0;
- if (fnumber > tuple->t_data->t_natts || fnumber == 0 ||
+ if (fnumber > HeapTupleHeaderGetNatts(tuple->t_data) || fnumber == 0 ||
fnumber <= FirstLowInvalidHeapAttributeNumber)
{
SPI_result = SPI_ERROR_NOATTRIBUTE;
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.118 2007/01/05 22:19:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.119 2007/01/09 22:01:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
( \
((attnum) > 0) ? \
( \
- ((attnum) > (int) (tup)->t_data->t_natts) ? \
+ ((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \
( \
(((isnull) != NULL) ? (*(isnull) = true) : (dummyret)NULL), \
(Datum)NULL \
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.88 2007/01/05 22:19:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.89 2007/01/09 22:01:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/* Fields below here must match MinimalTupleData! */
- int16 t_natts; /* number of attributes */
+ uint16 t_infomask2; /* number of attributes + various flags */
uint16 t_infomask; /* various flag bits, see below */
#define HEAP_XACT_MASK 0xFFC0 /* visibility-related bits */
+/* information stored in t_infomask2, and accessor macros */
+#define HEAP_NATTS_MASK 0x7FF /* 11 bits for number of attributes */
+/* bits 0xF800 are unused */
+
+#define HeapTupleHeaderGetNatts(tup) ((tup)->t_infomask2 & HEAP_NATTS_MASK)
+#define HeapTupleHeaderSetNatts(tup, natts) \
+( \
+ (tup)->t_infomask2 = ((tup)->t_infomask2 & ~HEAP_NATTS_MASK) | (natts) \
+)
/*
* HeapTupleHeader accessor macros
* and thereby prevent accidental use of the nonexistent fields.
*
* MinimalTupleData contains a length word, some padding, and fields matching
- * HeapTupleHeaderData beginning with t_natts. The padding is chosen so that
- * offsetof(t_natts) is the same modulo MAXIMUM_ALIGNOF in both structs.
+ * HeapTupleHeaderData beginning with t_infomask2. The padding is chosen so that
+ * offsetof(t_infomask2) is the same modulo MAXIMUM_ALIGNOF in both structs.
* This makes data alignment rules equivalent in both cases.
*
* When a minimal tuple is accessed via a HeapTupleData pointer, t_data is
* the MINIMAL_TUPLE_OFFSET distance. t_len does not include that, however.
*/
#define MINIMAL_TUPLE_OFFSET \
- ((offsetof(HeapTupleHeaderData, t_natts) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)
+ ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)
#define MINIMAL_TUPLE_PADDING \
- ((offsetof(HeapTupleHeaderData, t_natts) - sizeof(uint32)) % MAXIMUM_ALIGNOF)
+ ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF)
typedef struct MinimalTupleData
{
/* Fields below here must match HeapTupleHeaderData! */
- int16 t_natts; /* number of attributes */
+ uint16 t_infomask2; /* number of attributes + various flags */
uint16 t_infomask; /* various flag bits, see below */
*/
typedef struct xl_heap_header
{
- int16 t_natts;
+ uint16 t_infomask2;
uint16 t_infomask;
uint8 t_hoff;
} xl_heap_header;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.182 2007/01/05 22:20:02 momjian Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.183 2007/01/09 22:01:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* Row is a bit more complicated in that we assign the individual
* attributes of the tuple to the variables the row points to.
*
- * NOTE: this code used to demand row->nfields == tup->t_data->t_natts,
+ * NOTE: this code used to demand row->nfields == HeapTupleHeaderGetNatts(tup->t_data,
* but that's wrong. The tuple might have more fields than we expected if
* it's from an inheritance-child table of the current table, or it might
* have fewer if the table has had columns added by ALTER TABLE. Ignore
int anum;
if (HeapTupleIsValid(tup))
- t_natts = tup->t_data->t_natts;
+ t_natts = HeapTupleHeaderGetNatts(tup->t_data);
else
t_natts = 0;