]> granicus.if.org Git - postgresql/blob - src/include/postgres.h
Change Copyright from PostgreSQL, Inc to PostgreSQL Global Development Group.
[postgresql] / src / include / postgres.h
1 /*-------------------------------------------------------------------------
2  *
3  * postgres.h
4  *        definition of (and support for) postgres system types.
5  * this file is included by almost every .c in the system
6  *
7  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1995, Regents of the University of California
9  *
10  * $Id: postgres.h,v 1.45 2001/01/24 19:43:19 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 /*
15  *       NOTES
16  *              this file will eventually contain the definitions for the
17  *              following (and perhaps other) system types:
18  *
19  *                              int2       int4           float4           float8
20  *                              Oid                regproc        RegProcedure
21  *                              aclitem
22  *                              struct varlena
23  *                              int2vector        oidvector
24  *                              bytea      text
25  *                              NameData   Name
26  *
27  *       TABLE OF CONTENTS
28  *              1)              simple type definitions
29  *              2)              varlena and array types
30  *              3)              TransactionId and CommandId
31  *              4)              genbki macros used by catalog/pg_xxx.h files
32  *              5)              random stuff
33  *
34  * ----------------------------------------------------------------
35  */
36 #ifndef POSTGRES_H
37 #define POSTGRES_H
38
39 #include "postgres_ext.h"
40 #include "c.h"
41 #include "utils/elog.h"
42 #include "utils/palloc.h"
43
44 /* ----------------------------------------------------------------
45  *                              Section 1:      simple type definitions
46  * ----------------------------------------------------------------
47  */
48
49 #define InvalidOid              ((Oid) 0)
50 #define OidIsValid(objectId)  ((bool) ((objectId) != InvalidOid))
51
52 /* unfortunately, both regproc and RegProcedure are used */
53 typedef Oid regproc;
54 typedef Oid RegProcedure;
55
56 #define RegProcedureIsValid(p)  OidIsValid(p)
57
58 typedef int4 aclitem;                   /* PHONY definition for catalog use only */
59
60 /* ----------------------------------------------------------------
61  *                              Section 2:      variable length and array types
62  * ----------------------------------------------------------------
63  */
64 /* ----------------
65  *              struct varlena
66  * ----------------
67  */
68 struct varlena
69 {
70         int32           vl_len;
71         char            vl_dat[1];
72 };
73
74 #define TUPLE_TOASTER_ACTIVE
75
76 #ifndef TUPLE_TOASTER_ACTIVE
77 #define VARSIZE(PTR)    (((struct varlena *)(PTR))->vl_len)
78 #define VARDATA(PTR)    (((struct varlena *)(PTR))->vl_dat)
79 #endif
80 #define VARHDRSZ                ((int32) sizeof(int32))
81
82 /*
83  * These widely-used datatypes are just a varlena header and the data bytes.
84  * There is no terminating null or anything like that --- the data length is
85  * always VARSIZE(ptr) - VARHDRSZ.
86  */
87 typedef struct varlena bytea;
88 typedef struct varlena text;
89 typedef struct varlena BpChar;  /* blank-padded char, ie SQL char(n) */
90 typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */
91
92 /*
93  * Proposed new layout for variable length attributes
94  * DO NOT USE YET - Jan
95  */
96
97 #ifdef TUPLE_TOASTER_ACTIVE
98 typedef struct varattrib
99 {
100         int32           va_header;              /* External/compressed storage */
101         /* flags and item size */
102         union
103         {
104                 struct
105                 {
106                         int32           va_rawsize;             /* Plain data size */
107                         char            va_data[1];             /* Compressed data */
108                 }                       va_compressed;          /* Compressed stored attribute */
109
110                 struct
111                 {
112                         int32           va_rawsize;             /* Plain data size */
113                         int32           va_extsize;             /* External saved size */
114                         Oid                     va_valueid;             /* Unique identifier of value */
115                         Oid                     va_toastrelid;  /* RelID where to find chunks */
116                         Oid                     va_toastidxid;  /* Main tables row Oid */
117                         Oid                     va_rowid;               /* Referencing row Oid */
118                         int16           va_attno;               /* Main tables attno */
119                 }                       va_external;/* External stored attribute */
120
121                 char            va_data[1]; /* Plain stored attribute */
122         }                       va_content;
123 }                       varattrib;
124
125 #define VARATT_FLAG_EXTERNAL    0x80000000
126 #define VARATT_FLAG_COMPRESSED  0x40000000
127 #define VARATT_MASK_FLAGS               0xc0000000
128 #define VARATT_MASK_SIZE                0x3fffffff
129
130 #define VARATT_SIZEP(_PTR)      (((varattrib *)(_PTR))->va_header)
131 #define VARATT_SIZE(PTR)        (VARATT_SIZEP(PTR) & VARATT_MASK_SIZE)
132 #define VARATT_DATA(PTR)        (((varattrib *)(PTR))->va_content.va_data)
133 #define VARATT_CDATA(PTR)       (((varattrib *)(PTR))->va_content.va_compressed.va_data)
134
135 #define VARSIZE(__PTR)          VARATT_SIZE(__PTR)
136 #define VARDATA(__PTR)          VARATT_DATA(__PTR)
137
138 #define VARATT_IS_EXTENDED(PTR)         \
139                                 ((VARATT_SIZEP(PTR) & VARATT_MASK_FLAGS) != 0)
140 #define VARATT_IS_EXTERNAL(PTR)         \
141                                 ((VARATT_SIZEP(PTR) & VARATT_FLAG_EXTERNAL) != 0)
142 #define VARATT_IS_COMPRESSED(PTR)       \
143                                 ((VARATT_SIZEP(PTR) & VARATT_FLAG_COMPRESSED) != 0)
144
145 /* ----------
146  * This is regularly declared in access/tuptoaster.h,
147  * but we don't want to include that into every source,
148  * so we (evil evil evil) declare it here once more.
149  * ----------
150  */
151 extern varattrib *heap_tuple_untoast_attr(varattrib * attr);
152
153 #define VARATT_GETPLAIN(_ARG,_VAR) {                                                            \
154                                 if (VARATT_IS_EXTENDED(_ARG))                                           \
155                                         (_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
156                                 else                                                                                            \
157                                         (_VAR) = (void *)(_ARG);                                                \
158                         }
159 #define VARATT_FREE(_ARG,_VAR) do {                                                                     \
160                                 if ((void *)(_VAR) != (void *)(_ARG))                           \
161                                         pfree((void *)(_VAR));                                                  \
162                         } while (0)
163 #else                                                   /* TUPLE_TOASTER_ACTIVE */
164 #define VARATT_SIZE(__PTR) VARSIZE(__PTR)
165 #define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
166 #endif   /* TUPLE_TOASTER_ACTIVE */
167
168
169 /* fixed-length array types (these are not varlena's!) */
170
171 typedef int2 int2vector[INDEX_MAX_KEYS];
172 typedef Oid oidvector[INDEX_MAX_KEYS];
173
174 /* We want NameData to have length NAMEDATALEN and int alignment,
175  * because that's how the data type 'name' is defined in pg_type.
176  * Use a union to make sure the compiler agrees.
177  */
178 typedef union nameData
179 {
180         char            data[NAMEDATALEN];
181         int                     alignmentDummy;
182 } NameData;
183 typedef NameData *Name;
184
185 #define NameStr(name)   ((name).data)
186
187 /* ----------------------------------------------------------------
188  *                              Section 3: TransactionId and CommandId
189  * ----------------------------------------------------------------
190  */
191
192 typedef uint32 TransactionId;
193
194 #define InvalidTransactionId    0
195
196 typedef uint32 CommandId;
197
198 #define FirstCommandId  0
199
200 /* ----------------------------------------------------------------
201  *                              Section 4: genbki macros used by the
202  *                                                 catalog/pg_xxx.h files
203  * ----------------------------------------------------------------
204  */
205 #define CATALOG(x) \
206         typedef struct CppConcat(FormData_,x)
207
208 /* Huh? */
209 #define DATA(x) extern int errno
210 #define DESCR(x) extern int errno
211 #define DECLARE_INDEX(x) extern int errno
212 #define DECLARE_UNIQUE_INDEX(x) extern int errno
213
214 #define BUILD_INDICES
215 #define BOOTSTRAP
216
217 #define BKI_BEGIN
218 #define BKI_END
219
220 /* ----------------------------------------------------------------
221  *                              Section 5:      random stuff
222  *                                                      CSIGNBIT, STATUS...
223  * ----------------------------------------------------------------
224  */
225
226 /* msb for int/unsigned */
227 #define ISIGNBIT (0x80000000)
228 #define WSIGNBIT (0x8000)
229
230 /* msb for char */
231 #define CSIGNBIT (0x80)
232
233 #define STATUS_OK                               (0)
234 #define STATUS_ERROR                    (-1)
235 #define STATUS_NOT_FOUND                (-2)
236 #define STATUS_INVALID                  (-3)
237 #define STATUS_UNCATALOGUED             (-4)
238 #define STATUS_REPLACED                 (-5)
239 #define STATUS_NOT_DONE                 (-6)
240 #define STATUS_BAD_PACKET               (-7)
241 #define STATUS_FOUND                    (1)
242
243 /* ---------------
244  * Cyrillic on the fly charsets recode
245  * ---------------
246  */
247 #ifdef CYR_RECODE
248 extern void SetCharSet(void);
249 #endif   /* CYR_RECODE */
250
251 #endif   /* POSTGRES_H */