1/*-------------------------------------------------------------------------
2 *
3 * namespace.h
4 * prototypes for functions in backend/catalog/namespace.c
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/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 */
28typedef struct _FuncCandidateList
29{
30 struct _FuncCandidateList *next;
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 */
38} *FuncCandidateList;
39
40/*
41 * Structure for xxxOverrideSearchPath functions
42 */
43typedef struct OverrideSearchPath
44{
45 List *schemas; /* OIDs of explicitly named schemas */
46 bool addCatalog; /* implicitly prepend pg_catalog? */
47 bool addTemp; /* implicitly prepend temp schema? */
48} OverrideSearchPath;
49
50/*
51 * Option flag bits for RangeVarGetRelidExtended().
52 */
53typedef enum RVROption
54{
55 RVR_MISSING_OK = 1 << 0, /* don't error if relation doesn't exist */
56 RVR_NOWAIT = 1 << 1, /* error if relation cannot be locked */
57 RVR_SKIP_LOCKED = 1 << 2 /* skip if relation cannot be locked */
58} RVROption;
59
60typedef void (*RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId,
61 Oid oldRelId, void *callback_arg);
62
63#define RangeVarGetRelid(relation, lockmode, missing_ok) \
64 RangeVarGetRelidExtended(relation, lockmode, \
65 (missing_ok) ? RVR_MISSING_OK : 0, NULL, NULL)
66
67extern Oid RangeVarGetRelidExtended(const RangeVar *relation,
68 LOCKMODE lockmode, uint32 flags,
69 RangeVarGetRelidCallback callback,
70 void *callback_arg);
71extern Oid RangeVarGetCreationNamespace(const RangeVar *newRelation);
72extern Oid RangeVarGetAndCheckCreationNamespace(RangeVar *newRelation,
73 LOCKMODE lockmode,
74 Oid *existing_relation_id);
75extern void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid);
76extern Oid RelnameGetRelid(const char *relname);
77extern bool RelationIsVisible(Oid relid);
78
79extern Oid TypenameGetTypid(const char *typname);
80extern Oid TypenameGetTypidExtended(const char *typname, bool temp_ok);
81extern bool TypeIsVisible(Oid typid);
82
83extern FuncCandidateList FuncnameGetCandidates(List *names,
84 int nargs, List *argnames,
85 bool expand_variadic,
86 bool expand_defaults,
87 bool missing_ok);
88extern bool FunctionIsVisible(Oid funcid);
89
90extern Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright);
91extern FuncCandidateList OpernameGetCandidates(List *names, char oprkind,
92 bool missing_schema_ok);
93extern bool OperatorIsVisible(Oid oprid);
94
95extern Oid OpclassnameGetOpcid(Oid amid, const char *opcname);
96extern bool OpclassIsVisible(Oid opcid);
97
98extern Oid OpfamilynameGetOpfid(Oid amid, const char *opfname);
99extern bool OpfamilyIsVisible(Oid opfid);
100
101extern Oid CollationGetCollid(const char *collname);
102extern bool CollationIsVisible(Oid collid);
103
104extern Oid ConversionGetConid(const char *conname);
105extern bool ConversionIsVisible(Oid conid);
106
107extern Oid get_statistics_object_oid(List *names, bool missing_ok);
108extern bool StatisticsObjIsVisible(Oid stxid);
109
110extern Oid get_ts_parser_oid(List *names, bool missing_ok);
111extern bool TSParserIsVisible(Oid prsId);
112
113extern Oid get_ts_dict_oid(List *names, bool missing_ok);
114extern bool TSDictionaryIsVisible(Oid dictId);
115
116extern Oid get_ts_template_oid(List *names, bool missing_ok);
117extern bool TSTemplateIsVisible(Oid tmplId);
118
119extern Oid get_ts_config_oid(List *names, bool missing_ok);
120extern bool TSConfigIsVisible(Oid cfgid);
121
122extern void DeconstructQualifiedName(List *names,
123 char **nspname_p,
124 char **objname_p);
125extern Oid LookupNamespaceNoError(const char *nspname);
126extern Oid LookupExplicitNamespace(const char *nspname, bool missing_ok);
127extern Oid get_namespace_oid(const char *nspname, bool missing_ok);
128
129extern Oid LookupCreationNamespace(const char *nspname);
130extern void CheckSetNamespace(Oid oldNspOid, Oid nspOid);
131extern Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p);
132extern RangeVar *makeRangeVarFromNameList(List *names);
133extern char *NameListToString(List *names);
134extern char *NameListToQuotedString(List *names);
135
136extern bool isTempNamespace(Oid namespaceId);
137extern bool isTempToastNamespace(Oid namespaceId);
138extern bool isTempOrTempToastNamespace(Oid namespaceId);
139extern bool isAnyTempNamespace(Oid namespaceId);
140extern bool isOtherTempNamespace(Oid namespaceId);
141extern bool isTempNamespaceInUse(Oid namespaceId);
142extern int GetTempNamespaceBackendId(Oid namespaceId);
143extern Oid GetTempToastNamespace(void);
144extern void GetTempNamespaceState(Oid *tempNamespaceId,
145 Oid *tempToastNamespaceId);
146extern void SetTempNamespaceState(Oid tempNamespaceId,
147 Oid tempToastNamespaceId);
148extern void ResetTempTableNamespace(void);
149
150extern OverrideSearchPath *GetOverrideSearchPath(MemoryContext context);
151extern OverrideSearchPath *CopyOverrideSearchPath(OverrideSearchPath *path);
152extern bool OverrideSearchPathMatchesCurrent(OverrideSearchPath *path);
153extern void PushOverrideSearchPath(OverrideSearchPath *newpath);
154extern void PopOverrideSearchPath(void);
155
156extern Oid get_collation_oid(List *collname, bool missing_ok);
157extern Oid get_conversion_oid(List *conname, bool missing_ok);
158extern Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding);
159
160
161/* initialization & transaction cleanup code */
162extern void InitializeSearchPath(void);
163extern void AtEOXact_Namespace(bool isCommit, bool parallel);
164extern void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid,
165 SubTransactionId parentSubid);
166
167/* stuff for search_path GUC variable */
168extern char *namespace_search_path;
169
170extern List *fetch_search_path(bool includeImplicit);
171extern int fetch_search_path_array(Oid *sarray, int sarray_len);
172
173#endif /* NAMESPACE_H */
174