PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_attribute.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_attribute.h
4  * definition of the system "attribute" relation (pg_attribute)
5  * along with the relation's initial contents.
6  *
7  *
8  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  * src/include/catalog/pg_attribute.h
12  *
13  * NOTES
14  * the genbki.pl script reads this file and generates .bki
15  * information from the DATA() statements.
16  *
17  *-------------------------------------------------------------------------
18  */
19 #ifndef PG_ATTRIBUTE_H
20 #define PG_ATTRIBUTE_H
21 
22 #include "catalog/genbki.h"
23 
24 /* ----------------
25  * pg_attribute definition. cpp turns this into
26  * typedef struct FormData_pg_attribute
27  *
28  * If you change the following, make sure you change the structs for
29  * system attributes in catalog/heap.c also.
30  * You may need to change catalog/genbki.pl as well.
31  * ----------------
32  */
33 #define AttributeRelationId 1249
34 #define AttributeRelation_Rowtype_Id 75
35 
37 {
38  Oid attrelid; /* OID of relation containing this attribute */
39  NameData attname; /* name of attribute */
40 
41  /*
42  * atttypid is the OID of the instance in Catalog Class pg_type that
43  * defines the data type of this attribute (e.g. int4). Information in
44  * that instance is redundant with the attlen, attbyval, and attalign
45  * attributes of this instance, so they had better match or Postgres will
46  * fail.
47  */
48  Oid atttypid;
49 
50  /*
51  * attstattarget is the target number of statistics datapoints to collect
52  * during VACUUM ANALYZE of this column. A zero here indicates that we do
53  * not wish to collect any stats about this column. A "-1" here indicates
54  * that no value has been explicitly set for this column, so ANALYZE
55  * should use the default setting.
56  */
57  int32 attstattarget;
58 
59  /*
60  * attlen is a copy of the typlen field from pg_type for this attribute.
61  * See atttypid comments above.
62  */
63  int16 attlen;
64 
65  /*
66  * attnum is the "attribute number" for the attribute: A value that
67  * uniquely identifies this attribute within its class. For user
68  * attributes, Attribute numbers are greater than 0 and not greater than
69  * the number of attributes in the class. I.e. if the Class pg_class says
70  * that Class XYZ has 10 attributes, then the user attribute numbers in
71  * Class pg_attribute must be 1-10.
72  *
73  * System attributes have attribute numbers less than 0 that are unique
74  * within the class, but not constrained to any particular range.
75  *
76  * Note that (attnum - 1) is often used as the index to an array.
77  */
78  int16 attnum;
79 
80  /*
81  * attndims is the declared number of dimensions, if an array type,
82  * otherwise zero.
83  */
84  int32 attndims;
85 
86  /*
87  * fastgetattr() uses attcacheoff to cache byte offsets of attributes in
88  * heap tuples. The value actually stored in pg_attribute (-1) indicates
89  * no cached value. But when we copy these tuples into a tuple
90  * descriptor, we may then update attcacheoff in the copies. This speeds
91  * up the attribute walking process.
92  */
93  int32 attcacheoff;
94 
95  /*
96  * atttypmod records type-specific data supplied at table creation time
97  * (for example, the max length of a varchar field). It is passed to
98  * type-specific input and output functions as the third argument. The
99  * value will generally be -1 for types that do not need typmod.
100  */
101  int32 atttypmod;
102 
103  /*
104  * attbyval is a copy of the typbyval field from pg_type for this
105  * attribute. See atttypid comments above.
106  */
107  bool attbyval;
108 
109  /*----------
110  * attstorage tells for VARLENA attributes, what the heap access
111  * methods can do to it if a given tuple doesn't fit into a page.
112  * Possible values are
113  * 'p': Value must be stored plain always
114  * 'e': Value can be stored in "secondary" relation (if relation
115  * has one, see pg_class.reltoastrelid)
116  * 'm': Value can be stored compressed inline
117  * 'x': Value can be stored compressed inline or in "secondary"
118  * Note that 'm' fields can also be moved out to secondary storage,
119  * but only as a last resort ('e' and 'x' fields are moved first).
120  *----------
121  */
122  char attstorage;
123 
124  /*
125  * attalign is a copy of the typalign field from pg_type for this
126  * attribute. See atttypid comments above.
127  */
128  char attalign;
129 
130  /* This flag represents the "NOT NULL" constraint */
131  bool attnotnull;
132 
133  /* Has DEFAULT value or not */
134  bool atthasdef;
135 
136  /* One of the ATTRIBUTE_IDENTITY_* constants below, or '\0' */
137  char attidentity;
138 
139  /* Is dropped (ie, logically invisible) or not */
140  bool attisdropped;
141 
142  /*
143  * This flag specifies whether this column has ever had a local
144  * definition. It is set for normal non-inherited columns, but also for
145  * columns that are inherited from parents if also explicitly listed in
146  * CREATE TABLE INHERITS. It is also set when inheritance is removed from
147  * a table with ALTER TABLE NO INHERIT. If the flag is set, the column is
148  * not dropped by a parent's DROP COLUMN even if this causes the column's
149  * attinhcount to become zero.
150  */
151  bool attislocal;
152 
153  /* Number of times inherited from direct parent relation(s) */
154  int32 attinhcount;
155 
156  /* attribute's collation */
157  Oid attcollation;
158 
159 #ifdef CATALOG_VARLEN /* variable-length fields start here */
160  /* NOTE: The following fields are not present in tuple descriptors. */
161 
162  /* Column-level access permissions */
163  aclitem attacl[1];
164 
165  /* Column-level options */
166  text attoptions[1];
167 
168  /* Column-level FDW options */
169  text attfdwoptions[1];
170 #endif
172 
173 /*
174  * ATTRIBUTE_FIXED_PART_SIZE is the size of the fixed-layout,
175  * guaranteed-not-null part of a pg_attribute row. This is in fact as much
176  * of the row as gets copied into tuple descriptors, so don't expect you
177  * can access fields beyond attcollation except in a real tuple!
178  */
179 #define ATTRIBUTE_FIXED_PART_SIZE \
180  (offsetof(FormData_pg_attribute,attcollation) + sizeof(Oid))
181 
182 /* ----------------
183  * Form_pg_attribute corresponds to a pointer to a tuple with
184  * the format of pg_attribute relation.
185  * ----------------
186  */
188 
189 /* ----------------
190  * compiler constants for pg_attribute
191  * ----------------
192  */
193 
194 #define Natts_pg_attribute 22
195 #define Anum_pg_attribute_attrelid 1
196 #define Anum_pg_attribute_attname 2
197 #define Anum_pg_attribute_atttypid 3
198 #define Anum_pg_attribute_attstattarget 4
199 #define Anum_pg_attribute_attlen 5
200 #define Anum_pg_attribute_attnum 6
201 #define Anum_pg_attribute_attndims 7
202 #define Anum_pg_attribute_attcacheoff 8
203 #define Anum_pg_attribute_atttypmod 9
204 #define Anum_pg_attribute_attbyval 10
205 #define Anum_pg_attribute_attstorage 11
206 #define Anum_pg_attribute_attalign 12
207 #define Anum_pg_attribute_attnotnull 13
208 #define Anum_pg_attribute_atthasdef 14
209 #define Anum_pg_attribute_attidentity 15
210 #define Anum_pg_attribute_attisdropped 16
211 #define Anum_pg_attribute_attislocal 17
212 #define Anum_pg_attribute_attinhcount 18
213 #define Anum_pg_attribute_attcollation 19
214 #define Anum_pg_attribute_attacl 20
215 #define Anum_pg_attribute_attoptions 21
216 #define Anum_pg_attribute_attfdwoptions 22
217 
218 
219 /* ----------------
220  * initial contents of pg_attribute
221  *
222  * The initial contents of pg_attribute are generated at compile time by
223  * genbki.pl. Only "bootstrapped" relations need be included.
224  * ----------------
225  */
226 
227 
228 #define ATTRIBUTE_IDENTITY_ALWAYS 'a'
229 #define ATTRIBUTE_IDENTITY_BY_DEFAULT 'd'
230 
231 #endif /* PG_ATTRIBUTE_H */
#define BKI_SCHEMA_MACRO
Definition: genbki.h:30
#define BKI_BOOTSTRAP
Definition: genbki.h:26
signed short int16
Definition: c.h:255
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:256
#define BKI_WITHOUT_OIDS
Definition: genbki.h:28
Definition: c.h:493
#define BKI_ROWTYPE_OID(oid)
Definition: genbki.h:29
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
CATALOG(pg_attribute, 1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BKI_SCHEMA_MACRO
Definition: pg_attribute.h:36
FormData_pg_attribute
Definition: pg_attribute.h:171
Definition: c.h:439