1 /*-------------------------------------------------------------------------
4 * POSTGRES heap tuple definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: htup.h,v 1.27 1999/12/21 00:06:42 wieck 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...
83 * Up to now t_data could be NULL, the memory location directly following
84 * HeapTupleData or pointing into a buffer. Now, it could also point to
85 * a separate allocation that was done in the t_datamcxt memory context.
87 typedef struct HeapTupleData
89 uint32 t_len; /* length of *t_data */
90 ItemPointerData t_self; /* SelfItemPointer */
91 MemoryContext t_datamcxt; /* */
92 HeapTupleHeader t_data; /* */
95 typedef HeapTupleData *HeapTuple;
97 #define HEAPTUPLESIZE MAXALIGN(sizeof(HeapTupleData))
104 #define GETSTRUCT(TUP) (((char *)((HeapTuple)(TUP))->t_data) + \
105 ((HeapTuple)(TUP))->t_data->t_hoff)
110 * Computes minimum size of bitmap given number of domains.
112 #define BITMAPLEN(NATTS) \
113 ((((((int)(NATTS) - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) \
114 & ~03) + (MinHeapTupleBitmapSize >> 3))
118 * True iff the heap tuple is valid.
120 #define HeapTupleIsValid(tuple) PointerIsValid(tuple)
123 * information stored in t_infomask:
125 #define HEAP_HASNULL 0x0001 /* has null attribute(s) */
126 #define HEAP_HASVARLENA 0x0002 /* has variable length
128 #define HEAP_HASEXTERNAL 0x0004 /* has external stored */
130 #define HEAP_HASCOMPRESSED 0x0008 /* has compressed stored */
132 #define HEAP_HASEXTENDED 0x000C /* the two above combined */
133 #define HEAP_XMIN_COMMITTED 0x0100 /* t_xmin committed */
134 #define HEAP_XMIN_INVALID 0x0200 /* t_xmin invalid/aborted */
135 #define HEAP_XMAX_COMMITTED 0x0400 /* t_xmax committed */
136 #define HEAP_XMAX_INVALID 0x0800 /* t_xmax invalid/aborted */
137 #define HEAP_MARKED_FOR_UPDATE 0x1000 /* marked for UPDATE */
138 #define HEAP_UPDATED 0x2000 /* this is UPDATEd version of row */
139 #define HEAP_MOVED_OFF 0x4000 /* removed or moved to another
141 #define HEAP_MOVED_IN 0x8000 /* moved from another place by
144 #define HEAP_XACT_MASK 0xFF00 /* */
146 #define HeapTupleNoNulls(tuple) \
147 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
149 #define HeapTupleAllFixed(tuple) \
150 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA))
152 #define HeapTupleHasExternal(tuple) \
153 ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)
155 #define HeapTupleHasCompressed(tuple) \
156 ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASCOMPRESSED) != 0)
158 #define HeapTupleHasExtended(tuple) \
159 ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTENDED) != 0)