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