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