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 { 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 * 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 */ 48 } TempNamespaceStatus; 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 */ 63 } OverrideSearchPath; 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, 84 RangeVarGetRelidCallback callback, 85 void *callback_arg); 86 extern Oid RangeVarGetCreationNamespace(const RangeVar *newRelation); 87 extern Oid RangeVarGetAndCheckCreationNamespace(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 98 extern FuncCandidateList FuncnameGetCandidates(List *names, 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); 156 extern TempNamespaceStatus checkTempNamespaceStatus(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 165 extern OverrideSearchPath *GetOverrideSearchPath(MemoryContext context); 166 extern OverrideSearchPath *CopyOverrideSearchPath(OverrideSearchPath *path); 167 extern bool OverrideSearchPathMatchesCurrent(OverrideSearchPath *path); 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 */ 189