77 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
10- * $Id: htup.h,v 1.51 2001/11/05 17:46:31 momjian Exp $
10+ * $Id: htup.h,v 1.52 2002/05/27 19:53:33 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
1717#include "storage/bufpage.h"
1818#include "storage/relfilenode.h"
1919
20- #define MinHeapTupleBitmapSize 32/* 8 * 4 */
2120
2221/*
23- *MaxHeapAttributeNumber limits the number of (user) columns in atable .
22+ *MaxTupleAttributeNumber limits the number of (user) columns in atuple .
2423 * The key limit on this value is that the size of the fixed overhead for
2524 * a tuple, plus the size of the null-values bitmap (at 1 bit per column),
2625 * 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.
26+ * machines the upper limit without making t_hoff wider would be a little
27+ * over 1700. We use round numbers here and for MaxHeapAttributeNumber
28+ * so that alterations in HeapTupleHeaderData layout won't change the
29+ * supported max number of columns.
30+ */
31+ #define MaxTupleAttributeNumber 1664/* 8 * 208 */
32+
33+ /*----------
34+ * MaxHeapAttributeNumber limits the number of (user) columns in a table.
35+ * This should be somewhat less than MaxTupleAttributeNumber. It must be
36+ * at least one less, else we will fail to do UPDATEs on a maximal-width
37+ * table (because UPDATE has to form working tuples that include CTID).
38+ * In practice we want some additional daylight so that we can gracefully
39+ * support operations that add hidden "resjunk" columns, for example
40+ * SELECT * FROM wide_table ORDER BY foo, bar, baz.
41+ * In any case, depending on column data types you will likely be running
42+ * into the disk-block-based limit on overall tuple size if you have more
43+ * than a thousand or so columns. TOAST won't help.
44+ *----------
3145 */
3246#define MaxHeapAttributeNumber 1600/* 8 * 200 */
3347
3448/*
35- * This is the on-disk copy of the tuple.
49+ * On-disk heap tuple header. Currently this is also used as the header
50+ * format for tuples formed in memory, although in principle they could
51+ * be different.
3652 *
3753 * To avoid wasting space, the attributes should be layed out in such a
38- * way to reduce structure padding.
54+ * way to reduce structure padding. Note that t_hoff is the offset to
55+ * the start of the user data, and so must be a multiple of MAXALIGN.
56+ * Also note that we omit the nulls bitmap if t_infomask shows that there
57+ * are no nulls in the tuple.
3958 */
4059typedef struct HeapTupleHeaderData
4160{
@@ -51,14 +70,13 @@ typedef struct HeapTupleHeaderData
5170
5271int16 t_natts ;/* number of attributes */
5372
54- uint16 t_infomask ;/* variousinfos */
73+ uint16 t_infomask ;/* variousflag bits, see below */
5574
56- uint8 t_hoff ;/* sizeof() tuple header */
75+ uint8 t_hoff ;/* sizeof header incl. bitmap, padding */
5776
5877/* ^ - 31 bytes - ^ */
5978
60- bits8 t_bits [MinHeapTupleBitmapSize /8 ];
61- /* bit map of NULLs */
79+ bits8 t_bits [1 ];/* bitmap of NULLs -- VARIABLE LENGTH */
6280
6381/* MORE DATA FOLLOWS AT END OF STRUCT */
6482}HeapTupleHeaderData ;
@@ -183,7 +201,7 @@ typedef struct xl_heap_clean
183201#define FirstLowInvalidHeapAttributeNumber (-8)
184202
185203/*
186- *This isthe in-memorycopy of the tuple.
204+ *HeapTupleData isan in-memorydata structure that points to a tuple.
187205 *
188206 * This new HeapTuple for version >= 6.5 and this is why it was changed:
189207 *
@@ -222,11 +240,9 @@ typedef HeapTupleData *HeapTuple;
222240
223241/*
224242 * BITMAPLEN(NATTS) -
225- *Computesminimum size of bitmap given number ofdomains .
243+ *Computes size ofnull bitmap given number ofdata columns .
226244 */
227- #define BITMAPLEN (NATTS ) \
228- ((((((int)(NATTS) - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) \
229- & ~03) + (MinHeapTupleBitmapSize >> 3))
245+ #define BITMAPLEN (NATTS )(((int)(NATTS) + 7) / 8)
230246
231247/*
232248 * HeapTupleIsValid
@@ -240,26 +256,26 @@ typedef HeapTupleData *HeapTuple;
240256#define HEAP_HASNULL 0x0001/* has null attribute(s) */
241257#define HEAP_HASVARLENA 0x0002/* has variable length
242258 * attribute(s) */
243- #define HEAP_HASEXTERNAL 0x0004/* has external stored */
244- / * attribute(s) */
245- #define HEAP_HASCOMPRESSED 0x0008/* has compressed stored */
246- / * attribute(s) */
259+ #define HEAP_HASEXTERNAL 0x0004/* has external stored
260+ * attribute(s) */
261+ #define HEAP_HASCOMPRESSED 0x0008/* has compressed stored
262+ * attribute(s) */
247263#define HEAP_HASEXTENDED 0x000C/* the two above combined */
248264
249- #define HEAP_XMAX_UNLOGGED 0x0080/* to lock tuple for update */
250- / * without logging */
265+ #define HEAP_XMAX_UNLOGGED 0x0080/* to lock tuple for update
266+ * without logging */
251267#define HEAP_XMIN_COMMITTED 0x0100/* t_xmin committed */
252268#define HEAP_XMIN_INVALID 0x0200/* t_xmin invalid/aborted */
253269#define HEAP_XMAX_COMMITTED 0x0400/* t_xmax committed */
254270#define HEAP_XMAX_INVALID 0x0800/* t_xmax invalid/aborted */
255271#define HEAP_MARKED_FOR_UPDATE 0x1000/* marked for UPDATE */
256272#define HEAP_UPDATED 0x2000/* this is UPDATEd version of row */
257- #define HEAP_MOVED_OFF 0x4000/*removed or moved to another
258- *place by vacuum */
273+ #define HEAP_MOVED_OFF 0x4000/* moved to another place by
274+ * vacuum */
259275#define HEAP_MOVED_IN 0x8000/* moved from another place by
260276 * vacuum */
261277
262- #define HEAP_XACT_MASK 0xFFF0/* */
278+ #define HEAP_XACT_MASK 0xFFF0/*visibility-related bits */
263279
264280#define HeapTupleNoNulls (tuple ) \
265281(!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))