pg_class.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pg_class.h
  4. * definition of the "relation" system catalog (pg_class)
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/catalog/pg_class.h
  11. *
  12. * NOTES
  13. * The Catalog.pm module reads this file and derives schema
  14. * information.
  15. *
  16. *-------------------------------------------------------------------------
  17. */
  18. #ifndef PG_CLASS_H
  19. #define PG_CLASS_H
  20. #include "catalog/genbki.h"
  21. #include "catalog/pg_class_d.h"
  22. /* ----------------
  23. * pg_class definition. cpp turns this into
  24. * typedef struct FormData_pg_class
  25. *
  26. * Note that the BKI_DEFAULT values below are only used for rows describing
  27. * BKI_BOOTSTRAP catalogs, since only those rows appear in pg_class.dat.
  28. * ----------------
  29. */
  30. CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,RelationRelation_Rowtype_Id) BKI_SCHEMA_MACRO
  31. {
  32. /* oid */
  33. Oid oid;
  34. /* class name */
  35. NameData relname;
  36. /* OID of namespace containing this class */
  37. Oid relnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
  38. /* OID of entry in pg_type for relation's implicit row type, if any */
  39. Oid reltype BKI_LOOKUP_OPT(pg_type);
  40. /* OID of entry in pg_type for underlying composite type, if any */
  41. Oid reloftype BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_type);
  42. /* class owner */
  43. Oid relowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
  44. /* access method; 0 if not a table / index */
  45. Oid relam BKI_DEFAULT(heap) BKI_LOOKUP_OPT(pg_am);
  46. /* identifier of physical storage file */
  47. /* relfilenode == 0 means it is a "mapped" relation, see relmapper.c */
  48. Oid relfilenode BKI_DEFAULT(0);
  49. /* identifier of table space for relation (0 means default for database) */
  50. Oid reltablespace BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_tablespace);
  51. /* # of blocks (not always up-to-date) */
  52. int32 relpages BKI_DEFAULT(0);
  53. /* # of tuples (not always up-to-date; -1 means "unknown") */
  54. float4 reltuples BKI_DEFAULT(-1);
  55. /* # of all-visible blocks (not always up-to-date) */
  56. int32 relallvisible BKI_DEFAULT(0);
  57. /* OID of toast table; 0 if none */
  58. Oid reltoastrelid BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class);
  59. /* T if has (or has had) any indexes */
  60. bool relhasindex BKI_DEFAULT(f);
  61. /* T if shared across databases */
  62. bool relisshared BKI_DEFAULT(f);
  63. /* see RELPERSISTENCE_xxx constants below */
  64. char relpersistence BKI_DEFAULT(p);
  65. /* see RELKIND_xxx constants below */
  66. char relkind BKI_DEFAULT(r);
  67. /* number of user attributes */
  68. int16 relnatts BKI_DEFAULT(0); /* genbki.pl will fill this in */
  69. /*
  70. * Class pg_attribute must contain exactly "relnatts" user attributes
  71. * (with attnums ranging from 1 to relnatts) for this class. It may also
  72. * contain entries with negative attnums for system attributes.
  73. */
  74. /* # of CHECK constraints for class */
  75. int16 relchecks BKI_DEFAULT(0);
  76. /* has (or has had) any rules */
  77. bool relhasrules BKI_DEFAULT(f);
  78. /* has (or has had) any TRIGGERs */
  79. bool relhastriggers BKI_DEFAULT(f);
  80. /* has (or has had) child tables or indexes */
  81. bool relhassubclass BKI_DEFAULT(f);
  82. /* row security is enabled or not */
  83. bool relrowsecurity BKI_DEFAULT(f);
  84. /* row security forced for owners or not */
  85. bool relforcerowsecurity BKI_DEFAULT(f);
  86. /* matview currently holds query results */
  87. bool relispopulated BKI_DEFAULT(t);
  88. /* see REPLICA_IDENTITY_xxx constants */
  89. char relreplident BKI_DEFAULT(n);
  90. /* is relation a partition? */
  91. bool relispartition BKI_DEFAULT(f);
  92. /* link to original rel during table rewrite; otherwise 0 */
  93. Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class);
  94. /* all Xids < this are frozen in this rel */
  95. TransactionId relfrozenxid BKI_DEFAULT(3); /* FirstNormalTransactionId */
  96. /* all multixacts in this rel are >= this; it is really a MultiXactId */
  97. TransactionId relminmxid BKI_DEFAULT(1); /* FirstMultiXactId */
  98. #ifdef CATALOG_VARLEN /* variable-length fields start here */
  99. /* NOTE: These fields are not present in a relcache entry's rd_rel field. */
  100. /* access permissions */
  101. aclitem relacl[1] BKI_DEFAULT(_null_);
  102. /* access-method-specific options */
  103. text reloptions[1] BKI_DEFAULT(_null_);
  104. /* partition bound node tree */
  105. pg_node_tree relpartbound BKI_DEFAULT(_null_);
  106. #endif
  107. } FormData_pg_class;
  108. /* Size of fixed part of pg_class tuples, not counting var-length fields */
  109. #define CLASS_TUPLE_SIZE \
  110. (offsetof(FormData_pg_class,relminmxid) + sizeof(TransactionId))
  111. /* ----------------
  112. * Form_pg_class corresponds to a pointer to a tuple with
  113. * the format of pg_class relation.
  114. * ----------------
  115. */
  116. typedef FormData_pg_class *Form_pg_class;
  117. DECLARE_UNIQUE_INDEX_PKEY(pg_class_oid_index, 2662, ClassOidIndexId, on pg_class using btree(oid oid_ops));
  118. DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, ClassNameNspIndexId, on pg_class using btree(relname name_ops, relnamespace oid_ops));
  119. DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeIndexId, on pg_class using btree(reltablespace oid_ops, relfilenode oid_ops));
  120. #ifdef EXPOSE_TO_CLIENT_CODE
  121. #define RELKIND_RELATION 'r' /* ordinary table */
  122. #define RELKIND_INDEX 'i' /* secondary index */
  123. #define RELKIND_SEQUENCE 'S' /* sequence object */
  124. #define RELKIND_TOASTVALUE 't' /* for out-of-line values */
  125. #define RELKIND_VIEW 'v' /* view */
  126. #define RELKIND_MATVIEW 'm' /* materialized view */
  127. #define RELKIND_COMPOSITE_TYPE 'c' /* composite type */
  128. #define RELKIND_FOREIGN_TABLE 'f' /* foreign table */
  129. #define RELKIND_PARTITIONED_TABLE 'p' /* partitioned table */
  130. #define RELKIND_PARTITIONED_INDEX 'I' /* partitioned index */
  131. #define RELPERSISTENCE_PERMANENT 'p' /* regular table */
  132. #define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */
  133. #define RELPERSISTENCE_TEMP 't' /* temporary table */
  134. /* default selection for replica identity (primary key or nothing) */
  135. #define REPLICA_IDENTITY_DEFAULT 'd'
  136. /* no replica identity is logged for this relation */
  137. #define REPLICA_IDENTITY_NOTHING 'n'
  138. /* all columns are logged as replica identity */
  139. #define REPLICA_IDENTITY_FULL 'f'
  140. /*
  141. * an explicitly chosen candidate key's columns are used as replica identity.
  142. * Note this will still be set if the index has been dropped; in that case it
  143. * has the same meaning as 'n'.
  144. */
  145. #define REPLICA_IDENTITY_INDEX 'i'
  146. /*
  147. * Relation kinds that have physical storage. These relations normally have
  148. * relfilenode set to non-zero, but it can also be zero if the relation is
  149. * mapped.
  150. */
  151. #define RELKIND_HAS_STORAGE(relkind) \
  152. ((relkind) == RELKIND_RELATION || \
  153. (relkind) == RELKIND_INDEX || \
  154. (relkind) == RELKIND_SEQUENCE || \
  155. (relkind) == RELKIND_TOASTVALUE || \
  156. (relkind) == RELKIND_MATVIEW)
  157. #define RELKIND_HAS_PARTITIONS(relkind) \
  158. ((relkind) == RELKIND_PARTITIONED_TABLE || \
  159. (relkind) == RELKIND_PARTITIONED_INDEX)
  160. /*
  161. * Relation kinds that support tablespaces: All relation kinds with storage
  162. * support tablespaces, except that we don't support moving sequences around
  163. * into different tablespaces. Partitioned tables and indexes don't have
  164. * physical storage, but they have a tablespace settings so that their
  165. * children can inherit it.
  166. */
  167. #define RELKIND_HAS_TABLESPACE(relkind) \
  168. ((RELKIND_HAS_STORAGE(relkind) || RELKIND_HAS_PARTITIONS(relkind)) \
  169. && (relkind) != RELKIND_SEQUENCE)
  170. /*
  171. * Relation kinds with a table access method (rd_tableam). Although sequences
  172. * use the heap table AM, they are enough of a special case in most uses that
  173. * they are not included here.
  174. */
  175. #define RELKIND_HAS_TABLE_AM(relkind) \
  176. ((relkind) == RELKIND_RELATION || \
  177. (relkind) == RELKIND_TOASTVALUE || \
  178. (relkind) == RELKIND_MATVIEW)
  179. extern int errdetail_relkind_not_supported(char relkind);
  180. #endif /* EXPOSE_TO_CLIENT_CODE */
  181. #endif /* PG_CLASS_H */