1 /*-------------------------------------------------------------------------
4 * POSTGRES heap tuple definitions.
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: htup.h,v 1.15 1999/05/25 16:13:31 momjian Exp $
11 *-------------------------------------------------------------------------
16 #include <utils/nabstime.h>
17 #include <storage/itemptr.h>
19 #define MinHeapTupleBitmapSize 32 /* 8 * 4 */
21 /* check these, they are likely to be more severely limited by t_hoff */
23 #define MaxHeapAttributeNumber 1600 /* 8 * 200 */
26 * to avoid wasting space, the attributes should be layed out in such a
27 * way to reduce structure padding.
29 typedef struct HeapTupleHeaderData
31 Oid t_oid; /* OID of this tuple -- 4 bytes */
33 CommandId t_cmin; /* insert CID stamp -- 4 bytes each */
34 CommandId t_cmax; /* delete CommandId stamp */
36 TransactionId t_xmin; /* insert XID stamp -- 4 bytes each */
37 TransactionId t_xmax; /* delete XID stamp */
39 ItemPointerData t_ctid; /* current TID of this or newer tuple */
41 int16 t_natts; /* number of attributes */
43 uint16 t_infomask; /* various infos */
45 uint8 t_hoff; /* sizeof tuple header */
47 bits8 t_bits[MinHeapTupleBitmapSize / 8];
48 /* bit map of domains */
50 /* MORE DATA FOLLOWS AT END OF STRUCT */
51 } HeapTupleHeaderData;
53 typedef HeapTupleHeaderData *HeapTupleHeader;
55 #define SelfItemPointerAttributeNumber (-1)
56 #define ObjectIdAttributeNumber (-2)
57 #define MinTransactionIdAttributeNumber (-3)
58 #define MinCommandIdAttributeNumber (-4)
59 #define MaxTransactionIdAttributeNumber (-5)
60 #define MaxCommandIdAttributeNumber (-6)
61 #define FirstLowInvalidHeapAttributeNumber (-7)
63 /* If you make any changes above, the order off offsets in this must change */
64 extern long heap_sysoffset[];
67 * This new HeapTuple for version >= 6.5 and this is why it was changed:
69 * 1. t_len moved off on-disk tuple data - ItemIdData is used to get len;
70 * 2. t_ctid above is not self tuple TID now - it may point to
71 * updated version of tuple (required by MVCC);
72 * 3. someday someone let tuple to cross block boundaries -
73 * he have to add something below...
75 typedef struct HeapTupleData
77 uint32 t_len; /* length of *t_data */
78 ItemPointerData t_self; /* SelfItemPointer */
79 HeapTupleHeader t_data; /* */
82 typedef HeapTupleData *HeapTuple;
84 #define HEAPTUPLESIZE DOUBLEALIGN(sizeof(HeapTupleData))
91 #define GETSTRUCT(TUP) (((char *)((HeapTuple)(TUP))->t_data) + \
92 ((HeapTuple)(TUP))->t_data->t_hoff)
97 * Computes minimum size of bitmap given number of domains.
99 #define BITMAPLEN(NATTS) \
100 ((((((int)(NATTS) - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) \
101 & ~03) + (MinHeapTupleBitmapSize >> 3))
105 * True iff the heap tuple is valid.
107 #define HeapTupleIsValid(tuple) PointerIsValid(tuple)
110 * information stored in t_infomask:
112 #define HEAP_HASNULL 0x0001 /* has null attribute(s) */
113 #define HEAP_HASVARLENA 0x0002 /* has variable length
115 #define HEAP_XMIN_COMMITTED 0x0100 /* t_xmin committed */
116 #define HEAP_XMIN_INVALID 0x0200 /* t_xmin invalid/aborted */
117 #define HEAP_XMAX_COMMITTED 0x0400 /* t_xmax committed */
118 #define HEAP_XMAX_INVALID 0x0800 /* t_xmax invalid/aborted */
119 #define HEAP_MARKED_FOR_UPDATE 0x1000 /* marked for UPDATE */
120 #define HEAP_UPDATED 0x2000 /* this is UPDATEd version of row */
121 #define HEAP_MOVED_OFF 0x4000 /* removed or moved to another
123 #define HEAP_MOVED_IN 0x8000 /* moved from another place by
126 #define HEAP_XACT_MASK 0xFF00 /* */
128 #define HeapTupleNoNulls(tuple) \
129 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
131 #define HeapTupleAllFixed(tuple) \
132 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA))