pg_attribute.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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-2022, 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. #include "catalog/genbki.h"
  25. #include "catalog/pg_attribute_d.h"
  26. /* ----------------
  27. * pg_attribute definition. cpp turns this into
  28. * typedef struct FormData_pg_attribute
  29. *
  30. * If you change the following, make sure you change the structs for
  31. * system attributes in catalog/heap.c also.
  32. * You may need to change catalog/genbki.pl as well.
  33. * ----------------
  34. */
  35. CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75,AttributeRelation_Rowtype_Id) BKI_SCHEMA_MACRO
  36. {
  37. Oid attrelid BKI_LOOKUP(pg_class); /* OID of relation containing
  38. * this attribute */
  39. NameData attname; /* name of attribute */
  40. /*
  41. * atttypid is the OID of the instance in Catalog Class pg_type that
  42. * defines the data type of this attribute (e.g. int4). Information in
  43. * that instance is redundant with the attlen, attbyval, and attalign
  44. * attributes of this instance, so they had better match or Postgres will
  45. * fail. In an entry for a dropped column, this field is set to zero
  46. * since the pg_type entry may no longer exist; but we rely on attlen,
  47. * attbyval, and attalign to still tell us how large the values in the
  48. * table are.
  49. */
  50. Oid atttypid BKI_LOOKUP_OPT(pg_type);
  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. * 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. * attnum is the "attribute number" for the attribute: A value that
  66. * uniquely identifies this attribute within its class. For user
  67. * attributes, Attribute numbers are greater than 0 and not greater than
  68. * the number of attributes in the class. I.e. if the Class pg_class says
  69. * that Class XYZ has 10 attributes, then the user attribute numbers in
  70. * Class pg_attribute must be 1-10.
  71. *
  72. * System attributes have attribute numbers less than 0 that are unique
  73. * within the class, but not constrained to any particular range.
  74. *
  75. * Note that (attnum - 1) is often used as the index to an array.
  76. */
  77. int16 attnum;
  78. /*
  79. * attndims is the declared number of dimensions, if an array type,
  80. * otherwise zero.
  81. */
  82. int32 attndims;
  83. /*
  84. * fastgetattr() uses attcacheoff to cache byte offsets of attributes in
  85. * heap tuples. The value actually stored in pg_attribute (-1) indicates
  86. * no cached value. But when we copy these tuples into a tuple
  87. * descriptor, we may then update attcacheoff in the copies. This speeds
  88. * up the attribute walking process.
  89. */
  90. int32 attcacheoff BKI_DEFAULT(-1);
  91. /*
  92. * atttypmod records type-specific data supplied at table creation time
  93. * (for example, the max length of a varchar field). It is passed to
  94. * type-specific input and output functions as the third argument. The
  95. * value will generally be -1 for types that do not need typmod.
  96. */
  97. int32 atttypmod BKI_DEFAULT(-1);
  98. /*
  99. * attbyval is a copy of the typbyval field from pg_type for this
  100. * attribute. See atttypid comments above.
  101. */
  102. bool attbyval;
  103. /*
  104. * attalign is a copy of the typalign field from pg_type for this
  105. * attribute. See atttypid comments above.
  106. */
  107. char attalign;
  108. /*----------
  109. * attstorage tells for VARLENA attributes, what the heap access
  110. * methods can do to it if a given tuple doesn't fit into a page.
  111. * Possible values are as for pg_type.typstorage (see TYPSTORAGE macros).
  112. *----------
  113. */
  114. char attstorage;
  115. /*
  116. * attcompression sets the current compression method of the attribute.
  117. * Typically this is InvalidCompressionMethod ('\0') to specify use of the
  118. * current default setting (see default_toast_compression). Otherwise,
  119. * 'p' selects pglz compression, while 'l' selects LZ4 compression.
  120. * However, this field is ignored whenever attstorage does not allow
  121. * compression.
  122. */
  123. char attcompression BKI_DEFAULT('\0');
  124. /* This flag represents the "NOT NULL" constraint */
  125. bool attnotnull;
  126. /* Has DEFAULT value or not */
  127. bool atthasdef BKI_DEFAULT(f);
  128. /* Has a missing value or not */
  129. bool atthasmissing BKI_DEFAULT(f);
  130. /* One of the ATTRIBUTE_IDENTITY_* constants below, or '\0' */
  131. char attidentity BKI_DEFAULT('\0');
  132. /* One of the ATTRIBUTE_GENERATED_* constants below, or '\0' */
  133. char attgenerated BKI_DEFAULT('\0');
  134. /* Is dropped (ie, logically invisible) or not */
  135. bool attisdropped BKI_DEFAULT(f);
  136. /*
  137. * This flag specifies whether this column has ever had a local
  138. * definition. It is set for normal non-inherited columns, but also for
  139. * columns that are inherited from parents if also explicitly listed in
  140. * CREATE TABLE INHERITS. It is also set when inheritance is removed from
  141. * a table with ALTER TABLE NO INHERIT. If the flag is set, the column is
  142. * not dropped by a parent's DROP COLUMN even if this causes the column's
  143. * attinhcount to become zero.
  144. */
  145. bool attislocal BKI_DEFAULT(t);
  146. /* Number of times inherited from direct parent relation(s) */
  147. int32 attinhcount BKI_DEFAULT(0);
  148. /* attribute's collation, if any */
  149. Oid attcollation BKI_LOOKUP_OPT(pg_collation);
  150. #ifdef CATALOG_VARLEN /* variable-length fields start here */
  151. /* NOTE: The following fields are not present in tuple descriptors. */
  152. /* Column-level access permissions */
  153. aclitem attacl[1] BKI_DEFAULT(_null_);
  154. /* Column-level options */
  155. text attoptions[1] BKI_DEFAULT(_null_);
  156. /* Column-level FDW options */
  157. text attfdwoptions[1] BKI_DEFAULT(_null_);
  158. /*
  159. * Missing value for added columns. This is a one element array which lets
  160. * us store a value of the attribute type here.
  161. */
  162. anyarray attmissingval BKI_DEFAULT(_null_);
  163. #endif
  164. } FormData_pg_attribute;
  165. /*
  166. * ATTRIBUTE_FIXED_PART_SIZE is the size of the fixed-layout,
  167. * guaranteed-not-null part of a pg_attribute row. This is in fact as much
  168. * of the row as gets copied into tuple descriptors, so don't expect you
  169. * can access the variable-length fields except in a real tuple!
  170. */
  171. #define ATTRIBUTE_FIXED_PART_SIZE \
  172. (offsetof(FormData_pg_attribute,attcollation) + sizeof(Oid))
  173. /* ----------------
  174. * Form_pg_attribute corresponds to a pointer to a tuple with
  175. * the format of pg_attribute relation.
  176. * ----------------
  177. */
  178. typedef FormData_pg_attribute *Form_pg_attribute;
  179. DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnam_index, 2658, AttributeRelidNameIndexId, on pg_attribute using btree(attrelid oid_ops, attname name_ops));
  180. DECLARE_UNIQUE_INDEX_PKEY(pg_attribute_relid_attnum_index, 2659, AttributeRelidNumIndexId, on pg_attribute using btree(attrelid oid_ops, attnum int2_ops));
  181. #ifdef EXPOSE_TO_CLIENT_CODE
  182. #define ATTRIBUTE_IDENTITY_ALWAYS 'a'
  183. #define ATTRIBUTE_IDENTITY_BY_DEFAULT 'd'
  184. #define ATTRIBUTE_GENERATED_STORED 's'
  185. #endif /* EXPOSE_TO_CLIENT_CODE */
  186. #endif /* PG_ATTRIBUTE_H */