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