PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pg_class.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pg_class.h
4 * definition of the "relation" system catalog (pg_class)
5 *
6 *
7 * Portions Copyright (c) 1996-2025, 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" /* IWYU pragma: export */
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 */
32CATALOG(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 */
39
40 /* OID of namespace containing this class */
41 Oid relnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
42
43 /* OID of entry in pg_type for relation's implicit row type, if any */
44 Oid reltype BKI_LOOKUP_OPT(pg_type);
45
46 /* OID of entry in pg_type for underlying composite type, if any */
47 Oid reloftype BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_type);
48
49 /* class owner */
50 Oid relowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
51
52 /* access method; 0 if not a table / index */
53 Oid relam BKI_DEFAULT(heap) BKI_LOOKUP_OPT(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_OPT(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; -1 means "unknown") */
66 float4 reltuples BKI_DEFAULT(-1);
67
68 /* # of all-visible blocks (not always up-to-date) */
69 int32 relallvisible BKI_DEFAULT(0);
70
71 /* # of all-frozen blocks (not always up-to-date) */
72 int32 relallfrozen BKI_DEFAULT(0);
73
74 /* OID of toast table; 0 if none */
75 Oid reltoastrelid BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class);
76
77 /* T if has (or has had) any indexes */
78 bool relhasindex BKI_DEFAULT(f);
79
80 /* T if shared across databases */
81 bool relisshared BKI_DEFAULT(f);
82
83 /* see RELPERSISTENCE_xxx constants below */
84 char relpersistence BKI_DEFAULT(p);
85
86 /* see RELKIND_xxx constants below */
87 char relkind BKI_DEFAULT(r);
88
89 /* number of user attributes */
90 int16 relnatts BKI_DEFAULT(0); /* genbki.pl will fill this in */
91
92 /*
93 * Class pg_attribute must contain exactly "relnatts" user attributes
94 * (with attnums ranging from 1 to relnatts) for this class. It may also
95 * contain entries with negative attnums for system attributes.
96 */
97
98 /* # of CHECK constraints for class */
99 int16 relchecks BKI_DEFAULT(0);
100
101 /* has (or has had) any rules */
102 bool relhasrules BKI_DEFAULT(f);
103
104 /* has (or has had) any TRIGGERs */
105 bool relhastriggers BKI_DEFAULT(f);
106
107 /* has (or has had) child tables or indexes */
108 bool relhassubclass BKI_DEFAULT(f);
109
110 /* row security is enabled or not */
111 bool relrowsecurity BKI_DEFAULT(f);
112
113 /* row security forced for owners or not */
114 bool relforcerowsecurity BKI_DEFAULT(f);
115
116 /* matview currently holds query results */
117 bool relispopulated BKI_DEFAULT(t);
118
119 /* see REPLICA_IDENTITY_xxx constants */
120 char relreplident BKI_DEFAULT(n);
121
122 /* is relation a partition? */
123 bool relispartition BKI_DEFAULT(f);
124
125 /* link to original rel during table rewrite; otherwise 0 */
126 Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class);
127
128 /* all Xids < this are frozen in this rel */
129 TransactionId relfrozenxid BKI_DEFAULT(3); /* FirstNormalTransactionId */
130
131 /* all multixacts in this rel are >= this; it is really a MultiXactId */
132 TransactionId relminmxid BKI_DEFAULT(1); /* FirstMultiXactId */
133
134#ifdef CATALOG_VARLEN /* variable-length fields start here */
135 /* NOTE: These fields are not present in a relcache entry's rd_rel field. */
136 /* access permissions */
137 aclitem relacl[1] BKI_DEFAULT(_null_);
138
139 /* access-method-specific options */
140 text reloptions[1] BKI_DEFAULT(_null_);
141
142 /* partition bound node tree */
143 pg_node_tree relpartbound BKI_DEFAULT(_null_);
144#endif
146
147/* Size of fixed part of pg_class tuples, not counting var-length fields */
148#define CLASS_TUPLE_SIZE \
149 (offsetof(FormData_pg_class,relminmxid) + sizeof(TransactionId))
150
151/* ----------------
152 * Form_pg_class corresponds to a pointer to a tuple with
153 * the format of pg_class relation.
154 * ----------------
155 */
157
158DECLARE_UNIQUE_INDEX_PKEY(pg_class_oid_index, 2662, ClassOidIndexId, pg_class, btree(oid oid_ops));
159DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, ClassNameNspIndexId, pg_class, btree(relname name_ops, relnamespace oid_ops));
160DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeIndexId, pg_class, btree(reltablespace oid_ops, relfilenode oid_ops));
161
162MAKE_SYSCACHE(RELOID, pg_class_oid_index, 128);
163MAKE_SYSCACHE(RELNAMENSP, pg_class_relname_nsp_index, 128);
164
165#ifdef EXPOSE_TO_CLIENT_CODE
166
167#define RELKIND_RELATION 'r' /* ordinary table */
168#define RELKIND_INDEX 'i' /* secondary index */
169#define RELKIND_SEQUENCE 'S' /* sequence object */
170#define RELKIND_TOASTVALUE 't' /* for out-of-line values */
171#define RELKIND_VIEW 'v' /* view */
172#define RELKIND_MATVIEW 'm' /* materialized view */
173#define RELKIND_COMPOSITE_TYPE 'c' /* composite type */
174#define RELKIND_FOREIGN_TABLE 'f' /* foreign table */
175#define RELKIND_PARTITIONED_TABLE 'p' /* partitioned table */
176#define RELKIND_PARTITIONED_INDEX 'I' /* partitioned index */
177
178#define RELPERSISTENCE_PERMANENT 'p' /* regular table */
179#define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */
180#define RELPERSISTENCE_TEMP 't' /* temporary table */
181
182/* default selection for replica identity (primary key or nothing) */
183#define REPLICA_IDENTITY_DEFAULT 'd'
184/* no replica identity is logged for this relation */
185#define REPLICA_IDENTITY_NOTHING 'n'
186/* all columns are logged as replica identity */
187#define REPLICA_IDENTITY_FULL 'f'
188/*
189 * an explicitly chosen candidate key's columns are used as replica identity.
190 * Note this will still be set if the index has been dropped; in that case it
191 * has the same meaning as 'n'.
192 */
193#define REPLICA_IDENTITY_INDEX 'i'
194
195/*
196 * Relation kinds that have physical storage. These relations normally have
197 * relfilenode set to non-zero, but it can also be zero if the relation is
198 * mapped.
199 */
200#define RELKIND_HAS_STORAGE(relkind) \
201 ((relkind) == RELKIND_RELATION || \
202 (relkind) == RELKIND_INDEX || \
203 (relkind) == RELKIND_SEQUENCE || \
204 (relkind) == RELKIND_TOASTVALUE || \
205 (relkind) == RELKIND_MATVIEW)
206
207#define RELKIND_HAS_PARTITIONS(relkind) \
208 ((relkind) == RELKIND_PARTITIONED_TABLE || \
209 (relkind) == RELKIND_PARTITIONED_INDEX)
210
211/*
212 * Relation kinds that support tablespaces: All relation kinds with storage
213 * support tablespaces, except that we don't support moving sequences around
214 * into different tablespaces. Partitioned tables and indexes don't have
215 * physical storage, but they have a tablespace settings so that their
216 * children can inherit it.
217 */
218#define RELKIND_HAS_TABLESPACE(relkind) \
219 ((RELKIND_HAS_STORAGE(relkind) || RELKIND_HAS_PARTITIONS(relkind)) \
220 && (relkind) != RELKIND_SEQUENCE)
221
222/*
223 * Relation kinds with a table access method (rd_tableam). Although sequences
224 * use the heap table AM, they are enough of a special case in most uses that
225 * they are not included here. Likewise, partitioned tables can have an access
226 * method defined so that their partitions can inherit it, but they do not set
227 * rd_tableam; hence, this is handled specially outside of this macro.
228 */
229#define RELKIND_HAS_TABLE_AM(relkind) \
230 ((relkind) == RELKIND_RELATION || \
231 (relkind) == RELKIND_TOASTVALUE || \
232 (relkind) == RELKIND_MATVIEW)
233
234#endif /* EXPOSE_TO_CLIENT_CODE */
235
236extern int errdetail_relkind_not_supported(char relkind);
237
238#endif /* PG_CLASS_H */
int16_t int16
Definition: c.h:497
int32_t int32
Definition: c.h:498
float float4
Definition: c.h:600
uint32 TransactionId
Definition: c.h:623
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
#define BKI_BOOTSTRAP
Definition: genbki.h:26
#define BKI_ROWTYPE_OID(oid, oidmacro)
Definition: genbki.h:28
NameData relname
Definition: pg_class.h:38
FormData_pg_class * Form_pg_class
Definition: pg_class.h:156
DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, ClassNameNspIndexId, pg_class, btree(relname name_ops, relnamespace oid_ops))
CATALOG(pg_class, 1259, RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83
Oid relnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace)
Oid reltype BKI_LOOKUP_OPT(pg_type)
MAKE_SYSCACHE(RELOID, pg_class_oid_index, 128)
DECLARE_UNIQUE_INDEX_PKEY(pg_class_oid_index, 2662, ClassOidIndexId, pg_class, btree(oid oid_ops))
DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeIndexId, pg_class, btree(reltablespace oid_ops, relfilenode oid_ops))
RelationRelation_Rowtype_Id BKI_SCHEMA_MACRO
Definition: pg_class.h:33
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
FormData_pg_class
Definition: pg_class.h:145
unsigned int Oid
Definition: postgres_ext.h:30
Definition: c.h:712
Definition: c.h:658