PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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 */
33
35{
36 /* oid */
37 Oid oid;
38
39 /* class name */
41
42 /* OID of namespace containing this class */
44
45 /* OID of entry in pg_type for relation's implicit row type, if any */
47
48 /* OID of entry in pg_type for underlying composite type, if any */
50
51 /* class owner */
53
54 /* access method; 0 if not a table / index */
56
57 /* identifier of physical storage file */
58 /* relfilenode == 0 means it is a "mapped" relation, see relmapper.c */
60
61 /* identifier of table space for relation (0 means default for database) */
63
64 /* # of blocks (not always up-to-date) */
65 int32 relpages BKI_DEFAULT(0);
66
67 /* # of tuples (not always up-to-date; -1 means "unknown") */
68 float4 reltuples BKI_DEFAULT(-1);
69
70 /* # of all-visible blocks (not always up-to-date) */
71 int32 relallvisible BKI_DEFAULT(0);
72
73 /* # of all-frozen blocks (not always up-to-date) */
74 int32 relallfrozen BKI_DEFAULT(0);
75
76 /* OID of toast table; 0 if none */
78
79 /* T if has (or has had) any indexes */
81
82 /* T if shared across databases */
84
85 /* see RELPERSISTENCE_xxx constants below */
86 char relpersistence BKI_DEFAULT(p);
87
88 /* see RELKIND_xxx constants below */
89 char relkind BKI_DEFAULT(r);
90
91 /* number of user attributes */
92 int16 relnatts BKI_DEFAULT(0); /* genbki.pl will fill this in */
93
94 /*
95 * Class pg_attribute must contain exactly "relnatts" user attributes
96 * (with attnums ranging from 1 to relnatts) for this class. It may also
97 * contain entries with negative attnums for system attributes.
98 */
99
100 /* # of CHECK constraints for class */
102
103 /* has (or has had) any rules */
104 bool relhasrules BKI_DEFAULT(f);
105
106 /* has (or has had) any TRIGGERs */
108
109 /* has (or has had) child tables or indexes */
111
112 /* row security is enabled or not */
114
115 /* row security forced for owners or not */
117
118 /* matview currently holds query results */
119 bool relispopulated BKI_DEFAULT(t);
120
121 /* see REPLICA_IDENTITY_xxx constants */
122 char relreplident BKI_DEFAULT(n);
123
124 /* is relation a partition? */
126
127 /* link to original rel during table rewrite; otherwise 0 */
129
130 /* all Xids < this are frozen in this rel */
131 TransactionId relfrozenxid BKI_DEFAULT(3); /* FirstNormalTransactionId */
132
133 /* all multixacts in this rel are >= this; it is really a MultiXactId */
134 TransactionId relminmxid BKI_DEFAULT(1); /* FirstMultiXactId */
135
136#ifdef CATALOG_VARLEN /* variable-length fields start here */
137 /* NOTE: These fields are not present in a relcache entry's rd_rel field. */
138 /* access permissions */
140
141 /* access-method-specific options */
142 text reloptions[1] BKI_DEFAULT(_null_);
143
144 /* partition bound node tree */
146#endif
148
150
151/* Size of fixed part of pg_class tuples, not counting var-length fields */
152#define CLASS_TUPLE_SIZE \
153 (offsetof(FormData_pg_class,relminmxid) + sizeof(TransactionId))
154
155/* ----------------
156 * Form_pg_class corresponds to a pointer to a tuple with
157 * the format of pg_class relation.
158 * ----------------
159 */
161
165
168
169#ifdef EXPOSE_TO_CLIENT_CODE
170
171#define RELKIND_RELATION 'r' /* ordinary table */
172#define RELKIND_INDEX 'i' /* secondary index */
173#define RELKIND_SEQUENCE 'S' /* sequence object */
174#define RELKIND_TOASTVALUE 't' /* for out-of-line values */
175#define RELKIND_VIEW 'v' /* view */
176#define RELKIND_MATVIEW 'm' /* materialized view */
177#define RELKIND_COMPOSITE_TYPE 'c' /* composite type */
178#define RELKIND_FOREIGN_TABLE 'f' /* foreign table */
179#define RELKIND_PARTITIONED_TABLE 'p' /* partitioned table */
180#define RELKIND_PARTITIONED_INDEX 'I' /* partitioned index */
181
182#define RELPERSISTENCE_PERMANENT 'p' /* regular table */
183#define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */
184#define RELPERSISTENCE_TEMP 't' /* temporary table */
185
186/* default selection for replica identity (primary key or nothing) */
187#define REPLICA_IDENTITY_DEFAULT 'd'
188/* no replica identity is logged for this relation */
189#define REPLICA_IDENTITY_NOTHING 'n'
190/* all columns are logged as replica identity */
191#define REPLICA_IDENTITY_FULL 'f'
192/*
193 * an explicitly chosen candidate key's columns are used as replica identity.
194 * Note this will still be set if the index has been dropped; in that case it
195 * has the same meaning as 'n'.
196 */
197#define REPLICA_IDENTITY_INDEX 'i'
198
199/*
200 * Relation kinds that have physical storage. These relations normally have
201 * relfilenode set to non-zero, but it can also be zero if the relation is
202 * mapped.
203 */
204#define RELKIND_HAS_STORAGE(relkind) \
205 ((relkind) == RELKIND_RELATION || \
206 (relkind) == RELKIND_INDEX || \
207 (relkind) == RELKIND_SEQUENCE || \
208 (relkind) == RELKIND_TOASTVALUE || \
209 (relkind) == RELKIND_MATVIEW)
210
211#define RELKIND_HAS_PARTITIONS(relkind) \
212 ((relkind) == RELKIND_PARTITIONED_TABLE || \
213 (relkind) == RELKIND_PARTITIONED_INDEX)
214
215/*
216 * Relation kinds that support tablespaces: All relation kinds with storage
217 * support tablespaces, except that we don't support moving sequences around
218 * into different tablespaces. Partitioned tables and indexes don't have
219 * physical storage, but they have a tablespace settings so that their
220 * children can inherit it.
221 */
222#define RELKIND_HAS_TABLESPACE(relkind) \
223 ((RELKIND_HAS_STORAGE(relkind) || RELKIND_HAS_PARTITIONS(relkind)) \
224 && (relkind) != RELKIND_SEQUENCE)
225
226/*
227 * Relation kinds with a table access method (rd_tableam). Although sequences
228 * use the heap table AM, they are enough of a special case in most uses that
229 * they are not included here. Likewise, partitioned tables can have an access
230 * method defined so that their partitions can inherit it, but they do not set
231 * rd_tableam; hence, this is handled specially outside of this macro.
232 */
233#define RELKIND_HAS_TABLE_AM(relkind) \
234 ((relkind) == RELKIND_RELATION || \
235 (relkind) == RELKIND_TOASTVALUE || \
236 (relkind) == RELKIND_MATVIEW)
237
238#endif /* EXPOSE_TO_CLIENT_CODE */
239
240extern int errdetail_relkind_not_supported(char relkind);
241
242#endif /* PG_CLASS_H */
int16_t int16
Definition c.h:553
int32_t int32
Definition c.h:554
float float4
Definition c.h:655
uint32 TransactionId
Definition c.h:678
#define BEGIN_CATALOG_STRUCT
Definition genbki.h:37
#define DECLARE_UNIQUE_INDEX_PKEY(name, oid, oidmacro, tblname, decl)
Definition genbki.h:105
#define BKI_LOOKUP(catalog)
Definition genbki.h:65
#define END_CATALOG_STRUCT
Definition genbki.h:38
#define BKI_DEFAULT(value)
Definition genbki.h:54
#define BKI_LOOKUP_OPT(catalog)
Definition genbki.h:66
#define DECLARE_UNIQUE_INDEX(name, oid, oidmacro, tblname, decl)
Definition genbki.h:104
#define CATALOG(name, oid, oidmacro)
Definition genbki.h:42
#define BKI_BOOTSTRAP
Definition genbki.h:45
#define DECLARE_INDEX(name, oid, oidmacro, tblname, decl)
Definition genbki.h:103
#define MAKE_SYSCACHE(name, idxname, nbuckets)
Definition genbki.h:146
#define BKI_ROWTYPE_OID(oid, oidmacro)
Definition genbki.h:47
BEGIN_CATALOG_STRUCT RelationRelation_Rowtype_Id BKI_SCHEMA_MACRO
Definition pg_class.h:35
NameData relname
Definition pg_class.h:40
FormData_pg_class * Form_pg_class
Definition pg_class.h:160
int errdetail_relkind_not_supported(char relkind)
Definition pg_class.c:24
FormData_pg_class
Definition pg_class.h:147
unsigned int Oid
static int fb(int x)
Definition c.h:772
Definition c.h:718