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