codekingpro/portable-devtools
115k
1/*-------------------------------------------------------------------------2 *3 * pg_class.h4 * definition of the "relation" system catalog (pg_class)5 *6 *7 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group8 * Portions Copyright (c) 1994, Regents of the University of California9 *10 * src/include/catalog/pg_class.h11 *12 * NOTES13 * The Catalog.pm module reads this file and derives schema14 * information.15 *16 *-------------------------------------------------------------------------17 */18#ifndef PG_CLASS_H19#define PG_CLASS_H20 21#include "catalog/genbki.h"22#include "catalog/pg_class_d.h"23 24/* ----------------25 * pg_class definition. cpp turns this into26 * typedef struct FormData_pg_class27 *28 * Note that the BKI_DEFAULT values below are only used for rows describing29 * 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_MACRO33{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(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 attributes91 * (with attnums ranging from 1 to relnatts) for this class. It may also92 * 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#endif142} 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 with150 * the format of pg_class relation.151 * ----------------152 */153typedef FormData_pg_class *Form_pg_class;154 155DECLARE_UNIQUE_INDEX_PKEY(pg_class_oid_index, 2662, ClassOidIndexId, on pg_class using btree(oid oid_ops));156DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, ClassNameNspIndexId, on pg_class using btree(relname name_ops, relnamespace oid_ops));157DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 3455, ClassTblspcRelfilenodeIndexId, on pg_class using btree(reltablespace oid_ops, relfilenode oid_ops));158 159#ifdef EXPOSE_TO_CLIENT_CODE160 161#define RELKIND_RELATION 'r' /* ordinary table */162#define RELKIND_INDEX 'i' /* secondary index */163#define RELKIND_SEQUENCE 'S' /* sequence object */164#define RELKIND_TOASTVALUE 't' /* for out-of-line values */165#define RELKIND_VIEW 'v' /* view */166#define RELKIND_MATVIEW 'm' /* materialized view */167#define RELKIND_COMPOSITE_TYPE 'c' /* composite type */168#define RELKIND_FOREIGN_TABLE 'f' /* foreign table */169#define RELKIND_PARTITIONED_TABLE 'p' /* partitioned table */170#define RELKIND_PARTITIONED_INDEX 'I' /* partitioned index */171 172#define RELPERSISTENCE_PERMANENT 'p' /* regular table */173#define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */174#define RELPERSISTENCE_TEMP 't' /* temporary table */175 176/* default selection for replica identity (primary key or nothing) */177#define REPLICA_IDENTITY_DEFAULT 'd'178/* no replica identity is logged for this relation */179#define REPLICA_IDENTITY_NOTHING 'n'180/* all columns are logged as replica identity */181#define REPLICA_IDENTITY_FULL 'f'182/*183 * an explicitly chosen candidate key's columns are used as replica identity.184 * Note this will still be set if the index has been dropped; in that case it185 * has the same meaning as 'n'.186 */187#define REPLICA_IDENTITY_INDEX 'i'188 189/*190 * Relation kinds that have physical storage. These relations normally have191 * relfilenode set to non-zero, but it can also be zero if the relation is192 * mapped.193 */194#define RELKIND_HAS_STORAGE(relkind) \195 ((relkind) == RELKIND_RELATION || \196 (relkind) == RELKIND_INDEX || \197 (relkind) == RELKIND_SEQUENCE || \198 (relkind) == RELKIND_TOASTVALUE || \199 (relkind) == RELKIND_MATVIEW)200 201#define RELKIND_HAS_PARTITIONS(relkind) \202 ((relkind) == RELKIND_PARTITIONED_TABLE || \203 (relkind) == RELKIND_PARTITIONED_INDEX)204 205/*206 * Relation kinds that support tablespaces: All relation kinds with storage207 * support tablespaces, except that we don't support moving sequences around208 * into different tablespaces. Partitioned tables and indexes don't have209 * physical storage, but they have a tablespace settings so that their210 * children can inherit it.211 */212#define RELKIND_HAS_TABLESPACE(relkind) \213 ((RELKIND_HAS_STORAGE(relkind) || RELKIND_HAS_PARTITIONS(relkind)) \214 && (relkind) != RELKIND_SEQUENCE)215 216/*217 * Relation kinds with a table access method (rd_tableam). Although sequences218 * use the heap table AM, they are enough of a special case in most uses that219 * they are not included here.220 */221#define RELKIND_HAS_TABLE_AM(relkind) \222 ((relkind) == RELKIND_RELATION || \223 (relkind) == RELKIND_TOASTVALUE || \224 (relkind) == RELKIND_MATVIEW)225 226extern int errdetail_relkind_not_supported(char relkind);227 228#endif /* EXPOSE_TO_CLIENT_CODE */229 230#endif /* PG_CLASS_H */231 