1/*-------------------------------------------------------------------------
2 *
3 * relcache.h
4 * Relation descriptor cache definitions.
5 *
6 *
7 * Portions Copyright (c) 1996-2019, 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
26typedef 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 */
34typedef Relation *RelationPtr;
35
36/*
37 * Routines to open (lookup) and close a relcache entry
38 */
39extern Relation RelationIdGetRelation(Oid relationId);
40extern void RelationClose(Relation relation);
41
42/*
43 * Routines to compute/retrieve additional cached information
44 */
45extern List *RelationGetFKeyList(Relation relation);
46extern List *RelationGetIndexList(Relation relation);
47extern List *RelationGetStatExtList(Relation relation);
48extern Oid RelationGetPrimaryKeyIndex(Relation relation);
49extern Oid RelationGetReplicaIndex(Relation relation);
50extern List *RelationGetIndexExpressions(Relation relation);
51extern List *RelationGetIndexPredicate(Relation relation);
52
53typedef enum IndexAttrBitmapKind
54{
55 INDEX_ATTR_BITMAP_ALL,
56 INDEX_ATTR_BITMAP_KEY,
57 INDEX_ATTR_BITMAP_PRIMARY_KEY,
58 INDEX_ATTR_BITMAP_IDENTITY_KEY
59} IndexAttrBitmapKind;
60
61extern Bitmapset *RelationGetIndexAttrBitmap(Relation relation,
62 IndexAttrBitmapKind keyAttrs);
63
64extern void RelationGetExclusionInfo(Relation indexRelation,
65 Oid **operators,
66 Oid **procs,
67 uint16 **strategies);
68
69extern void RelationInitIndexAccessInfo(Relation relation);
70
71/* caller must include pg_publication.h */
72struct PublicationActions;
73extern struct PublicationActions *GetRelationPublicationActions(Relation relation);
74
75extern void RelationInitTableAccessMethod(Relation relation);
76
77/*
78 * Routines to support ereport() reports of relation-related errors
79 */
80extern int errtable(Relation rel);
81extern int errtablecol(Relation rel, int attnum);
82extern int errtablecolname(Relation rel, const char *colname);
83extern int errtableconstraint(Relation rel, const char *conname);
84
85/*
86 * Routines for backend startup
87 */
88extern void RelationCacheInitialize(void);
89extern void RelationCacheInitializePhase2(void);
90extern void RelationCacheInitializePhase3(void);
91
92/*
93 * Routine to create a relcache entry for an about-to-be-created relation
94 */
95extern Relation RelationBuildLocalRelation(const char *relname,
96 Oid relnamespace,
97 TupleDesc tupDesc,
98 Oid relid,
99 Oid accessmtd,
100 Oid relfilenode,
101 Oid reltablespace,
102 bool shared_relation,
103 bool mapped_relation,
104 char relpersistence,
105 char relkind);
106
107/*
108 * Routine to manage assignment of new relfilenode to a relation
109 */
110extern void RelationSetNewRelfilenode(Relation relation, char persistence);
111
112/*
113 * Routines for flushing/rebuilding relcache entries in various scenarios
114 */
115extern void RelationForgetRelation(Oid rid);
116
117extern void RelationCacheInvalidateEntry(Oid relationId);
118
119extern void RelationCacheInvalidate(void);
120
121extern void RelationCloseSmgrByOid(Oid relationId);
122
123extern void AtEOXact_RelationCache(bool isCommit);
124extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid,
125 SubTransactionId parentSubid);
126
127/*
128 * Routines to help manage rebuilding of relcache init files
129 */
130extern bool RelationIdIsInInitFile(Oid relationId);
131extern void RelationCacheInitFilePreInvalidate(void);
132extern void RelationCacheInitFilePostInvalidate(void);
133extern void RelationCacheInitFileRemove(void);
134
135/* should be used only by relcache.c and catcache.c */
136extern bool criticalRelcachesBuilt;
137
138/* should be used only by relcache.c and postinit.c */
139extern bool criticalSharedRelcachesBuilt;
140
141#endif /* RELCACHE_H */
142