1 /*------------------------------------------------------------------------- 2 * 3 * relcache.h 4 * Relation descriptor cache definitions. 5 * 6 * 7 * Portions Copyright (c) 1996-2020, 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 void RelationGetExclusionInfo(Relation indexRelation, 68 Oid **operators, 69 Oid **procs, 70 uint16 **strategies); 71 72 extern void RelationInitIndexAccessInfo(Relation relation); 73 74 /* caller must include pg_publication.h */ 75 struct PublicationActions; 76 extern struct PublicationActions *GetRelationPublicationActions(Relation relation); 77 78 extern void RelationInitTableAccessMethod(Relation relation); 79 80 /* 81 * Routines to support ereport() reports of relation-related errors 82 */ 83 extern int errtable(Relation rel); 84 extern int errtablecol(Relation rel, int attnum); 85 extern int errtablecolname(Relation rel, const char *colname); 86 extern int errtableconstraint(Relation rel, const char *conname); 87 88 /* 89 * Routines for backend startup 90 */ 91 extern void RelationCacheInitialize(void); 92 extern void RelationCacheInitializePhase2(void); 93 extern void RelationCacheInitializePhase3(void); 94 95 /* 96 * Routine to create a relcache entry for an about-to-be-created relation 97 */ 98 extern Relation RelationBuildLocalRelation(const char *relname, 99 Oid relnamespace, 100 TupleDesc tupDesc, 101 Oid relid, 102 Oid accessmtd, 103 Oid relfilenode, 104 Oid reltablespace, 105 bool shared_relation, 106 bool mapped_relation, 107 char relpersistence, 108 char relkind); 109 110 /* 111 * Routines to manage assignment of new relfilenode to a relation 112 */ 113 extern void RelationSetNewRelfilenode(Relation relation, char persistence); 114 extern void RelationAssumeNewRelfilenode(Relation relation); 115 116 /* 117 * Routines for flushing/rebuilding relcache entries in various scenarios 118 */ 119 extern void RelationForgetRelation(Oid rid); 120 121 extern void RelationCacheInvalidateEntry(Oid relationId); 122 123 extern void RelationCacheInvalidate(bool debug_discard); 124 125 extern void RelationCloseSmgrByOid(Oid relationId); 126 127 #ifdef USE_ASSERT_CHECKING 128 extern void AssertPendingSyncs_RelationCache(void); 129 #else 130 #define AssertPendingSyncs_RelationCache() do {} while (0) 131 #endif 132 extern void AtEOXact_RelationCache(bool isCommit); 133 extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid, 134 SubTransactionId parentSubid); 135 136 /* 137 * Routines to help manage rebuilding of relcache init files 138 */ 139 extern bool RelationIdIsInInitFile(Oid relationId); 140 extern void RelationCacheInitFilePreInvalidate(void); 141 extern void RelationCacheInitFilePostInvalidate(void); 142 extern void RelationCacheInitFileRemove(void); 143 144 /* should be used only by relcache.c and catcache.c */ 145 extern bool criticalRelcachesBuilt; 146 147 /* should be used only by relcache.c and postinit.c */ 148 extern bool criticalSharedRelcachesBuilt; 149 150 #endif /* RELCACHE_H */ 151