PostgreSQL Source Code  git master
namespace.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * namespace.h
4  * prototypes for functions in backend/catalog/namespace.c
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/catalog/namespace.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef NAMESPACE_H
15 #define NAMESPACE_H
16 
17 #include "nodes/primnodes.h"
18 #include "storage/lock.h"
19 
20 
21 /*
22  * This structure holds a list of possible functions or operators
23  * found by namespace lookup. Each function/operator is identified
24  * by OID and by argument types; the list must be pruned by type
25  * resolution rules that are embodied in the parser, not here.
26  * See FuncnameGetCandidates's comments for more info.
27  */
28 typedef struct _FuncCandidateList
29 {
31  int pathpos; /* for internal use of namespace lookup */
32  Oid oid; /* the function or operator's OID */
33  int nargs; /* number of arg types returned */
34  int nvargs; /* number of args to become variadic array */
35  int ndargs; /* number of defaulted args */
36  int *argnumbers; /* args' positional indexes, if named call */
37  Oid args[FLEXIBLE_ARRAY_MEMBER]; /* arg types */
39 
40 /*
41  * Result of checkTempNamespaceStatus
42  */
43 typedef enum TempNamespaceStatus
44 {
45  TEMP_NAMESPACE_NOT_TEMP, /* nonexistent, or non-temp namespace */
46  TEMP_NAMESPACE_IDLE, /* exists, belongs to no active session */
47  TEMP_NAMESPACE_IN_USE /* belongs to some active session */
49 
50 /*
51  * Structure for xxxOverrideSearchPath functions
52  *
53  * The generation counter is private to namespace.c and shouldn't be touched
54  * by other code. It can be initialized to zero if necessary (that means
55  * "not known equal to the current active path").
56  */
57 typedef struct OverrideSearchPath
58 {
59  List *schemas; /* OIDs of explicitly named schemas */
60  bool addCatalog; /* implicitly prepend pg_catalog? */
61  bool addTemp; /* implicitly prepend temp schema? */
62  uint64 generation; /* for quick detection of equality to active */
64 
65 /*
66  * Option flag bits for RangeVarGetRelidExtended().
67  */
68 typedef enum RVROption
69 {
70  RVR_MISSING_OK = 1 << 0, /* don't error if relation doesn't exist */
71  RVR_NOWAIT = 1 << 1, /* error if relation cannot be locked */
72  RVR_SKIP_LOCKED = 1 << 2 /* skip if relation cannot be locked */
73 } RVROption;
74 
75 typedef void (*RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId,
76  Oid oldRelId, void *callback_arg);
77 
78 #define RangeVarGetRelid(relation, lockmode, missing_ok) \
79  RangeVarGetRelidExtended(relation, lockmode, \
80  (missing_ok) ? RVR_MISSING_OK : 0, NULL, NULL)
81 
82 extern Oid RangeVarGetRelidExtended(const RangeVar *relation,
83  LOCKMODE lockmode, uint32 flags,
85  void *callback_arg);
86 extern Oid RangeVarGetCreationNamespace(const RangeVar *newRelation);
88  LOCKMODE lockmode,
89  Oid *existing_relation_id);
90 extern void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid);
91 extern Oid RelnameGetRelid(const char *relname);
92 extern bool RelationIsVisible(Oid relid);
93 
94 extern Oid TypenameGetTypid(const char *typname);
95 extern Oid TypenameGetTypidExtended(const char *typname, bool temp_ok);
96 extern bool TypeIsVisible(Oid typid);
97 
99  int nargs, List *argnames,
100  bool expand_variadic,
101  bool expand_defaults,
102  bool missing_ok);
103 extern bool FunctionIsVisible(Oid funcid);
104 
105 extern Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright);
106 extern FuncCandidateList OpernameGetCandidates(List *names, char oprkind,
107  bool missing_schema_ok);
108 extern bool OperatorIsVisible(Oid oprid);
109 
110 extern Oid OpclassnameGetOpcid(Oid amid, const char *opcname);
111 extern bool OpclassIsVisible(Oid opcid);
112 
113 extern Oid OpfamilynameGetOpfid(Oid amid, const char *opfname);
114 extern bool OpfamilyIsVisible(Oid opfid);
115 
116 extern Oid CollationGetCollid(const char *collname);
117 extern bool CollationIsVisible(Oid collid);
118 
119 extern Oid ConversionGetConid(const char *conname);
120 extern bool ConversionIsVisible(Oid conid);
121 
122 extern Oid get_statistics_object_oid(List *names, bool missing_ok);
123 extern bool StatisticsObjIsVisible(Oid relid);
124 
125 extern Oid get_ts_parser_oid(List *names, bool missing_ok);
126 extern bool TSParserIsVisible(Oid prsId);
127 
128 extern Oid get_ts_dict_oid(List *names, bool missing_ok);
129 extern bool TSDictionaryIsVisible(Oid dictId);
130 
131 extern Oid get_ts_template_oid(List *names, bool missing_ok);
132 extern bool TSTemplateIsVisible(Oid tmplId);
133 
134 extern Oid get_ts_config_oid(List *names, bool missing_ok);
135 extern bool TSConfigIsVisible(Oid cfgid);
136 
137 extern void DeconstructQualifiedName(List *names,
138  char **nspname_p,
139  char **objname_p);
140 extern Oid LookupNamespaceNoError(const char *nspname);
141 extern Oid LookupExplicitNamespace(const char *nspname, bool missing_ok);
142 extern Oid get_namespace_oid(const char *nspname, bool missing_ok);
143 
144 extern Oid LookupCreationNamespace(const char *nspname);
145 extern void CheckSetNamespace(Oid oldNspOid, Oid nspOid);
146 extern Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p);
147 extern RangeVar *makeRangeVarFromNameList(List *names);
148 extern char *NameListToString(List *names);
149 extern char *NameListToQuotedString(List *names);
150 
151 extern bool isTempNamespace(Oid namespaceId);
152 extern bool isTempToastNamespace(Oid namespaceId);
153 extern bool isTempOrTempToastNamespace(Oid namespaceId);
154 extern bool isAnyTempNamespace(Oid namespaceId);
155 extern bool isOtherTempNamespace(Oid namespaceId);
157 extern int GetTempNamespaceBackendId(Oid namespaceId);
158 extern Oid GetTempToastNamespace(void);
159 extern void GetTempNamespaceState(Oid *tempNamespaceId,
160  Oid *tempToastNamespaceId);
161 extern void SetTempNamespaceState(Oid tempNamespaceId,
162  Oid tempToastNamespaceId);
163 extern void ResetTempTableNamespace(void);
164 
168 extern void PushOverrideSearchPath(OverrideSearchPath *newpath);
169 extern void PopOverrideSearchPath(void);
170 
171 extern Oid get_collation_oid(List *collname, bool missing_ok);
172 extern Oid get_conversion_oid(List *conname, bool missing_ok);
173 extern Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding);
174 
175 
176 /* initialization & transaction cleanup code */
177 extern void InitializeSearchPath(void);
178 extern void AtEOXact_Namespace(bool isCommit, bool parallel);
179 extern void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid,
180  SubTransactionId parentSubid);
181 
182 /* stuff for search_path GUC variable */
183 extern char *namespace_search_path;
184 
185 extern List *fetch_search_path(bool includeImplicit);
186 extern int fetch_search_path_array(Oid *sarray, int sarray_len);
187 
188 #endif /* NAMESPACE_H */
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:1747
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2737
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *newRelation, LOCKMODE lockmode, Oid *existing_relation_id)
Definition: namespace.c:534
int GetTempNamespaceBackendId(Oid namespaceId)
Definition: namespace.c:3274
Oid CollationGetCollid(const char *collname)
Definition: namespace.c:2014
Oid GetTempToastNamespace(void)
Definition: namespace.c:3299
void PushOverrideSearchPath(OverrideSearchPath *newpath)
Definition: namespace.c:3490
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1833
Oid TypenameGetTypidExtended(const char *typname, bool temp_ok)
Definition: namespace.c:784
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
Definition: namespace.c:2893
bool FunctionIsVisible(Oid funcid)
Definition: namespace.c:1413
int LOCKMODE
Definition: lockdefs.h:26
void GetTempNamespaceState(Oid *tempNamespaceId, Oid *tempToastNamespaceId)
Definition: namespace.c:3313
Oid oprid(Operator op)
Definition: parse_oper.c:245
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2426
void ResetTempTableNamespace(void)
Definition: namespace.c:4261
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2679
char * namespace_search_path
Definition: namespace.c:198
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:283
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:2611
uint32 SubTransactionId
Definition: c.h:524
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
Oid LookupCreationNamespace(const char *nspname)
Definition: namespace.c:2936
OverrideSearchPath * GetOverrideSearchPath(MemoryContext context)
Definition: namespace.c:3360
signed int int32
Definition: c.h:362
struct OverrideSearchPath OverrideSearchPath
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition: namespace.c:3710
Oid RelnameGetRelid(const char *relname)
Definition: namespace.c:680
Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p)
Definition: namespace.c:2995
bool isTempOrTempToastNamespace(Oid namespaceId)
Definition: namespace.c:3181
Oid args[FLEXIBLE_ARRAY_MEMBER]
Definition: namespace.h:37
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3157
Oid get_collation_oid(List *collname, bool missing_ok)
Definition: namespace.c:3601
Oid LookupNamespaceNoError(const char *nspname)
Definition: namespace.c:2863
void DeconstructQualifiedName(List *names, char **nspname_p, char **objname_p)
Definition: namespace.c:2809
struct _FuncCandidateList * FuncCandidateList
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
Oid get_conversion_oid(List *conname, bool missing_ok)
Definition: namespace.c:3655
char * NameListToQuotedString(List *names)
Definition: namespace.c:3136
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2131
Oid ConversionGetConid(const char *conname)
Definition: namespace.c:2099
void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid)
Definition: namespace.c:4132
unsigned int uint32
Definition: c.h:374
Oid TypenameGetTypid(const char *typname)
Definition: namespace.c:771
struct _FuncCandidateList * next
Definition: namespace.h:30
bool OverrideSearchPathMatchesCurrent(OverrideSearchPath *path)
Definition: namespace.c:3419
void InitializeSearchPath(void)
Definition: namespace.c:4324
TempNamespaceStatus checkTempNamespaceStatus(Oid namespaceId)
Definition: namespace.c:3237
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2178
OverrideSearchPath * CopyOverrideSearchPath(OverrideSearchPath *path)
Definition: namespace.c:3397
NameData typname
Definition: pg_type.h:41
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2553
RVROption
Definition: namespace.h:68
char * NameListToString(List *names)
Definition: namespace.c:3102
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3043
void PopOverrideSearchPath(void)
Definition: namespace.c:3557
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3195
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
bool OpfamilyIsVisible(Oid opfid)
Definition: namespace.c:1916
TempNamespaceStatus
Definition: namespace.h:43
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2358
void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid)
Definition: namespace.c:641
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok)
Definition: namespace.c:1587
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:236
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2300
void CheckSetNamespace(Oid oldNspOid, Oid nspOid)
Definition: namespace.c:2967
bool RelationIsVisible(Oid relid)
Definition: namespace.c:708
bool isTempToastNamespace(Oid namespaceId)
Definition: namespace.c:3169
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2484
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool missing_ok)
Definition: namespace.c:942
bool TypeIsVisible(Oid typid)
Definition: namespace.c:816
Oid OpclassnameGetOpcid(Oid amid, const char *opcname)
Definition: namespace.c:1800
void(* RangeVarGetRelidCallback)(const RangeVar *relation, Oid relId, Oid oldRelId, void *callback_arg)
Definition: namespace.h:75
void SetTempNamespaceState(Oid tempNamespaceId, Oid tempToastNamespaceId)
Definition: namespace.c:3329
int fetch_search_path_array(Oid *sarray, int sarray_len)
Definition: namespace.c:4423
void AtEOXact_Namespace(bool isCommit, bool parallel)
Definition: namespace.c:4064
bool isOtherTempNamespace(Oid namespaceId)
Definition: namespace.c:3218
Oid RangeVarGetCreationNamespace(const RangeVar *newRelation)
Definition: namespace.c:449
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2048
Definition: pg_list.h:50
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition: namespace.c:1484
Oid OpfamilynameGetOpfid(Oid amid, const char *opfname)
Definition: namespace.c:1883
bool StatisticsObjIsVisible(Oid relid)
Definition: namespace.c:2235
List * fetch_search_path(bool includeImplicit)
Definition: namespace.c:4383