1 /*------------------------------------------------------------------------- 2 * 3 * namespace.h 4 * prototypes for functions in backend/catalog/namespace.c 5 * 6 * 7 * Portions Copyright (c) 1996-2021, 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 { 30 struct _FuncCandidateList *next; 31 int pathpos; /* for internal use of namespace lookup */ 32 Oid oid; /* the function or operator's OID */ 33 int nominalnargs; /* either pronargs or length(proallargtypes) */ 34 int nargs; /* number of arg types returned */ 35 int nvargs; /* number of args to become variadic array */ 36 int ndargs; /* number of defaulted args */ 37 int *argnumbers; /* args' positional indexes, if named call */ 38 Oid args[FLEXIBLE_ARRAY_MEMBER]; /* arg types */ 39 } *FuncCandidateList; 40 41 /* 42 * Result of checkTempNamespaceStatus 43 */ 44 typedef enum TempNamespaceStatus 45 { 46 TEMP_NAMESPACE_NOT_TEMP, /* nonexistent, or non-temp namespace */ 47 TEMP_NAMESPACE_IDLE, /* exists, belongs to no active session */ 48 TEMP_NAMESPACE_IN_USE /* belongs to some active session */ 49 } TempNamespaceStatus; 50 51 /* 52 * Structure for xxxOverrideSearchPath functions 53 * 54 * The generation counter is private to namespace.c and shouldn't be touched 55 * by other code. It can be initialized to zero if necessary (that means 56 * "not known equal to the current active path"). 57 */ 58 typedef struct OverrideSearchPath 59 { 60 List *schemas; /* OIDs of explicitly named schemas */ 61 bool addCatalog; /* implicitly prepend pg_catalog? */ 62 bool addTemp; /* implicitly prepend temp schema? */ 63 uint64 generation; /* for quick detection of equality to active */ 64 } OverrideSearchPath; 65 66 /* 67 * Option flag bits for RangeVarGetRelidExtended(). 68 */ 69 typedef enum RVROption 70 { 71 RVR_MISSING_OK = 1 << 0, /* don't error if relation doesn't exist */ 72 RVR_NOWAIT = 1 << 1, /* error if relation cannot be locked */ 73 RVR_SKIP_LOCKED = 1 << 2 /* skip if relation cannot be locked */ 74 } RVROption; 75 76 typedef void (*RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId, 77 Oid oldRelId, void *callback_arg); 78 79 #define RangeVarGetRelid(relation, lockmode, missing_ok) \ 80 RangeVarGetRelidExtended(relation, lockmode, \ 81 (missing_ok) ? RVR_MISSING_OK : 0, NULL, NULL) 82 83 extern Oid RangeVarGetRelidExtended(const RangeVar *relation, 84 LOCKMODE lockmode, uint32 flags, 85 RangeVarGetRelidCallback callback, 86 void *callback_arg); 87 extern Oid RangeVarGetCreationNamespace(const RangeVar *newRelation); 88 extern Oid RangeVarGetAndCheckCreationNamespace(RangeVar *newRelation, 89 LOCKMODE lockmode, 90 Oid *existing_relation_id); 91 extern void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid); 92 extern Oid RelnameGetRelid(const char *relname); 93 extern bool RelationIsVisible(Oid relid); 94 95 extern Oid TypenameGetTypid(const char *typname); 96 extern Oid TypenameGetTypidExtended(const char *typname, bool temp_ok); 97 extern bool TypeIsVisible(Oid typid); 98 99 extern FuncCandidateList FuncnameGetCandidates(List *names, 100 int nargs, List *argnames, 101 bool expand_variadic, 102 bool expand_defaults, 103 bool include_out_arguments, 104 bool missing_ok); 105 extern bool FunctionIsVisible(Oid funcid); 106 107 extern Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright); 108 extern FuncCandidateList OpernameGetCandidates(List *names, char oprkind, 109 bool missing_schema_ok); 110 extern bool OperatorIsVisible(Oid oprid); 111 112 extern Oid OpclassnameGetOpcid(Oid amid, const char *opcname); 113 extern bool OpclassIsVisible(Oid opcid); 114 115 extern Oid OpfamilynameGetOpfid(Oid amid, const char *opfname); 116 extern bool OpfamilyIsVisible(Oid opfid); 117 118 extern Oid CollationGetCollid(const char *collname); 119 extern bool CollationIsVisible(Oid collid); 120 121 extern Oid ConversionGetConid(const char *conname); 122 extern bool ConversionIsVisible(Oid conid); 123 124 extern Oid get_statistics_object_oid(List *names, bool missing_ok); 125 extern bool StatisticsObjIsVisible(Oid relid); 126 127 extern Oid get_ts_parser_oid(List *names, bool missing_ok); 128 extern bool TSParserIsVisible(Oid prsId); 129 130 extern Oid get_ts_dict_oid(List *names, bool missing_ok); 131 extern bool TSDictionaryIsVisible(Oid dictId); 132 133 extern Oid get_ts_template_oid(List *names, bool missing_ok); 134 extern bool TSTemplateIsVisible(Oid tmplId); 135 136 extern Oid get_ts_config_oid(List *names, bool missing_ok); 137 extern bool TSConfigIsVisible(Oid cfgid); 138 139 extern void DeconstructQualifiedName(List *names, 140 char **nspname_p, 141 char **objname_p); 142 extern Oid LookupNamespaceNoError(const char *nspname); 143 extern Oid LookupExplicitNamespace(const char *nspname, bool missing_ok); 144 extern Oid get_namespace_oid(const char *nspname, bool missing_ok); 145 146 extern Oid LookupCreationNamespace(const char *nspname); 147 extern void CheckSetNamespace(Oid oldNspOid, Oid nspOid); 148 extern Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p); 149 extern RangeVar *makeRangeVarFromNameList(List *names); 150 extern char *NameListToString(List *names); 151 extern char *NameListToQuotedString(List *names); 152 153 extern bool isTempNamespace(Oid namespaceId); 154 extern bool isTempToastNamespace(Oid namespaceId); 155 extern bool isTempOrTempToastNamespace(Oid namespaceId); 156 extern bool isAnyTempNamespace(Oid namespaceId); 157 extern bool isOtherTempNamespace(Oid namespaceId); 158 extern TempNamespaceStatus checkTempNamespaceStatus(Oid namespaceId); 159 extern int GetTempNamespaceBackendId(Oid namespaceId); 160 extern Oid GetTempToastNamespace(void); 161 extern void GetTempNamespaceState(Oid *tempNamespaceId, 162 Oid *tempToastNamespaceId); 163 extern void SetTempNamespaceState(Oid tempNamespaceId, 164 Oid tempToastNamespaceId); 165 extern void ResetTempTableNamespace(void); 166 167 extern OverrideSearchPath *GetOverrideSearchPath(MemoryContext context); 168 extern OverrideSearchPath *CopyOverrideSearchPath(OverrideSearchPath *path); 169 extern bool OverrideSearchPathMatchesCurrent(OverrideSearchPath *path); 170 extern void PushOverrideSearchPath(OverrideSearchPath *newpath); 171 extern void PopOverrideSearchPath(void); 172 173 extern Oid get_collation_oid(List *collname, bool missing_ok); 174 extern Oid get_conversion_oid(List *conname, bool missing_ok); 175 extern Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding); 176 177 178 /* initialization & transaction cleanup code */ 179 extern void InitializeSearchPath(void); 180 extern void AtEOXact_Namespace(bool isCommit, bool parallel); 181 extern void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid, 182 SubTransactionId parentSubid); 183 184 /* stuff for search_path GUC variable */ 185 extern char *namespace_search_path; 186 187 extern List *fetch_search_path(bool includeImplicit); 188 extern int fetch_search_path_array(Oid *sarray, int sarray_len); 189 190 #endif /* NAMESPACE_H */ 191