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