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