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-2025, 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#include "storage/procnumber.h"
20
21
22/*
23 * This structure holds a list of possible functions or operators
24 * found by namespace lookup. Each function/operator is identified
25 * by OID and by argument types; the list must be pruned by type
26 * resolution rules that are embodied in the parser, not here.
27 * See FuncnameGetCandidates's comments for more info.
28 */
29typedef struct _FuncCandidateList
30{
32 int pathpos; /* for internal use of namespace lookup */
33 Oid oid; /* the function or operator's OID */
34 int nominalnargs; /* either pronargs or length(proallargtypes) */
35 int nargs; /* number of arg types returned */
36 int nvargs; /* number of args to become variadic array */
37 int ndargs; /* number of defaulted args */
38 int *argnumbers; /* args' positional indexes, if named call */
39 Oid args[FLEXIBLE_ARRAY_MEMBER]; /* arg types */
41
42/*
43 * FuncnameGetCandidates also returns a bitmask containing these flags,
44 * which report on what it found or didn't find. They can help callers
45 * produce better error reports after a function lookup failure.
46 */
47#define FGC_SCHEMA_GIVEN 0x0001 /* Func name includes a schema */
48#define FGC_SCHEMA_EXISTS 0x0002 /* Found the explicitly-specified schema */
49#define FGC_NAME_EXISTS 0x0004 /* Found a routine by that name */
50#define FGC_NAME_VISIBLE 0x0008 /* Found a routine name/schema match */
51#define FGC_ARGCOUNT_MATCH 0x0010 /* Found a func with right # of args */
52/* These bits relate only to calls using named or mixed arguments: */
53#define FGC_ARGNAMES_MATCH 0x0020 /* Found a func matching all argnames */
54#define FGC_ARGNAMES_NONDUP 0x0040 /* argnames don't overlap positional args */
55#define FGC_ARGNAMES_ALL 0x0080 /* Found a func with no missing args */
56#define FGC_ARGNAMES_VALID 0x0100 /* Found a fully-valid use of argnames */
57/* These bits are actually filled by func_get_detail: */
58#define FGC_VARIADIC_FAIL 0x0200 /* Disallowed VARIADIC with named args */
59
60/*
61 * Result of checkTempNamespaceStatus
62 */
64{
65 TEMP_NAMESPACE_NOT_TEMP, /* nonexistent, or non-temp namespace */
66 TEMP_NAMESPACE_IDLE, /* exists, belongs to no active session */
67 TEMP_NAMESPACE_IN_USE, /* belongs to some active session */
69
70/*
71 * Structure for xxxSearchPathMatcher functions
72 *
73 * The generation counter is private to namespace.c and shouldn't be touched
74 * by other code. It can be initialized to zero if necessary (that means
75 * "not known equal to the current active path").
76 */
77typedef struct SearchPathMatcher
78{
79 List *schemas; /* OIDs of explicitly named schemas */
80 bool addCatalog; /* implicitly prepend pg_catalog? */
81 bool addTemp; /* implicitly prepend temp schema? */
82 uint64 generation; /* for quick detection of equality to active */
84
85/*
86 * Option flag bits for RangeVarGetRelidExtended().
87 */
88typedef enum RVROption
89{
90 RVR_MISSING_OK = 1 << 0, /* don't error if relation doesn't exist */
91 RVR_NOWAIT = 1 << 1, /* error if relation cannot be locked */
92 RVR_SKIP_LOCKED = 1 << 2, /* skip if relation cannot be locked */
94
95typedef void (*RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId,
96 Oid oldRelId, void *callback_arg);
97
98#define RangeVarGetRelid(relation, lockmode, missing_ok) \
99 RangeVarGetRelidExtended(relation, lockmode, \
100 (missing_ok) ? RVR_MISSING_OK : 0, NULL, NULL)
101
102extern Oid RangeVarGetRelidExtended(const RangeVar *relation,
103 LOCKMODE lockmode, uint32 flags,
105 void *callback_arg);
106extern Oid RangeVarGetCreationNamespace(const RangeVar *newRelation);
108 LOCKMODE lockmode,
109 Oid *existing_relation_id);
110extern void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid);
111extern Oid RelnameGetRelid(const char *relname);
112extern bool RelationIsVisible(Oid relid);
113
114extern Oid TypenameGetTypid(const char *typname);
115extern Oid TypenameGetTypidExtended(const char *typname, bool temp_ok);
116extern bool TypeIsVisible(Oid typid);
117
119 int nargs, List *argnames,
120 bool expand_variadic,
121 bool expand_defaults,
122 bool include_out_arguments,
123 bool missing_ok,
124 int *fgc_flags);
125extern bool FunctionIsVisible(Oid funcid);
126
127extern Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright);
128extern FuncCandidateList OpernameGetCandidates(List *names, char oprkind,
129 bool missing_schema_ok,
130 int *fgc_flags);
131extern bool OperatorIsVisible(Oid oprid);
132
133extern Oid OpclassnameGetOpcid(Oid amid, const char *opcname);
134extern bool OpclassIsVisible(Oid opcid);
135
136extern Oid OpfamilynameGetOpfid(Oid amid, const char *opfname);
137extern bool OpfamilyIsVisible(Oid opfid);
138
139extern Oid CollationGetCollid(const char *collname);
140extern bool CollationIsVisible(Oid collid);
141
142extern Oid ConversionGetConid(const char *conname);
143extern bool ConversionIsVisible(Oid conid);
144
145extern Oid get_statistics_object_oid(List *names, bool missing_ok);
146extern bool StatisticsObjIsVisible(Oid stxid);
147
148extern Oid get_ts_parser_oid(List *names, bool missing_ok);
149extern bool TSParserIsVisible(Oid prsId);
150
151extern Oid get_ts_dict_oid(List *names, bool missing_ok);
152extern bool TSDictionaryIsVisible(Oid dictId);
153
154extern Oid get_ts_template_oid(List *names, bool missing_ok);
155extern bool TSTemplateIsVisible(Oid tmplId);
156
157extern Oid get_ts_config_oid(List *names, bool missing_ok);
158extern bool TSConfigIsVisible(Oid cfgid);
159
160extern void DeconstructQualifiedName(const List *names,
161 char **nspname_p,
162 char **objname_p);
163extern Oid LookupNamespaceNoError(const char *nspname);
164extern Oid LookupExplicitNamespace(const char *nspname, bool missing_ok);
165extern Oid get_namespace_oid(const char *nspname, bool missing_ok);
166
167extern Oid LookupCreationNamespace(const char *nspname);
168extern void CheckSetNamespace(Oid oldNspOid, Oid nspOid);
169extern Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p);
170extern RangeVar *makeRangeVarFromNameList(const List *names);
171extern char *NameListToString(const List *names);
172extern char *NameListToQuotedString(const List *names);
173
174extern bool isTempNamespace(Oid namespaceId);
175extern bool isTempToastNamespace(Oid namespaceId);
176extern bool isTempOrTempToastNamespace(Oid namespaceId);
177extern bool isAnyTempNamespace(Oid namespaceId);
178extern bool isOtherTempNamespace(Oid namespaceId);
180extern ProcNumber GetTempNamespaceProcNumber(Oid namespaceId);
181extern Oid GetTempToastNamespace(void);
182extern void GetTempNamespaceState(Oid *tempNamespaceId,
183 Oid *tempToastNamespaceId);
184extern void SetTempNamespaceState(Oid tempNamespaceId,
185 Oid tempToastNamespaceId);
186extern void ResetTempTableNamespace(void);
187
191
192extern Oid get_collation_oid(List *collname, bool missing_ok);
193extern Oid get_conversion_oid(List *conname, bool missing_ok);
194extern Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding);
195
196
197/* initialization & transaction cleanup code */
198extern void InitializeSearchPath(void);
199extern void AtEOXact_Namespace(bool isCommit, bool parallel);
200extern void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid,
201 SubTransactionId parentSubid);
202
203/* stuff for search_path GUC variable */
205
206extern List *fetch_search_path(bool includeImplicit);
207extern int fetch_search_path_array(Oid *sarray, int sarray_len);
208
209#endif /* NAMESPACE_H */
#define PGDLLIMPORT
Definition: c.h:1324
uint32 SubTransactionId
Definition: c.h:666
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:475
int32_t int32
Definition: c.h:539
uint64_t uint64
Definition: c.h:544
uint32_t uint32
Definition: c.h:543
int nspid
Oid collid
int LOCKMODE
Definition: lockdefs.h:26
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
Definition: namespace.c:738
Oid OpclassnameGetOpcid(Oid amid, const char *opcname)
Definition: namespace.c:2188
bool isTempOrTempToastNamespace(Oid namespaceId)
Definition: namespace.c:3743
void ResetTempTableNamespace(void)
Definition: namespace.c:4714
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition: namespace.c:4150
Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright)
Definition: namespace.c:1832
PGDLLIMPORT char * namespace_search_path
Definition: namespace.c:210
char * NameListToString(const List *names)
Definition: namespace.c:3664
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
Definition: namespace.c:3455
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:3135
Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p)
Definition: namespace.c:3557
void(* RangeVarGetRelidCallback)(const RangeVar *relation, Oid relId, Oid oldRelId, void *callback_arg)
Definition: namespace.h:95
bool OpfamilyIsVisible(Oid opfid)
Definition: namespace.c:2323
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2474
bool TypeIsVisible(Oid typid)
Definition: namespace.c:1039
bool isOtherTempNamespace(Oid namespaceId)
Definition: namespace.c:3780
Oid CollationGetCollid(const char *collname)
Definition: namespace.c:2440
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3719
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3757
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2576
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2642
Oid LookupCreationNamespace(const char *nspname)
Definition: namespace.c:3498
void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid)
Definition: namespace.c:845
Oid get_collation_oid(List *collname, bool missing_ok)
Definition: namespace.c:4041
void DeconstructQualifiedName(const List *names, char **nspname_p, char **objname_p)
Definition: namespace.c:3371
List * fetch_search_path(bool includeImplicit)
Definition: namespace.c:4889
RVROption
Definition: namespace.h:89
@ RVR_SKIP_LOCKED
Definition: namespace.h:92
@ RVR_NOWAIT
Definition: namespace.h:91
@ RVR_MISSING_OK
Definition: namespace.h:90
FuncCandidateList OpernameGetCandidates(List *names, char oprkind, bool missing_schema_ok, int *fgc_flags)
Definition: namespace.c:1945
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3605
SearchPathMatcher * GetSearchPathMatcher(MemoryContext context)
Definition: namespace.c:3922
Oid TypenameGetTypidExtended(const char *typname, bool temp_ok)
Definition: namespace.c:1007
char * NameListToQuotedString(const List *names)
Definition: namespace.c:3698
Oid RangeVarGetCreationNamespace(const RangeVar *newRelation)
Definition: namespace.c:653
bool RelationIsVisible(Oid relid)
Definition: namespace.c:912
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:2221
Oid ConversionGetConid(const char *conname)
Definition: namespace.c:2544
void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid)
Definition: namespace.c:4628
TempNamespaceStatus checkTempNamespaceStatus(Oid namespaceId)
Definition: namespace.c:3799
void CheckSetNamespace(Oid oldNspOid, Oid nspOid)
Definition: namespace.c:3529
void GetTempNamespaceState(Oid *tempNamespaceId, Oid *tempToastNamespaceId)
Definition: namespace.c:3875
void InitializeSearchPath(void)
Definition: namespace.c:4806
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:2116
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2844
FuncCandidateList FuncnameGetCandidates(List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool include_out_arguments, bool missing_ok, int *fgc_flags)
Definition: namespace.c:1197
bool SearchPathMatchesCurrentEnvironment(SearchPathMatcher *path)
Definition: namespace.c:3981
TempNamespaceStatus
Definition: namespace.h:64
@ TEMP_NAMESPACE_IN_USE
Definition: namespace.h:67
@ TEMP_NAMESPACE_NOT_TEMP
Definition: namespace.h:65
@ TEMP_NAMESPACE_IDLE
Definition: namespace.h:66
Oid get_conversion_oid(List *conname, bool missing_ok)
Definition: namespace.c:4095
bool FunctionIsVisible(Oid funcid)
Definition: namespace.c:1741
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2931
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2786
SearchPathMatcher * CopySearchPathMatcher(SearchPathMatcher *path)
Definition: namespace.c:3959
void SetTempNamespaceState(Oid tempNamespaceId, Oid tempToastNamespaceId)
Definition: namespace.c:3891
Oid GetTempToastNamespace(void)
Definition: namespace.c:3861
Oid OpfamilynameGetOpfid(Oid amid, const char *opfname)
Definition: namespace.c:2290
struct _FuncCandidateList * FuncCandidateList
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3624
void AtEOXact_Namespace(bool isCommit, bool parallel)
Definition: namespace.c:4582
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:3222
Oid LookupNamespaceNoError(const char *nspname)
Definition: namespace.c:3425
ProcNumber GetTempNamespaceProcNumber(Oid namespaceId)
Definition: namespace.c:3836
Oid TypenameGetTypid(const char *typname)
Definition: namespace.c:994
int fetch_search_path_array(Oid *sarray, int sarray_len)
Definition: namespace.c:4929
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:440
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:3280
bool StatisticsObjIsVisible(Oid stxid)
Definition: namespace.c:2699
Oid RelnameGetRelid(const char *relname)
Definition: namespace.c:884
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2989
struct SearchPathMatcher SearchPathMatcher
bool isTempToastNamespace(Oid namespaceId)
Definition: namespace.c:3731
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:3077
Oid oprid(Operator op)
Definition: parse_oper.c:239
NameData relname
Definition: pg_class.h:38
NameData typname
Definition: pg_type.h:41
unsigned int Oid
Definition: postgres_ext.h:32
int ProcNumber
Definition: procnumber.h:24
Definition: pg_list.h:54
uint64 generation
Definition: namespace.h:82
struct _FuncCandidateList * next
Definition: namespace.h:31
Oid args[FLEXIBLE_ARRAY_MEMBER]
Definition: namespace.h:39
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46