]> granicus.if.org Git - postgresql/blob - src/include/access/htup.h
f105dafee27f530f5a3318879bb88e1dd5610c51
[postgresql] / src / include / access / htup.h
1  /*-------------------------------------------------------------------------
2  *
3  * htup.h
4  *        POSTGRES heap tuple definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: htup.h,v 1.35 2000/09/07 09:58:35 vadim Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef HTUP_H
15 #define HTUP_H
16
17 #include "storage/bufpage.h"
18 #include "storage/relfilenode.h"
19
20 #define MinHeapTupleBitmapSize  32              /* 8 * 4 */
21
22 /*
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.
31  */
32 #define MaxHeapAttributeNumber  1600    /* 8 * 200 */
33
34 /*
35  * to avoid wasting space, the attributes should be layed out in such a
36  * way to reduce structure padding.
37  */
38 typedef struct HeapTupleHeaderData
39 {
40         Oid                     t_oid;                  /* OID of this tuple -- 4 bytes */
41
42         CommandId       t_cmin;                 /* insert CID stamp -- 4 bytes each */
43         CommandId       t_cmax;                 /* delete CommandId stamp */
44
45         TransactionId t_xmin;           /* insert XID stamp -- 4 bytes each */
46         TransactionId t_xmax;           /* delete XID stamp */
47
48         ItemPointerData t_ctid;         /* current TID of this or newer tuple */
49
50         int16           t_natts;                /* number of attributes */
51
52         uint16          t_infomask;             /* various infos */
53
54         uint8           t_hoff;                 /* sizeof tuple header */
55
56                                                                 /* ^ - 31 bytes - ^ */
57
58         bits8           t_bits[MinHeapTupleBitmapSize / 8];
59         /* bit map of domains */
60
61         /* MORE DATA FOLLOWS AT END OF STRUCT */
62 } HeapTupleHeaderData;
63
64 typedef HeapTupleHeaderData *HeapTupleHeader;
65
66
67 #ifdef XLOG
68
69 /* XLOG stuff */
70
71 /*
72  * XLOG allows to store some information in high 4 bits of log
73  * record xl_info field
74  */
75 #define XLOG_HEAP_INSERT        0x00
76 #define XLOG_HEAP_DELETE        0x10
77 #define XLOG_HEAP_UPDATE        0x20
78 #define XLOG_HEAP_MOVE          0x30
79
80 /*
81  * All what we need to find changed tuple (18 bytes)
82  */
83 typedef struct xl_heaptid
84 {
85         RelFileNode                     node;
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 */
90 } xl_heaptid;
91
92 /* This is what we need to know about delete - ALIGN(18) = 24 bytes */
93 typedef struct xl_heap_delete
94 {
95         xl_heaptid                      target;         /* deleted tuple id */
96 } xl_heap_delete;
97
98 #define SizeOfHeapDelete        (offsetof(xl_heaptid, tid) + SizeOfIptrData))
99
100 /* This is what we need to know about insert - 26 + data */
101 typedef struct xl_heap_insert
102 {
103         xl_heaptid                      target;         /* inserted tuple id */
104         /* something from tuple header */
105         int16                           t_natts;
106         Oid                                     t_oid;
107         uint8                           t_hoff;
108         uint8                           mask;           /* low 8 bits of t_infomask */
109         /* TUPLE DATA FOLLOWS AT END OF STRUCT */
110 } xl_heap_insert;
111
112 #define SizeOfHeapInsert        (offsetof(xl_heap_insert, mask) + sizeof(uint8))
113
114 /* This is what we need to know about update - 28 + data */
115 typedef struct xl_heap_update
116 {
117         xl_heaptid                      target;         /* deleted tuple id */
118         ItemPointerData         newtid;         /* new inserted tuple id */
119         /* something from header of new tuple version */
120         int16                           t_natts;
121         uint8                           t_hoff;
122         uint8                           mask;           /* low 8 bits of t_infomask */
123         /* NEW TUPLE DATA FOLLOWS AT END OF STRUCT */
124 } xl_heap_update;
125
126 #define SizeOfHeapUpdate        (offsetof(xl_heap_update, mask) + sizeof(uint8))
127
128 /* This is what we need to know about tuple move - 24 bytes */
129 typedef struct xl_heap_move
130 {
131         xl_heaptid                      target;         /* moved from */
132         ItemPointerData         newtid;         /* moved to */
133 } xl_heap_move;
134
135 #define SizeOfHeapMove  (offsetof(xl_heap_move, ttid) + SizeOfIptrData))
136
137 /* end of XLOG stuff */
138
139 #endif  /* XLOG */
140
141
142 /*
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).
148  *
149  * NOTE: we do not need to count an ItemId for the tuple because
150  * sizeof(PageHeaderData) includes the first ItemId on the page.
151  */
152 #define MaxSpecialSpace  32
153
154 #define MaxTupleSize    \
155         (BLCKSZ - MAXALIGN(sizeof(PageHeaderData) + MaxSpecialSpace))
156
157
158 /*
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.
164  */
165 #define MaxAttrSize             (10 * 1024 * 1024)
166
167
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)
176
177 /* If you make any changes above, the order off offsets in this must change */
178 extern long heap_sysoffset[];
179
180 /*
181  * This new HeapTuple for version >= 6.5 and this is why it was changed:
182  *
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...
188  *
189  * Change for 7.0:
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.
193  */
194 typedef struct HeapTupleData
195 {
196         uint32          t_len;                  /* length of *t_data */
197         ItemPointerData t_self;         /* SelfItemPointer */
198         Oid tableOid;                    /* */
199         MemoryContext t_datamcxt;       /* */
200         HeapTupleHeader t_data;         /* */
201 } HeapTupleData;
202
203 typedef HeapTupleData *HeapTuple;
204
205 #define HEAPTUPLESIZE   MAXALIGN(sizeof(HeapTupleData))
206
207
208 /* ----------------
209  *              support macros
210  * ----------------
211  */
212 #define GETSTRUCT(TUP) (((char *)((HeapTuple)(TUP))->t_data) + \
213                                                 ((HeapTuple)(TUP))->t_data->t_hoff)
214
215
216 /*
217  * BITMAPLEN(NATTS) -
218  *              Computes minimum size of bitmap given number of domains.
219  */
220 #define BITMAPLEN(NATTS) \
221                 ((((((int)(NATTS) - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) \
222                   & ~03) + (MinHeapTupleBitmapSize >> 3))
223
224 /*
225  * HeapTupleIsValid
226  *              True iff the heap tuple is valid.
227  */
228 #define HeapTupleIsValid(tuple) PointerIsValid(tuple)
229
230 /*
231  * information stored in t_infomask:
232  */
233 #define HEAP_HASNULL                    0x0001  /* has null attribute(s) */
234 #define HEAP_HASVARLENA                 0x0002  /* has variable length
235                                                                                  * attribute(s) */
236 #define HEAP_HASEXTERNAL                0x0004  /* has external stored */
237  /* attribute(s) */
238 #define HEAP_HASCOMPRESSED              0x0008  /* has compressed stored */
239  /* attribute(s) */
240 #define HEAP_HASEXTENDED                0x000C  /* the two above combined */
241
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
251                                                                                  * place by vacuum */
252 #define HEAP_MOVED_IN                   0x8000  /* moved from another place by
253                                                                                  * vacuum */
254
255 #define HEAP_XACT_MASK                  0xFFF0  /* */
256
257 #define HeapTupleNoNulls(tuple) \
258                 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
259
260 #define HeapTupleAllFixed(tuple) \
261                 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA))
262
263 #define HeapTupleHasExternal(tuple) \
264                 ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)
265
266 #define HeapTupleHasCompressed(tuple) \
267                 ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASCOMPRESSED) != 0)
268
269 #define HeapTupleHasExtended(tuple) \
270                 ((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTENDED) != 0)
271
272 #endif   /* HTUP_H */