1 /*-------------------------------------------------------------------------
4 * POSTGRES heap tuple definitions.
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: htup.h,v 1.35 2000/09/07 09:58:35 vadim Exp $
12 *-------------------------------------------------------------------------
17 #include "storage/bufpage.h"
18 #include "storage/relfilenode.h"
20 #define MinHeapTupleBitmapSize 32 /* 8 * 4 */
23 * MaxHeapAttributeNumber limits the number of (user) columns in a table.
24 * The key limit on this value is that the size of the fixed overhead for
25 * a tuple, plus the size of the null-values bitmap (at 1 bit per column),
26 * plus MAXALIGN alignment, must fit into t_hoff which is uint8. On most
27 * machines the absolute upper limit without making t_hoff wider would be
28 * about 1700. Note, however, that depending on column data types you will
29 * likely also be running into the disk-block-based limit on overall tuple
30 * size if you have more than a thousand or so columns. TOAST won't help.
32 #define MaxHeapAttributeNumber 1600 /* 8 * 200 */
35 * to avoid wasting space, the attributes should be layed out in such a
36 * way to reduce structure padding.
38 typedef struct HeapTupleHeaderData
40 Oid t_oid; /* OID of this tuple -- 4 bytes */
42 CommandId t_cmin; /* insert CID stamp -- 4 bytes each */
43 CommandId t_cmax; /* delete CommandId stamp */
45 TransactionId t_xmin; /* insert XID stamp -- 4 bytes each */
46 TransactionId t_xmax; /* delete XID stamp */
48 ItemPointerData t_ctid; /* current TID of this or newer tuple */
50 int16 t_natts; /* number of attributes */
52 uint16 t_infomask; /* various infos */
54 uint8 t_hoff; /* sizeof tuple header */
56 /* ^ - 31 bytes - ^ */
58 bits8 t_bits[MinHeapTupleBitmapSize / 8];
59 /* bit map of domains */
61 /* MORE DATA FOLLOWS AT END OF STRUCT */
62 } HeapTupleHeaderData;
64 typedef HeapTupleHeaderData *HeapTupleHeader;
72 * XLOG allows to store some information in high 4 bits of log
73 * record xl_info field
75 #define XLOG_HEAP_INSERT 0x00
76 #define XLOG_HEAP_DELETE 0x10
77 #define XLOG_HEAP_UPDATE 0x20
78 #define XLOG_HEAP_MOVE 0x30
81 * All what we need to find changed tuple (18 bytes)
83 typedef struct xl_heaptid
86 CommandId cid; /* this is for "better" tuple' */
87 /* identification - it allows to avoid */
88 /* "compensation" records for undo */
89 ItemPointerData tid; /* changed tuple id */
92 /* This is what we need to know about delete - ALIGN(18) = 24 bytes */
93 typedef struct xl_heap_delete
95 xl_heaptid target; /* deleted tuple id */
98 #define SizeOfHeapDelete (offsetof(xl_heaptid, tid) + SizeOfIptrData))
100 /* This is what we need to know about insert - 26 + data */
101 typedef struct xl_heap_insert
103 xl_heaptid target; /* inserted tuple id */
104 /* something from tuple header */
108 uint8 mask; /* low 8 bits of t_infomask */
109 /* TUPLE DATA FOLLOWS AT END OF STRUCT */
112 #define SizeOfHeapInsert (offsetof(xl_heap_insert, mask) + sizeof(uint8))
114 /* This is what we need to know about update - 28 + data */
115 typedef struct xl_heap_update
117 xl_heaptid target; /* deleted tuple id */
118 ItemPointerData newtid; /* new inserted tuple id */
119 /* something from header of new tuple version */
122 uint8 mask; /* low 8 bits of t_infomask */
123 /* NEW TUPLE DATA FOLLOWS AT END OF STRUCT */
126 #define SizeOfHeapUpdate (offsetof(xl_heap_update, mask) + sizeof(uint8))
128 /* This is what we need to know about tuple move - 24 bytes */
129 typedef struct xl_heap_move
131 xl_heaptid target; /* moved from */
132 ItemPointerData newtid; /* moved to */
135 #define SizeOfHeapMove (offsetof(xl_heap_move, ttid) + SizeOfIptrData))
137 /* end of XLOG stuff */
143 * MaxTupleSize is the maximum allowed size of a tuple, including header and
144 * MAXALIGN alignment padding. Basically it's BLCKSZ minus the other stuff
145 * that has to be on a disk page. The "other stuff" includes access-method-
146 * dependent "special space", which we assume will be no more than
147 * MaxSpecialSpace bytes (currently, on heap pages it's actually zero).
149 * NOTE: we do not need to count an ItemId for the tuple because
150 * sizeof(PageHeaderData) includes the first ItemId on the page.
152 #define MaxSpecialSpace 32
154 #define MaxTupleSize \
155 (BLCKSZ - MAXALIGN(sizeof(PageHeaderData) + MaxSpecialSpace))
159 * MaxAttrSize is a somewhat arbitrary upper limit on the declared size of
160 * data fields of char(n) and similar types. It need not have anything
161 * directly to do with the *actual* upper limit of varlena values, which
162 * is currently 1Gb (see struct varattrib in postgres.h). I've set it
163 * at 10Mb which seems like a reasonable number --- tgl 8/6/00.
165 #define MaxAttrSize (10 * 1024 * 1024)
168 #define SelfItemPointerAttributeNumber (-1)
169 #define ObjectIdAttributeNumber (-2)
170 #define MinTransactionIdAttributeNumber (-3)
171 #define MinCommandIdAttributeNumber (-4)
172 #define MaxTransactionIdAttributeNumber (-5)
173 #define MaxCommandIdAttributeNumber (-6)
174 #define TableOidAttributeNumber (-7)
175 #define FirstLowInvalidHeapAttributeNumber (-8)
177 /* If you make any changes above, the order off offsets in this must change */
178 extern long heap_sysoffset[];
181 * This new HeapTuple for version >= 6.5 and this is why it was changed:
183 * 1. t_len moved off on-disk tuple data - ItemIdData is used to get len;
184 * 2. t_ctid above is not self tuple TID now - it may point to
185 * updated version of tuple (required by MVCC);
186 * 3. someday someone let tuple to cross block boundaries -
187 * he have to add something below...
190 * Up to now t_data could be NULL, the memory location directly following
191 * HeapTupleData or pointing into a buffer. Now, it could also point to
192 * a separate allocation that was done in the t_datamcxt memory context.
194 typedef struct HeapTupleData
196 uint32 t_len; /* length of *t_data */
197 ItemPointerData t_self; /* SelfItemPointer */
199 MemoryContext t_datamcxt; /* */
200 HeapTupleHeader t_data; /* */
203 typedef HeapTupleData *HeapTuple;
205 #define HEAPTUPLESIZE MAXALIGN(sizeof(HeapTupleData))
212 #define GETSTRUCT(TUP) (((char *)((HeapTuple)(TUP))->t_data) + \
213 ((HeapTuple)(TUP))->t_data->t_hoff)
218 * Computes minimum size of bitmap given number of domains.
220 #define BITMAPLEN(NATTS) \
221 ((((((int)(NATTS) - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) \
222 & ~03) + (MinHeapTupleBitmapSize >> 3))
226 * True iff the heap tuple is valid.
228 #define HeapTupleIsValid(tuple) PointerIsValid(tuple)
231 * information stored in t_infomask:
233 #define HEAP_HASNULL 0x0001 /* has null attribute(s) */
234 #define HEAP_HASVARLENA 0x0002 /* has variable length
236 #define HEAP_HASEXTERNAL 0x0004 /* has external stored */
238 #define HEAP_HASCOMPRESSED 0x0008 /* has compressed stored */
240 #define HEAP_HASEXTENDED 0x000C /* the two above combined */
242 #define HEAP_XMAX_UNLOGGED 0x0080 /* to lock tuple for update */
243 /* without logging */
244 #define HEAP_XMIN_COMMITTED 0x0100 /* t_xmin committed */
245 #define HEAP_XMIN_INVALID 0x0200 /* t_xmin invalid/aborted */
246 #define HEAP_XMAX_COMMITTED 0x0400 /* t_xmax committed */
247 #define HEAP_XMAX_INVALID 0x0800 /* t_xmax invalid/aborted */
248 #define HEAP_MARKED_FOR_UPDATE 0x1000 /* marked for UPDATE */
249 #define HEAP_UPDATED 0x2000 /* this is UPDATEd version of row */
250 #define HEAP_MOVED_OFF 0x4000 /* removed or moved to another
252 #define HEAP_MOVED_IN 0x8000 /* moved from another place by
255 #define HEAP_XACT_MASK 0xFFF0 /* */
257 #define HeapTupleNoNulls(tuple) \
258 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
260 #define HeapTupleAllFixed(tuple) \
261 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA))
263 #define HeapTupleHasExternal(tuple) \
264 ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)
266 #define HeapTupleHasCompressed(tuple) \
267 ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASCOMPRESSED) != 0)
269 #define HeapTupleHasExtended(tuple) \
270 ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTENDED) != 0)