]> granicus.if.org Git - postgresql/blob - src/include/access/htup.h
pgindent run over code.
[postgresql] / src / include / access / htup.h
1 /*-------------------------------------------------------------------------
2  *
3  * htup.h
4  *        POSTGRES heap tuple definitions.
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: htup.h,v 1.15 1999/05/25 16:13:31 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef HTUP_H
14 #define HTUP_H
15
16 #include <utils/nabstime.h>
17 #include <storage/itemptr.h>
18
19 #define MinHeapTupleBitmapSize  32              /* 8 * 4 */
20
21 /* check these, they are likely to be more severely limited by t_hoff */
22
23 #define MaxHeapAttributeNumber  1600    /* 8 * 200 */
24
25 /*
26  * to avoid wasting space, the attributes should be layed out in such a
27  * way to reduce structure padding.
28  */
29 typedef struct HeapTupleHeaderData
30 {
31         Oid                     t_oid;                  /* OID of this tuple -- 4 bytes */
32
33         CommandId       t_cmin;                 /* insert CID stamp -- 4 bytes each */
34         CommandId       t_cmax;                 /* delete CommandId stamp */
35
36         TransactionId t_xmin;           /* insert XID stamp -- 4 bytes each */
37         TransactionId t_xmax;           /* delete XID stamp */
38
39         ItemPointerData t_ctid;         /* current TID of this or newer tuple */
40
41         int16           t_natts;                /* number of attributes */
42
43         uint16          t_infomask;             /* various infos */
44
45         uint8           t_hoff;                 /* sizeof tuple header */
46
47         bits8           t_bits[MinHeapTupleBitmapSize / 8];
48         /* bit map of domains */
49
50         /* MORE DATA FOLLOWS AT END OF STRUCT */
51 }                       HeapTupleHeaderData;
52
53 typedef HeapTupleHeaderData *HeapTupleHeader;
54
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)
62
63 /* If you make any changes above, the order off offsets in this must change */
64 extern long heap_sysoffset[];
65
66 /*
67  * This new HeapTuple for version >= 6.5 and this is why it was changed:
68  *
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...
74  */
75 typedef struct HeapTupleData
76 {
77         uint32          t_len;                  /* length of *t_data */
78         ItemPointerData t_self;         /* SelfItemPointer */
79         HeapTupleHeader t_data;         /* */
80 } HeapTupleData;
81
82 typedef HeapTupleData *HeapTuple;
83
84 #define HEAPTUPLESIZE   DOUBLEALIGN(sizeof(HeapTupleData))
85
86
87 /* ----------------
88  *              support macros
89  * ----------------
90  */
91 #define GETSTRUCT(TUP) (((char *)((HeapTuple)(TUP))->t_data) + \
92                                                 ((HeapTuple)(TUP))->t_data->t_hoff)
93
94
95 /*
96  * BITMAPLEN(NATTS) -
97  *              Computes minimum size of bitmap given number of domains.
98  */
99 #define BITMAPLEN(NATTS) \
100                 ((((((int)(NATTS) - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) \
101                   & ~03) + (MinHeapTupleBitmapSize >> 3))
102
103 /*
104  * HeapTupleIsValid
105  *              True iff the heap tuple is valid.
106  */
107 #define HeapTupleIsValid(tuple) PointerIsValid(tuple)
108
109 /*
110  * information stored in t_infomask:
111  */
112 #define HEAP_HASNULL                    0x0001  /* has null attribute(s) */
113 #define HEAP_HASVARLENA                 0x0002  /* has variable length
114                                                                                  * attribute(s) */
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
122                                                                                  * place by vacuum */
123 #define HEAP_MOVED_IN                   0x8000  /* moved from another place by
124                                                                                  * vacuum */
125
126 #define HEAP_XACT_MASK                  0xFF00  /* */
127
128 #define HeapTupleNoNulls(tuple) \
129                 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
130
131 #define HeapTupleAllFixed(tuple) \
132                 (!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA))
133
134 #endif   /* HTUP_H */