PostgreSQL Source Code git master
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 /* OID of toast table; 0 if none */
72 Oid reltoastrelid BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class);
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 /* link to original rel during table rewrite; otherwise 0 */
123 Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class);
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
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 */
154
155DECLARE_UNIQUE_INDEX_PKEY(pg_class_oid_index, 2662, ClassOidIndexId, pg_class, btree(oid oid_ops));
156DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, ClassNameNspIndexId, pg_class, btree(relname name_ops, relnamespace oid_ops));
157DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeIndexId, pg_class, btree(reltablespace oid_ops, relfilenode oid_ops));
158
159MAKE_SYSCACHE(RELOID, pg_class_oid_index, 128);
160MAKE_SYSCACHE(RELNAMENSP, pg_class_relname_nsp_index, 128);
161
162#ifdef EXPOSE_TO_CLIENT_CODE
163
164#define RELKIND_RELATION 'r' /* ordinary table */
165#define RELKIND_INDEX 'i' /* secondary index */
166#define RELKIND_SEQUENCE 'S' /* sequence object */
167#define RELKIND_TOASTVALUE 't' /* for out-of-line values */
168#define RELKIND_VIEW 'v' /* view */
169#define RELKIND_MATVIEW 'm' /* materialized view */
170#define RELKIND_COMPOSITE_TYPE 'c' /* composite type */
171#define RELKIND_FOREIGN_TABLE 'f' /* foreign table */
172#define RELKIND_PARTITIONED_TABLE 'p' /* partitioned table */
173#define RELKIND_PARTITIONED_INDEX 'I' /* partitioned index */
174
175#define RELPERSISTENCE_PERMANENT 'p' /* regular table */
176#define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */
177#define RELPERSISTENCE_TEMP 't' /* temporary table */
178
179/* default selection for replica identity (primary key or nothing) */
180#define REPLICA_IDENTITY_DEFAULT 'd'
181/* no replica identity is logged for this relation */
182#define REPLICA_IDENTITY_NOTHING 'n'
183/* all columns are logged as replica identity */
184#define REPLICA_IDENTITY_FULL 'f'
185/*
186 * an explicitly chosen candidate key's columns are used as replica identity.
187 * Note this will still be set if the index has been dropped; in that case it
188 * has the same meaning as 'n'.
189 */
190#define REPLICA_IDENTITY_INDEX 'i'
191
192/*
193 * Relation kinds that have physical storage. These relations normally have
194 * relfilenode set to non-zero, but it can also be zero if the relation is
195 * mapped.
196 */
197#define RELKIND_HAS_STORAGE(relkind) \
198 ((relkind) == RELKIND_RELATION || \
199 (relkind) == RELKIND_INDEX || \
200 (relkind) == RELKIND_SEQUENCE || \
201 (relkind) == RELKIND_TOASTVALUE || \
202 (relkind) == RELKIND_MATVIEW)
203
204#define RELKIND_HAS_PARTITIONS(relkind) \
205 ((relkind) == RELKIND_PARTITIONED_TABLE || \
206 (relkind) == RELKIND_PARTITIONED_INDEX)
207
208/*
209 * Relation kinds that support tablespaces: All relation kinds with storage
210 * support tablespaces, except that we don't support moving sequences around
211 * into different tablespaces. Partitioned tables and indexes don't have
212 * physical storage, but they have a tablespace settings so that their
213 * children can inherit it.
214 */
215#define RELKIND_HAS_TABLESPACE(relkind) \
216 ((RELKIND_HAS_STORAGE(relkind) || RELKIND_HAS_PARTITIONS(relkind)) \
217 && (relkind) != RELKIND_SEQUENCE)
218
219/*
220 * Relation kinds with a table access method (rd_tableam). Although sequences
221 * use the heap table AM, they are enough of a special case in most uses that
222 * they are not included here. Likewise, partitioned tables can have an access
223 * method defined so that their partitions can inherit it, but they do not set
224 * rd_tableam; hence, this is handled specially outside of this macro.
225 */
226#define RELKIND_HAS_TABLE_AM(relkind) \
227 ((relkind) == RELKIND_RELATION || \
228 (relkind) == RELKIND_TOASTVALUE || \
229 (relkind) == RELKIND_MATVIEW)
230
231extern int errdetail_relkind_not_supported(char relkind);
232
233#endif /* EXPOSE_TO_CLIENT_CODE */
234
235#endif /* PG_CLASS_H */
int16_t int16
Definition: c.h:483
int32_t int32
Definition: c.h:484
float float4
Definition: c.h:586
uint32 TransactionId
Definition: c.h:609
#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
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
NameData relname
Definition: pg_class.h:38
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
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
FormData_pg_class
Definition: pg_class.h:142
unsigned int Oid
Definition: postgres_ext.h:32
Definition: c.h:698
Definition: c.h:644