1 /*-------------------------------------------------------------------------
4 * POSTGRES heap tuple definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: htup.h,v 1.23 1999/07/15 15:20:54 momjian Exp $
11 *-------------------------------------------------------------------------
16 #include <storage/bufpage.h>
18 #define MinHeapTupleBitmapSize 32 /* 8 * 4 */
20 /* check these, they are likely to be more severely limited by t_hoff */
22 #define MaxHeapAttributeNumber 1600 /* 8 * 200 */
25 * to avoid wasting space, the attributes should be layed out in such a
26 * way to reduce structure padding.
28 typedef struct HeapTupleHeaderData
30 Oid t_oid; /* OID of this tuple -- 4 bytes */
32 CommandId t_cmin; /* insert CID stamp -- 4 bytes each */
33 CommandId t_cmax; /* delete CommandId stamp */
35 TransactionId t_xmin; /* insert XID stamp -- 4 bytes each */
36 TransactionId t_xmax; /* delete XID stamp */
38 ItemPointerData t_ctid; /* current TID of this or newer tuple */
40 int16 t_natts; /* number of attributes */
42 uint16 t_infomask; /* various infos */
44 uint8 t_hoff; /* sizeof tuple header */
46 bits8 t_bits[MinHeapTupleBitmapSize / 8];
47 /* bit map of domains */
49 /* MORE DATA FOLLOWS AT END OF STRUCT */
50 } HeapTupleHeaderData;
52 typedef HeapTupleHeaderData *HeapTupleHeader;
54 #define MinTupleSize (MAXALIGN(sizeof (PageHeaderData)) + \
55 MAXALIGN(sizeof(HeapTupleHeaderData)) + \
56 MAXALIGN(sizeof(char)))
58 #define MaxTupleSize (BLCKSZ - MinTupleSize)
60 #define MaxAttrSize (MaxTupleSize - MAXALIGN(sizeof(HeapTupleHeaderData)))
62 #define SelfItemPointerAttributeNumber (-1)
63 #define ObjectIdAttributeNumber (-2)
64 #define MinTransactionIdAttributeNumber (-3)
65 #define MinCommandIdAttributeNumber (-4)
66 #define MaxTransactionIdAttributeNumber (-5)
67 #define MaxCommandIdAttributeNumber (-6)
68 #define FirstLowInvalidHeapAttributeNumber (-7)
70 /* If you make any changes above, the order off offsets in this must change */
71 extern long heap_sysoffset[];
74 * This new HeapTuple for version >= 6.5 and this is why it was changed:
76 * 1. t_len moved off on-disk tuple data - ItemIdData is used to get len;
77 * 2. t_ctid above is not self tuple TID now - it may point to
78 * updated version of tuple (required by MVCC);
79 * 3. someday someone let tuple to cross block boundaries -
80 * he have to add something below...
82 typedef struct HeapTupleData
84 uint32 t_len; /* length of *t_data */
85 ItemPointerData t_self; /* SelfItemPointer */
86 HeapTupleHeader t_data; /* */
89 typedef HeapTupleData *HeapTuple;
91 #define HEAPTUPLESIZE DOUBLEALIGN(sizeof(HeapTupleData))
98 #define GETSTRUCT(TUP) (((char *)((HeapTuple)(TUP))->t_data) + \
99 ((HeapTuple)(TUP))->t_data->t_hoff)
104 * Computes minimum size of bitmap given number of domains.
106 #define BITMAPLEN(NATTS) \
107 ((((((int)(NATTS) - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) \
108 & ~03) + (MinHeapTupleBitmapSize >> 3))
112 * True iff the heap tuple is valid.
114 #define HeapTupleIsValid(tuple) PointerIsValid(tuple)
117 * information stored in t_infomask:
119 #define HEAP_HASNULL 0x0001 /* has null attribute(s) */
120 #define HEAP_HASVARLENA 0x0002 /* has variable length
122 #define HEAP_XMIN_COMMITTED 0x0100 /* t_xmin committed */
123 #define HEAP_XMIN_INVALID 0x0200 /* t_xmin invalid/aborted */
124 #define HEAP_XMAX_COMMITTED 0x0400 /* t_xmax committed */
125 #define HEAP_XMAX_INVALID 0x0800 /* t_xmax invalid/aborted */
126 #define HEAP_MARKED_FOR_UPDATE 0x1000 /* marked for UPDATE */
127 #define HEAP_UPDATED 0x2000 /* this is UPDATEd version of row */
128 #define HEAP_MOVED_OFF 0x4000 /* removed or moved to another
130 #define HEAP_MOVED_IN 0x8000 /* moved from another place by
133 #define HEAP_XACT_MASK 0xFF00 /* */
135 #define HeapTupleNoNulls(tuple) \
136 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
138 #define HeapTupleAllFixed(tuple) \
139 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA))