Line data Source code
1 : /*------------------------------------------------------------------------- 2 : * 3 : * relcache.h 4 : * Relation descriptor cache definitions. 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/utils/relcache.h 11 : * 12 : *------------------------------------------------------------------------- 13 : */ 14 : #ifndef RELCACHE_H 15 : #define RELCACHE_H 16 : 17 : #include "access/tupdesc.h" 18 : #include "common/relpath.h" 19 : #include "nodes/bitmapset.h" 20 : 21 : 22 : /* 23 : * Name of relcache init file(s), used to speed up backend startup 24 : */ 25 : #define RELCACHE_INIT_FILENAME "pg_internal.init" 26 : 27 : typedef struct RelationData *Relation; 28 : 29 : /* ---------------- 30 : * RelationPtr is used in the executor to support index scans 31 : * where we have to keep track of several index relations in an 32 : * array. -cim 9/10/89 33 : * ---------------- 34 : */ 35 : typedef Relation *RelationPtr; 36 : 37 : /* 38 : * Routines to open (lookup) and close a relcache entry 39 : */ 40 : #ifdef USE_ASSERT_CHECKING 41 : extern void AssertCouldGetRelation(void); 42 : #else 43 : static inline void 44 73623708 : AssertCouldGetRelation(void) 45 : { 46 73623708 : } 47 : #endif 48 : extern Relation RelationIdGetRelation(Oid relationId); 49 : extern void RelationClose(Relation relation); 50 : 51 : /* 52 : * Routines to compute/retrieve additional cached information 53 : */ 54 : extern List *RelationGetFKeyList(Relation relation); 55 : extern List *RelationGetIndexList(Relation relation); 56 : extern List *RelationGetStatExtList(Relation relation); 57 : extern Oid RelationGetPrimaryKeyIndex(Relation relation, bool deferrable_ok); 58 : extern Oid RelationGetReplicaIndex(Relation relation); 59 : extern List *RelationGetIndexExpressions(Relation relation); 60 : extern List *RelationGetDummyIndexExpressions(Relation relation); 61 : extern List *RelationGetIndexPredicate(Relation relation); 62 : extern bytea **RelationGetIndexAttOptions(Relation relation, bool copy); 63 : 64 : /* 65 : * Which set of columns to return by RelationGetIndexAttrBitmap. 66 : */ 67 : typedef enum IndexAttrBitmapKind 68 : { 69 : INDEX_ATTR_BITMAP_KEY, 70 : INDEX_ATTR_BITMAP_PRIMARY_KEY, 71 : INDEX_ATTR_BITMAP_IDENTITY_KEY, 72 : INDEX_ATTR_BITMAP_HOT_BLOCKING, 73 : INDEX_ATTR_BITMAP_SUMMARIZED, 74 : } IndexAttrBitmapKind; 75 : 76 : extern Bitmapset *RelationGetIndexAttrBitmap(Relation relation, 77 : IndexAttrBitmapKind attrKind); 78 : 79 : extern Bitmapset *RelationGetIdentityKeyBitmap(Relation relation); 80 : 81 : extern void RelationGetExclusionInfo(Relation indexRelation, 82 : Oid **operators, 83 : Oid **procs, 84 : uint16 **strategies); 85 : 86 : extern void RelationInitIndexAccessInfo(Relation relation); 87 : 88 : /* caller must include pg_publication.h */ 89 : struct PublicationDesc; 90 : extern void RelationBuildPublicationDesc(Relation relation, 91 : struct PublicationDesc *pubdesc); 92 : 93 : extern void RelationInitTableAccessMethod(Relation relation); 94 : 95 : /* 96 : * Routines to support ereport() reports of relation-related errors 97 : */ 98 : extern int errtable(Relation rel); 99 : extern int errtablecol(Relation rel, int attnum); 100 : extern int errtablecolname(Relation rel, const char *colname); 101 : extern int errtableconstraint(Relation rel, const char *conname); 102 : 103 : /* 104 : * Routines for backend startup 105 : */ 106 : extern void RelationCacheInitialize(void); 107 : extern void RelationCacheInitializePhase2(void); 108 : extern void RelationCacheInitializePhase3(void); 109 : 110 : /* 111 : * Routine to create a relcache entry for an about-to-be-created relation 112 : */ 113 : extern Relation RelationBuildLocalRelation(const char *relname, 114 : Oid relnamespace, 115 : TupleDesc tupDesc, 116 : Oid relid, 117 : Oid accessmtd, 118 : RelFileNumber relfilenumber, 119 : Oid reltablespace, 120 : bool shared_relation, 121 : bool mapped_relation, 122 : char relpersistence, 123 : char relkind); 124 : 125 : /* 126 : * Routines to manage assignment of new relfilenumber to a relation 127 : */ 128 : extern void RelationSetNewRelfilenumber(Relation relation, char persistence); 129 : extern void RelationAssumeNewRelfilelocator(Relation relation); 130 : 131 : /* 132 : * Routines for flushing/rebuilding relcache entries in various scenarios 133 : */ 134 : extern void RelationForgetRelation(Oid rid); 135 : 136 : extern void RelationCacheInvalidateEntry(Oid relationId); 137 : 138 : extern void RelationCacheInvalidate(bool debug_discard); 139 : 140 : #ifdef USE_ASSERT_CHECKING 141 : extern void AssertPendingSyncs_RelationCache(void); 142 : #else 143 : #define AssertPendingSyncs_RelationCache() do {} while (0) 144 : #endif 145 : extern void AtEOXact_RelationCache(bool isCommit); 146 : extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid, 147 : SubTransactionId parentSubid); 148 : 149 : /* 150 : * Routines to help manage rebuilding of relcache init files 151 : */ 152 : extern bool RelationIdIsInInitFile(Oid relationId); 153 : extern void RelationCacheInitFilePreInvalidate(void); 154 : extern void RelationCacheInitFilePostInvalidate(void); 155 : extern void RelationCacheInitFileRemove(void); 156 : 157 : /* should be used only by relcache.c and catcache.c */ 158 : extern PGDLLIMPORT bool criticalRelcachesBuilt; 159 : 160 : /* should be used only by relcache.c and postinit.c */ 161 : extern PGDLLIMPORT bool criticalSharedRelcachesBuilt; 162 : 163 : #endif /* RELCACHE_H */