PostgreSQL Source Code git master
Loading...
Searching...
No Matches
namespace.h File Reference
#include "nodes/primnodes.h"
#include "storage/lock.h"
#include "storage/procnumber.h"
Include dependency graph for namespace.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _FuncCandidateList
 
struct  SearchPathMatcher
 

Macros

#define FGC_SCHEMA_GIVEN   0x0001 /* Func name includes a schema */
 
#define FGC_SCHEMA_EXISTS   0x0002 /* Found the explicitly-specified schema */
 
#define FGC_NAME_EXISTS   0x0004 /* Found a routine by that name */
 
#define FGC_NAME_VISIBLE   0x0008 /* Found a routine name/schema match */
 
#define FGC_ARGCOUNT_MATCH   0x0010 /* Found a func with right # of args */
 
#define FGC_ARGNAMES_MATCH   0x0020 /* Found a func matching all argnames */
 
#define FGC_ARGNAMES_NONDUP   0x0040 /* argnames don't overlap positional args */
 
#define FGC_ARGNAMES_ALL   0x0080 /* Found a func with no missing args */
 
#define FGC_ARGNAMES_VALID   0x0100 /* Found a fully-valid use of argnames */
 
#define FGC_VARIADIC_FAIL   0x0200 /* Disallowed VARIADIC with named args */
 
#define RangeVarGetRelid(relation, lockmode, missing_ok)
 

Typedefs

typedef struct _FuncCandidateListFuncCandidateList
 
typedef enum TempNamespaceStatus TempNamespaceStatus
 
typedef struct SearchPathMatcher SearchPathMatcher
 
typedef enum RVROption RVROption
 
typedef void(* RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId, Oid oldRelId, void *callback_arg)
 

Enumerations

enum  TempNamespaceStatus { TEMP_NAMESPACE_NOT_TEMP , TEMP_NAMESPACE_IDLE , TEMP_NAMESPACE_IN_USE }
 
enum  RVROption { RVR_MISSING_OK = 1 << 0 , RVR_NOWAIT = 1 << 1 , RVR_SKIP_LOCKED = 1 << 2 }
 

Functions

Oid RangeVarGetRelidExtended (const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
 
Oid RangeVarGetCreationNamespace (const RangeVar *newRelation)
 
Oid RangeVarGetAndCheckCreationNamespace (RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
 
void RangeVarAdjustRelationPersistence (RangeVar *newRelation, Oid nspid)
 
Oid RelnameGetRelid (const char *relname)
 
bool RelationIsVisible (Oid relid)
 
Oid TypenameGetTypid (const char *typname)
 
Oid TypenameGetTypidExtended (const char *typname, bool temp_ok)
 
bool TypeIsVisible (Oid typid)
 
FuncCandidateList FuncnameGetCandidates (List *names, int nargs, List *argnames, bool expand_variadic, bool expand_defaults, bool include_out_arguments, bool missing_ok, int *fgc_flags)
 
bool FunctionIsVisible (Oid funcid)
 
Oid OpernameGetOprid (List *names, Oid oprleft, Oid oprright)
 
FuncCandidateList OpernameGetCandidates (List *names, char oprkind, bool missing_schema_ok, int *fgc_flags)
 
bool OperatorIsVisible (Oid oprid)
 
Oid OpclassnameGetOpcid (Oid amid, const char *opcname)
 
bool OpclassIsVisible (Oid opcid)
 
Oid OpfamilynameGetOpfid (Oid amid, const char *opfname)
 
bool OpfamilyIsVisible (Oid opfid)
 
Oid CollationGetCollid (const char *collname)
 
bool CollationIsVisible (Oid collid)
 
Oid ConversionGetConid (const char *conname)
 
bool ConversionIsVisible (Oid conid)
 
Oid get_statistics_object_oid (List *names, bool missing_ok)
 
bool StatisticsObjIsVisible (Oid stxid)
 
Oid get_ts_parser_oid (List *names, bool missing_ok)
 
bool TSParserIsVisible (Oid prsId)
 
Oid get_ts_dict_oid (List *names, bool missing_ok)
 
bool TSDictionaryIsVisible (Oid dictId)
 
Oid get_ts_template_oid (List *names, bool missing_ok)
 
bool TSTemplateIsVisible (Oid tmplId)
 
Oid get_ts_config_oid (List *names, bool missing_ok)
 
bool TSConfigIsVisible (Oid cfgid)
 
void DeconstructQualifiedName (const List *names, char **nspname_p, char **objname_p)
 
Oid LookupNamespaceNoError (const char *nspname)
 
Oid LookupExplicitNamespace (const char *nspname, bool missing_ok)
 
Oid get_namespace_oid (const char *nspname, bool missing_ok)
 
Oid LookupCreationNamespace (const char *nspname)
 
void CheckSetNamespace (Oid oldNspOid, Oid nspOid)
 
Oid QualifiedNameGetCreationNamespace (const List *names, char **objname_p)
 
RangeVarmakeRangeVarFromNameList (const List *names)
 
charNameListToString (const List *names)
 
charNameListToQuotedString (const List *names)
 
bool isTempNamespace (Oid namespaceId)
 
bool isTempToastNamespace (Oid namespaceId)
 
bool isTempOrTempToastNamespace (Oid namespaceId)
 
bool isAnyTempNamespace (Oid namespaceId)
 
bool isOtherTempNamespace (Oid namespaceId)
 
TempNamespaceStatus checkTempNamespaceStatus (Oid namespaceId)
 
ProcNumber GetTempNamespaceProcNumber (Oid namespaceId)
 
Oid GetTempToastNamespace (void)
 
void GetTempNamespaceState (Oid *tempNamespaceId, Oid *tempToastNamespaceId)
 
void SetTempNamespaceState (Oid tempNamespaceId, Oid tempToastNamespaceId)
 
void ResetTempTableNamespace (void)
 
SearchPathMatcherGetSearchPathMatcher (MemoryContext context)
 
SearchPathMatcherCopySearchPathMatcher (SearchPathMatcher *path)
 
bool SearchPathMatchesCurrentEnvironment (SearchPathMatcher *path)
 
Oid get_collation_oid (List *collname, bool missing_ok)
 
Oid get_conversion_oid (List *conname, bool missing_ok)
 
Oid FindDefaultConversionProc (int32 for_encoding, int32 to_encoding)
 
void InitializeSearchPath (void)
 
void AtEOXact_Namespace (bool isCommit, bool parallel)
 
void AtEOSubXact_Namespace (bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid)
 
Listfetch_search_path (bool includeImplicit)
 
int fetch_search_path_array (Oid *sarray, int sarray_len)
 

Variables

PGDLLIMPORT charnamespace_search_path
 

Macro Definition Documentation

◆ FGC_ARGCOUNT_MATCH

#define FGC_ARGCOUNT_MATCH   0x0010 /* Found a func with right # of args */

Definition at line 51 of file namespace.h.

◆ FGC_ARGNAMES_ALL

#define FGC_ARGNAMES_ALL   0x0080 /* Found a func with no missing args */

Definition at line 55 of file namespace.h.

◆ FGC_ARGNAMES_MATCH

#define FGC_ARGNAMES_MATCH   0x0020 /* Found a func matching all argnames */

Definition at line 53 of file namespace.h.

◆ FGC_ARGNAMES_NONDUP

#define FGC_ARGNAMES_NONDUP   0x0040 /* argnames don't overlap positional args */

Definition at line 54 of file namespace.h.

◆ FGC_ARGNAMES_VALID

#define FGC_ARGNAMES_VALID   0x0100 /* Found a fully-valid use of argnames */

Definition at line 56 of file namespace.h.

◆ FGC_NAME_EXISTS

#define FGC_NAME_EXISTS   0x0004 /* Found a routine by that name */

Definition at line 49 of file namespace.h.

◆ FGC_NAME_VISIBLE

#define FGC_NAME_VISIBLE   0x0008 /* Found a routine name/schema match */

Definition at line 50 of file namespace.h.

◆ FGC_SCHEMA_EXISTS

#define FGC_SCHEMA_EXISTS   0x0002 /* Found the explicitly-specified schema */

Definition at line 48 of file namespace.h.

◆ FGC_SCHEMA_GIVEN

#define FGC_SCHEMA_GIVEN   0x0001 /* Func name includes a schema */

Definition at line 47 of file namespace.h.

◆ FGC_VARIADIC_FAIL

#define FGC_VARIADIC_FAIL   0x0200 /* Disallowed VARIADIC with named args */

Definition at line 58 of file namespace.h.

◆ RangeVarGetRelid

#define RangeVarGetRelid (   relation,
  lockmode,
  missing_ok 
)
Value:
RangeVarGetRelidExtended(relation, lockmode, \
(missing_ok) ? RVR_MISSING_OK : 0, NULL, NULL)
@ RVR_MISSING_OK
Definition namespace.h:90
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition namespace.c:440
static int fb(int x)

Definition at line 98 of file namespace.h.

100 : 0, NULL, NULL)

Typedef Documentation

◆ FuncCandidateList

◆ RangeVarGetRelidCallback

typedef void(* RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId, Oid oldRelId, void *callback_arg)

Definition at line 95 of file namespace.h.

◆ RVROption

◆ SearchPathMatcher

◆ TempNamespaceStatus

Enumeration Type Documentation

◆ RVROption

Enumerator
RVR_MISSING_OK 
RVR_NOWAIT 
RVR_SKIP_LOCKED 

Definition at line 88 of file namespace.h.

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 */
93} RVROption;
RVROption
Definition namespace.h:89
@ RVR_SKIP_LOCKED
Definition namespace.h:92
@ RVR_NOWAIT
Definition namespace.h:91

◆ TempNamespaceStatus

Enumerator
TEMP_NAMESPACE_NOT_TEMP 
TEMP_NAMESPACE_IDLE 
TEMP_NAMESPACE_IN_USE 

Definition at line 63 of file namespace.h.

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 */
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

Function Documentation

◆ AtEOSubXact_Namespace()

void AtEOSubXact_Namespace ( bool  isCommit,
SubTransactionId  mySubid,
SubTransactionId  parentSubid 
)
extern

Definition at line 4628 of file namespace.c.

4630{
4631
4633 {
4634 if (isCommit)
4636 else
4637 {
4639 /* TEMP namespace creation failed, so reset state */
4642 baseSearchPathValid = false; /* need to rebuild list */
4643 searchPathCacheValid = false;
4644
4645 /*
4646 * Reset the temporary namespace flag in MyProc. We assume that
4647 * this operation is atomic.
4648 *
4649 * Because this subtransaction is aborting, the pg_namespace row
4650 * is not visible to anyone else anyway, but that doesn't matter:
4651 * it's not a problem if objects contained in this namespace are
4652 * removed concurrently.
4653 */
4655 }
4656 }
4657}
#define InvalidSubTransactionId
Definition c.h:672
static bool searchPathCacheValid
Definition namespace.c:163
static bool baseSearchPathValid
Definition namespace.c:157
static SubTransactionId myTempNamespaceSubID
Definition namespace.c:204
static Oid myTempToastNamespace
Definition namespace.c:202
static Oid myTempNamespace
Definition namespace.c:200
#define InvalidOid
PGPROC * MyProc
Definition proc.c:67
Oid tempNamespaceId
Definition proc.h:227

References baseSearchPathValid, fb(), InvalidOid, InvalidSubTransactionId, MyProc, myTempNamespace, myTempNamespaceSubID, myTempToastNamespace, searchPathCacheValid, and PGPROC::tempNamespaceId.

Referenced by AbortSubTransaction(), and CommitSubTransaction().

◆ AtEOXact_Namespace()

void AtEOXact_Namespace ( bool  isCommit,
bool  parallel 
)
extern

Definition at line 4582 of file namespace.c.

4583{
4584 /*
4585 * If we abort the transaction in which a temp namespace was selected,
4586 * we'll have to do any creation or cleanout work over again. So, just
4587 * forget the namespace entirely until next time. On the other hand, if
4588 * we commit then register an exit callback to clean out the temp tables
4589 * at backend shutdown. (We only want to register the callback once per
4590 * session, so this is a good place to do it.)
4591 */
4593 {
4594 if (isCommit)
4596 else
4597 {
4600 baseSearchPathValid = false; /* need to rebuild list */
4601 searchPathCacheValid = false;
4602
4603 /*
4604 * Reset the temporary namespace flag in MyProc. We assume that
4605 * this operation is atomic.
4606 *
4607 * Because this transaction is aborting, the pg_namespace row is
4608 * not visible to anyone else anyway, but that doesn't matter:
4609 * it's not a problem if objects contained in this namespace are
4610 * removed concurrently.
4611 */
4613 }
4615 }
4616
4617}
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:344
static void RemoveTempRelationsCallback(int code, Datum arg)
Definition namespace.c:4694

References baseSearchPathValid, before_shmem_exit(), fb(), InvalidOid, InvalidSubTransactionId, MyProc, myTempNamespace, myTempNamespaceSubID, myTempToastNamespace, RemoveTempRelationsCallback(), searchPathCacheValid, and PGPROC::tempNamespaceId.

Referenced by AbortTransaction(), CommitTransaction(), and PrepareTransaction().

◆ CheckSetNamespace()

void CheckSetNamespace ( Oid  oldNspOid,
Oid  nspOid 
)
extern

Definition at line 3529 of file namespace.c.

3530{
3531 /* disallow renaming into or out of temp schemas */
3533 ereport(ERROR,
3535 errmsg("cannot move objects into or out of temporary schemas")));
3536
3537 /* same for TOAST schema */
3539 ereport(ERROR,
3541 errmsg("cannot move objects into or out of TOAST schema")));
3542}
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
bool isAnyTempNamespace(Oid namespaceId)
Definition namespace.c:3757

References ereport, errcode(), errmsg(), ERROR, fb(), and isAnyTempNamespace().

Referenced by AlterObjectNamespace_internal(), AlterTableNamespace(), and AlterTypeNamespaceInternal().

◆ checkTempNamespaceStatus()

TempNamespaceStatus checkTempNamespaceStatus ( Oid  namespaceId)
extern

Definition at line 3799 of file namespace.c.

3800{
3801 PGPROC *proc;
3802 ProcNumber procNumber;
3803
3805
3807
3808 /* No such namespace, or its name shows it's not temp? */
3809 if (procNumber == INVALID_PROC_NUMBER)
3811
3812 /* Is the backend alive? */
3813 proc = ProcNumberGetProc(procNumber);
3814 if (proc == NULL)
3815 return TEMP_NAMESPACE_IDLE;
3816
3817 /* Is the backend connected to the same database we are looking at? */
3818 if (proc->databaseId != MyDatabaseId)
3819 return TEMP_NAMESPACE_IDLE;
3820
3821 /* Does the backend own the temporary namespace? */
3822 if (proc->tempNamespaceId != namespaceId)
3823 return TEMP_NAMESPACE_IDLE;
3824
3825 /* Yup, so namespace is busy */
3826 return TEMP_NAMESPACE_IN_USE;
3827}
#define Assert(condition)
Definition c.h:873
#define OidIsValid(objectId)
Definition c.h:788
Oid MyDatabaseId
Definition globals.c:94
ProcNumber GetTempNamespaceProcNumber(Oid namespaceId)
Definition namespace.c:3836
PGPROC * ProcNumberGetProc(ProcNumber procNumber)
Definition procarray.c:3101
#define INVALID_PROC_NUMBER
Definition procnumber.h:26
int ProcNumber
Definition procnumber.h:24
Definition proc.h:179
Oid databaseId
Definition proc.h:224

References Assert, PGPROC::databaseId, fb(), GetTempNamespaceProcNumber(), INVALID_PROC_NUMBER, MyDatabaseId, OidIsValid, ProcNumberGetProc(), TEMP_NAMESPACE_IDLE, TEMP_NAMESPACE_IN_USE, TEMP_NAMESPACE_NOT_TEMP, and PGPROC::tempNamespaceId.

Referenced by do_autovacuum().

◆ CollationGetCollid()

Oid CollationGetCollid ( const char collname)
extern

Definition at line 2440 of file namespace.c.

2441{
2443 ListCell *l;
2444
2446
2447 foreach(l, activeSearchPath)
2448 {
2450 Oid collid;
2451
2453 continue; /* do not look in temp namespace */
2454
2456 if (OidIsValid(collid))
2457 return collid;
2458 }
2459
2460 /* Not found in path */
2461 return InvalidOid;
2462}
int32_t int32
Definition c.h:542
Oid collid
int GetDatabaseEncoding(void)
Definition mbutils.c:1264
static Oid lookup_collation(const char *collname, Oid collnamespace, int32 encoding)
Definition namespace.c:2389
static List * activeSearchPath
Definition namespace.c:135
static void recomputeNamespacePath(void)
Definition namespace.c:4369
#define lfirst_oid(lc)
Definition pg_list.h:174
unsigned int Oid

References activeSearchPath, collid, fb(), GetDatabaseEncoding(), InvalidOid, lfirst_oid, lookup_collation(), myTempNamespace, OidIsValid, and recomputeNamespacePath().

Referenced by CollationIsVisibleExt().

◆ CollationIsVisible()

bool CollationIsVisible ( Oid  collid)
extern

Definition at line 2474 of file namespace.c.

2475{
2477}
static bool CollationIsVisibleExt(Oid collid, bool *is_missing)
Definition namespace.c:2486

References CollationIsVisibleExt(), collid, and fb().

Referenced by generate_collation_name(), getObjectDescription(), and regcollationout().

◆ ConversionGetConid()

Oid ConversionGetConid ( const char conname)
extern

Definition at line 2544 of file namespace.c.

2545{
2546 Oid conid;
2547 ListCell *l;
2548
2550
2551 foreach(l, activeSearchPath)
2552 {
2554
2556 continue; /* do not look in temp namespace */
2557
2559 PointerGetDatum(conname),
2561 if (OidIsValid(conid))
2562 return conid;
2563 }
2564
2565 /* Not found in path */
2566 return InvalidOid;
2567}
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition syscache.h:111

References activeSearchPath, fb(), GetSysCacheOid2, InvalidOid, lfirst_oid, myTempNamespace, ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), and recomputeNamespacePath().

Referenced by ConversionIsVisibleExt().

◆ ConversionIsVisible()

bool ConversionIsVisible ( Oid  conid)
extern

Definition at line 2576 of file namespace.c.

2577{
2578 return ConversionIsVisibleExt(conid, NULL);
2579}
static bool ConversionIsVisibleExt(Oid conid, bool *is_missing)
Definition namespace.c:2588

References ConversionIsVisibleExt(), and fb().

Referenced by getObjectDescription().

◆ CopySearchPathMatcher()

SearchPathMatcher * CopySearchPathMatcher ( SearchPathMatcher path)
extern

Definition at line 3959 of file namespace.c.

3960{
3961 SearchPathMatcher *result;
3962
3964 result->schemas = list_copy(path->schemas);
3965 result->addCatalog = path->addCatalog;
3966 result->addTemp = path->addTemp;
3967 result->generation = path->generation;
3968
3969 return result;
3970}
#define palloc_object(type)
Definition fe_memutils.h:74
List * list_copy(const List *oldlist)
Definition list.c:1573

References SearchPathMatcher::addCatalog, SearchPathMatcher::addTemp, SearchPathMatcher::generation, list_copy(), palloc_object, and SearchPathMatcher::schemas.

Referenced by CopyCachedPlan().

◆ DeconstructQualifiedName()

void DeconstructQualifiedName ( const List names,
char **  nspname_p,
char **  objname_p 
)
extern

Definition at line 3371 of file namespace.c.

3374{
3375 char *catalogname;
3376 char *schemaname = NULL;
3377 char *objname = NULL;
3378
3379 switch (list_length(names))
3380 {
3381 case 1:
3382 objname = strVal(linitial(names));
3383 break;
3384 case 2:
3385 schemaname = strVal(linitial(names));
3386 objname = strVal(lsecond(names));
3387 break;
3388 case 3:
3389 catalogname = strVal(linitial(names));
3390 schemaname = strVal(lsecond(names));
3391 objname = strVal(lthird(names));
3392
3393 /*
3394 * We check the catalog name and then ignore it.
3395 */
3396 if (strcmp(catalogname, get_database_name(MyDatabaseId)) != 0)
3397 ereport(ERROR,
3399 errmsg("cross-database references are not implemented: %s",
3400 NameListToString(names))));
3401 break;
3402 default:
3403 ereport(ERROR,
3405 errmsg("improper qualified name (too many dotted names): %s",
3406 NameListToString(names))));
3407 break;
3408 }
3409
3410 *nspname_p = schemaname;
3411 *objname_p = objname;
3412}
char * get_database_name(Oid dbid)
Definition lsyscache.c:1242
char * NameListToString(const List *names)
Definition namespace.c:3664
static int list_length(const List *l)
Definition pg_list.h:152
#define lthird(l)
Definition pg_list.h:188
#define linitial(l)
Definition pg_list.h:178
#define lsecond(l)
Definition pg_list.h:183
#define strVal(v)
Definition value.h:82

References ereport, errcode(), errmsg(), ERROR, fb(), get_database_name(), linitial, list_length(), lsecond, lthird, MyDatabaseId, NameListToString(), and strVal.

Referenced by AlterStatistics(), FuncnameGetCandidates(), get_collation_oid(), get_conversion_oid(), get_statistics_object_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), LookupTypeNameExtended(), make_oper_cache_key(), OpClassCacheLookup(), OpernameGetCandidates(), OpernameGetOprid(), OpFamilyCacheLookup(), QualifiedNameGetCreationNamespace(), and ResolveOpClass().

◆ fetch_search_path()

List * fetch_search_path ( bool  includeImplicit)
extern

Definition at line 4889 of file namespace.c.

4890{
4891 List *result;
4892
4894
4895 /*
4896 * If the temp namespace should be first, force it to exist. This is so
4897 * that callers can trust the result to reflect the actual default
4898 * creation namespace. It's a bit bogus to do this here, since
4899 * current_schema() is supposedly a stable function without side-effects,
4900 * but the alternatives seem worse.
4901 */
4903 {
4906 }
4907
4908 result = list_copy(activeSearchPath);
4909 if (!includeImplicit)
4910 {
4911 while (result && linitial_oid(result) != activeCreationNamespace)
4912 result = list_delete_first(result);
4913 }
4914
4915 return result;
4916}
List * list_delete_first(List *list)
Definition list.c:943
static Oid activeCreationNamespace
Definition namespace.c:138
static bool activeTempCreationPending
Definition namespace.c:141
static void AccessTempTableNamespace(bool force)
Definition namespace.c:4432
#define linitial_oid(l)
Definition pg_list.h:180
Definition pg_list.h:54

References AccessTempTableNamespace(), activeCreationNamespace, activeSearchPath, activeTempCreationPending, fb(), linitial_oid, list_copy(), list_delete_first(), and recomputeNamespacePath().

Referenced by AfterTriggerSetState(), CreateExtensionInternal(), current_schema(), current_schemas(), and ObjectsInPublicationToOids().

◆ fetch_search_path_array()

int fetch_search_path_array ( Oid sarray,
int  sarray_len 
)
extern

Definition at line 4929 of file namespace.c.

4930{
4931 int count = 0;
4932 ListCell *l;
4933
4935
4936 foreach(l, activeSearchPath)
4937 {
4939
4941 continue; /* do not include temp namespace */
4942
4943 if (count < sarray_len)
4944 sarray[count] = namespaceId;
4945 count++;
4946 }
4947
4948 return count;
4949}

References activeSearchPath, fb(), lfirst_oid, myTempNamespace, and recomputeNamespacePath().

Referenced by make_oper_cache_key().

◆ FindDefaultConversionProc()

Oid FindDefaultConversionProc ( int32  for_encoding,
int32  to_encoding 
)
extern

Definition at line 4150 of file namespace.c.

4151{
4152 Oid proc;
4153 ListCell *l;
4154
4156
4157 foreach(l, activeSearchPath)
4158 {
4160
4162 continue; /* do not look in temp namespace */
4163
4165 if (OidIsValid(proc))
4166 return proc;
4167 }
4168
4169 /* Not found in path */
4170 return InvalidOid;
4171}
Oid FindDefaultConversion(Oid name_space, int32 for_encoding, int32 to_encoding)

References activeSearchPath, fb(), FindDefaultConversion(), InvalidOid, lfirst_oid, myTempNamespace, OidIsValid, and recomputeNamespacePath().

Referenced by BeginCopyFrom(), InitializeClientEncoding(), pg_do_encoding_conversion(), PrepareClientEncoding(), and test_enc_conversion().

◆ FuncnameGetCandidates()

FuncCandidateList FuncnameGetCandidates ( List names,
int  nargs,
List argnames,
bool  expand_variadic,
bool  expand_defaults,
bool  include_out_arguments,
bool  missing_ok,
int fgc_flags 
)
extern

Definition at line 1197 of file namespace.c.

1201{
1203 bool any_special = false;
1204 char *schemaname;
1205 char *funcname;
1208 int i;
1209
1210 /* check for caller error */
1211 Assert(nargs >= 0 || !(expand_variadic | expand_defaults));
1212
1213 /* initialize output fgc_flags to empty */
1214 *fgc_flags = 0;
1215
1216 /* deconstruct the name list */
1217 DeconstructQualifiedName(names, &schemaname, &funcname);
1218
1219 if (schemaname)
1220 {
1221 /* use exact schema given */
1222 *fgc_flags |= FGC_SCHEMA_GIVEN; /* report that a schema is given */
1223 namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
1224 if (!OidIsValid(namespaceId))
1225 return NULL;
1226 *fgc_flags |= FGC_SCHEMA_EXISTS; /* report that the schema exists */
1227 }
1228 else
1229 {
1230 /* flag to indicate we need namespace search */
1233 }
1234
1235 /* Search syscache by name only */
1237
1238 for (i = 0; i < catlist->n_members; i++)
1239 {
1240 HeapTuple proctup = &catlist->members[i]->tuple;
1242 Oid *proargtypes = procform->proargtypes.values;
1243 int pronargs = procform->pronargs;
1244 int effective_nargs;
1245 int pathpos = 0;
1246 bool variadic;
1247 bool use_defaults;
1249 int *argnumbers = NULL;
1251
1252 *fgc_flags |= FGC_NAME_EXISTS; /* the name is present in pg_proc */
1253
1255 {
1256 /* Consider only procs in specified namespace */
1257 if (procform->pronamespace != namespaceId)
1258 continue;
1259 }
1260 else
1261 {
1262 /*
1263 * Consider only procs that are in the search path and are not in
1264 * the temp namespace.
1265 */
1266 ListCell *nsp;
1267
1268 foreach(nsp, activeSearchPath)
1269 {
1270 if (procform->pronamespace == lfirst_oid(nsp) &&
1271 procform->pronamespace != myTempNamespace)
1272 break;
1273 pathpos++;
1274 }
1275 if (nsp == NULL)
1276 continue; /* proc is not in search path */
1277 }
1278
1279 *fgc_flags |= FGC_NAME_VISIBLE; /* routine is in the right schema */
1280
1281 /*
1282 * If we are asked to match to OUT arguments, then use the
1283 * proallargtypes array (which includes those); otherwise use
1284 * proargtypes (which doesn't). Of course, if proallargtypes is null,
1285 * we always use proargtypes.
1286 */
1288 {
1290 bool isNull;
1291
1294 &isNull);
1295 if (!isNull)
1296 {
1298
1299 pronargs = ARR_DIMS(arr)[0];
1300 if (ARR_NDIM(arr) != 1 ||
1301 pronargs < 0 ||
1302 ARR_HASNULL(arr) ||
1303 ARR_ELEMTYPE(arr) != OIDOID)
1304 elog(ERROR, "proallargtypes is not a 1-D Oid array or it contains nulls");
1305 Assert(pronargs >= procform->pronargs);
1306 proargtypes = (Oid *) ARR_DATA_PTR(arr);
1307 }
1308 }
1309
1310 if (argnames != NIL)
1311 {
1312 /*
1313 * Call uses named or mixed notation
1314 *
1315 * Check argument count.
1316 */
1317 Assert(nargs >= 0); /* -1 not supported with argnames */
1318
1319 if (pronargs > nargs && expand_defaults)
1320 {
1321 /* Ignore if not enough default expressions */
1322 if (nargs + procform->pronargdefaults < pronargs)
1323 continue;
1324 use_defaults = true;
1325 }
1326 else
1327 use_defaults = false;
1328
1329 /* Ignore if it doesn't match requested argument count */
1330 if (pronargs != nargs && !use_defaults)
1331 continue;
1332
1333 /* We found a routine with a suitable number of arguments */
1335
1336 /* Check for argument name match, generate positional mapping */
1337 if (!MatchNamedCall(proctup, nargs, argnames,
1339 &argnumbers, fgc_flags))
1340 continue;
1341
1342 /*
1343 * Named or mixed notation can match a variadic function only if
1344 * expand_variadic is off; otherwise there is no way to match the
1345 * presumed-nameless parameters expanded from the variadic array.
1346 * However, we postpone the check until here because we want to
1347 * perform argument name matching anyway (using the variadic array
1348 * argument's name). This allows us to give an on-point error
1349 * message if the user forgets to say VARIADIC in what would have
1350 * been a valid call with it.
1351 */
1352 if (OidIsValid(procform->provariadic) && expand_variadic)
1353 continue;
1355 variadic = false;
1356
1357 /* We found a fully-valid call using argument names */
1359
1360 /* Named argument matching is always "special" */
1361 any_special = true;
1362 }
1363 else
1364 {
1365 /*
1366 * Call uses positional notation
1367 *
1368 * Check if function is variadic, and get variadic element type if
1369 * so. If expand_variadic is false, we should just ignore
1370 * variadic-ness.
1371 */
1372 if (pronargs <= nargs && expand_variadic)
1373 {
1374 va_elem_type = procform->provariadic;
1377 }
1378 else
1379 {
1381 variadic = false;
1382 }
1383
1384 /*
1385 * Check if function can match by using parameter defaults.
1386 */
1387 if (pronargs > nargs && expand_defaults)
1388 {
1389 /* Ignore if not enough default expressions */
1390 if (nargs + procform->pronargdefaults < pronargs)
1391 continue;
1392 use_defaults = true;
1393 any_special = true;
1394 }
1395 else
1396 use_defaults = false;
1397
1398 /* Ignore if it doesn't match requested argument count */
1399 if (nargs >= 0 && pronargs != nargs && !variadic && !use_defaults)
1400 continue;
1401
1402 /* We found a routine with a suitable number of arguments */
1404 }
1405
1406 /*
1407 * We must compute the effective argument list so that we can easily
1408 * compare it to earlier results. We waste a palloc cycle if it gets
1409 * masked by an earlier result, but really that's a pretty infrequent
1410 * case so it's not worth worrying about.
1411 */
1412 effective_nargs = Max(pronargs, nargs);
1414 palloc(offsetof(struct _FuncCandidateList, args) +
1415 effective_nargs * sizeof(Oid));
1416 newResult->pathpos = pathpos;
1417 newResult->oid = procform->oid;
1418 newResult->nominalnargs = pronargs;
1419 newResult->nargs = effective_nargs;
1420 newResult->argnumbers = argnumbers;
1421 if (argnumbers)
1422 {
1423 /* Re-order the argument types into call's logical order */
1424 for (int j = 0; j < pronargs; j++)
1425 newResult->args[j] = proargtypes[argnumbers[j]];
1426 }
1427 else
1428 {
1429 /* Simple positional case, just copy proargtypes as-is */
1430 memcpy(newResult->args, proargtypes, pronargs * sizeof(Oid));
1431 }
1432 if (variadic)
1433 {
1434 newResult->nvargs = effective_nargs - pronargs + 1;
1435 /* Expand variadic argument into N copies of element type */
1436 for (int j = pronargs - 1; j < effective_nargs; j++)
1437 newResult->args[j] = va_elem_type;
1438 }
1439 else
1440 newResult->nvargs = 0;
1441 newResult->ndargs = use_defaults ? pronargs - nargs : 0;
1442
1443 /*
1444 * Does it have the same arguments as something we already accepted?
1445 * If so, decide what to do to avoid returning duplicate argument
1446 * lists. We can skip this check for the single-namespace case if no
1447 * special (named, variadic or defaults) match has been made, since
1448 * then the unique index on pg_proc guarantees all the matches have
1449 * different argument lists.
1450 */
1451 if (resultList != NULL &&
1453 {
1454 /*
1455 * If we have an ordered list from SearchSysCacheList (the normal
1456 * case), then any conflicting proc must immediately adjoin this
1457 * one in the list, so we only need to look at the newest result
1458 * item. If we have an unordered list, we have to scan the whole
1459 * result list. Also, if either the current candidate or any
1460 * previous candidate is a special match, we can't assume that
1461 * conflicts are adjacent.
1462 *
1463 * We ignore defaulted arguments in deciding what is a match.
1464 */
1466
1467 if (catlist->ordered && !any_special)
1468 {
1469 /* ndargs must be 0 if !any_special */
1470 if (effective_nargs == resultList->nargs &&
1471 memcmp(newResult->args,
1472 resultList->args,
1473 effective_nargs * sizeof(Oid)) == 0)
1475 else
1476 prevResult = NULL;
1477 }
1478 else
1479 {
1480 int cmp_nargs = newResult->nargs - newResult->ndargs;
1481
1482 for (prevResult = resultList;
1483 prevResult;
1484 prevResult = prevResult->next)
1485 {
1486 if (cmp_nargs == prevResult->nargs - prevResult->ndargs &&
1487 memcmp(newResult->args,
1488 prevResult->args,
1489 cmp_nargs * sizeof(Oid)) == 0)
1490 break;
1491 }
1492 }
1493
1494 if (prevResult)
1495 {
1496 /*
1497 * We have a match with a previous result. Decide which one
1498 * to keep, or mark it ambiguous if we can't decide. The
1499 * logic here is preference > 0 means prefer the old result,
1500 * preference < 0 means prefer the new, preference = 0 means
1501 * ambiguous.
1502 */
1503 int preference;
1504
1505 if (pathpos != prevResult->pathpos)
1506 {
1507 /*
1508 * Prefer the one that's earlier in the search path.
1509 */
1510 preference = pathpos - prevResult->pathpos;
1511 }
1512 else if (variadic && prevResult->nvargs == 0)
1513 {
1514 /*
1515 * With variadic functions we could have, for example,
1516 * both foo(numeric) and foo(variadic numeric[]) in the
1517 * same namespace; if so we prefer the non-variadic match
1518 * on efficiency grounds.
1519 */
1520 preference = 1;
1521 }
1522 else if (!variadic && prevResult->nvargs > 0)
1523 {
1524 preference = -1;
1525 }
1526 else
1527 {
1528 /*----------
1529 * We can't decide. This can happen with, for example,
1530 * both foo(numeric, variadic numeric[]) and
1531 * foo(variadic numeric[]) in the same namespace, or
1532 * both foo(int) and foo (int, int default something)
1533 * in the same namespace, or both foo(a int, b text)
1534 * and foo(b text, a int) in the same namespace.
1535 *----------
1536 */
1537 preference = 0;
1538 }
1539
1540 if (preference > 0)
1541 {
1542 /* keep previous result */
1544 continue;
1545 }
1546 else if (preference < 0)
1547 {
1548 /* remove previous result from the list */
1549 if (prevResult == resultList)
1550 resultList = prevResult->next;
1551 else
1552 {
1554
1558 {
1559 if (prevResult == prevPrevResult->next)
1560 {
1562 break;
1563 }
1564 }
1565 Assert(prevPrevResult); /* assert we found it */
1566 }
1568 /* fall through to add newResult to list */
1569 }
1570 else
1571 {
1572 /* mark old result as ambiguous, discard new */
1573 prevResult->oid = InvalidOid;
1575 continue;
1576 }
1577 }
1578 }
1579
1580 /*
1581 * Okay to add it to result list
1582 */
1583 newResult->next = resultList;
1585 }
1586
1588
1589 return resultList;
1590}
#define ARR_NDIM(a)
Definition array.h:290
#define ARR_DATA_PTR(a)
Definition array.h:322
#define DatumGetArrayTypeP(X)
Definition array.h:261
#define ARR_ELEMTYPE(a)
Definition array.h:292
#define ARR_DIMS(a)
Definition array.h:294
#define ARR_HASNULL(a)
Definition array.h:291
#define Max(x, y)
Definition c.h:991
#define elog(elevel,...)
Definition elog.h:226
static void * GETSTRUCT(const HeapTupleData *tuple)
#define funcname
int j
Definition isn.c:78
int i
Definition isn.c:77
void pfree(void *pointer)
Definition mcxt.c:1616
void * palloc(Size size)
Definition mcxt.c:1387
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
Definition namespace.c:3455
void DeconstructQualifiedName(const List *names, char **nspname_p, char **objname_p)
Definition namespace.c:3371
static bool MatchNamedCall(HeapTuple proctup, int nargs, List *argnames, bool include_out_arguments, int pronargs, int **argnumbers, int *fgc_flags)
Definition namespace.c:1616
#define FGC_NAME_EXISTS
Definition namespace.h:49
#define FGC_ARGNAMES_VALID
Definition namespace.h:56
#define FGC_SCHEMA_GIVEN
Definition namespace.h:47
#define FGC_ARGCOUNT_MATCH
Definition namespace.h:51
struct _FuncCandidateList * FuncCandidateList
#define FGC_NAME_VISIBLE
Definition namespace.h:50
#define FGC_SCHEMA_EXISTS
Definition namespace.h:48
#define NIL
Definition pg_list.h:68
FormData_pg_proc * Form_pg_proc
Definition pg_proc.h:136
int16 pronargs
Definition pg_proc.h:81
uint64_t Datum
Definition postgres.h:70
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
struct _FuncCandidateList * next
Definition namespace.h:31
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:595
#define ReleaseSysCacheList(x)
Definition syscache.h:134
#define SearchSysCacheList1(cacheId, key1)
Definition syscache.h:127

References activeSearchPath, ARR_DATA_PTR, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_NDIM, Assert, CStringGetDatum(), DatumGetArrayTypeP, DeconstructQualifiedName(), elog, ERROR, fb(), FGC_ARGCOUNT_MATCH, FGC_ARGNAMES_VALID, FGC_NAME_EXISTS, FGC_NAME_VISIBLE, FGC_SCHEMA_EXISTS, FGC_SCHEMA_GIVEN, funcname, GETSTRUCT(), i, InvalidOid, j, lfirst_oid, LookupExplicitNamespace(), MatchNamedCall(), Max, myTempNamespace, _FuncCandidateList::nargs, _FuncCandidateList::next, NIL, OidIsValid, palloc(), pfree(), pronargs, recomputeNamespacePath(), ReleaseSysCacheList, SearchSysCacheList1, and SysCacheGetAttr().

Referenced by func_get_detail(), FunctionIsVisibleExt(), LookupFuncNameInternal(), regprocedurein(), regprocin(), and regprocout().

◆ FunctionIsVisible()

bool FunctionIsVisible ( Oid  funcid)
extern

Definition at line 1741 of file namespace.c.

1742{
1743 return FunctionIsVisibleExt(funcid, NULL);
1744}
static bool FunctionIsVisibleExt(Oid funcid, bool *is_missing)
Definition namespace.c:1753

References fb(), and FunctionIsVisibleExt().

Referenced by format_procedure_extended().

◆ get_collation_oid()

Oid get_collation_oid ( List collname,
bool  missing_ok 
)
extern

Definition at line 4041 of file namespace.c.

4042{
4043 char *schemaname;
4044 char *collation_name;
4047 Oid colloid;
4048 ListCell *l;
4049
4050 /* deconstruct the name list */
4051 DeconstructQualifiedName(collname, &schemaname, &collation_name);
4052
4053 if (schemaname)
4054 {
4055 /* use exact schema given */
4056 namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
4057 if (missing_ok && !OidIsValid(namespaceId))
4058 return InvalidOid;
4059
4061 if (OidIsValid(colloid))
4062 return colloid;
4063 }
4064 else
4065 {
4066 /* search for it in search path */
4068
4069 foreach(l, activeSearchPath)
4070 {
4072
4074 continue; /* do not look in temp namespace */
4075
4077 if (OidIsValid(colloid))
4078 return colloid;
4079 }
4080 }
4081
4082 /* Not found in path */
4083 if (!missing_ok)
4084 ereport(ERROR,
4086 errmsg("collation \"%s\" for encoding \"%s\" does not exist",
4088 return InvalidOid;
4089}
const char * GetDatabaseEncodingName(void)
Definition mbutils.c:1270

References activeSearchPath, DeconstructQualifiedName(), ereport, errcode(), errmsg(), ERROR, fb(), GetDatabaseEncoding(), GetDatabaseEncodingName(), InvalidOid, lfirst_oid, lookup_collation(), LookupExplicitNamespace(), myTempNamespace, NameListToString(), OidIsValid, and recomputeNamespacePath().

Referenced by AlterCollation(), ComputeIndexAttrs(), ComputePartitionAttrs(), DefineCollation(), DefineDomain(), DefineRange(), get_object_address(), LookupCollation(), and regcollationin().

◆ get_conversion_oid()

Oid get_conversion_oid ( List conname,
bool  missing_ok 
)
extern

Definition at line 4095 of file namespace.c.

4096{
4097 char *schemaname;
4098 char *conversion_name;
4100 Oid conoid = InvalidOid;
4101 ListCell *l;
4102
4103 /* deconstruct the name list */
4104 DeconstructQualifiedName(conname, &schemaname, &conversion_name);
4105
4106 if (schemaname)
4107 {
4108 /* use exact schema given */
4109 namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
4110 if (missing_ok && !OidIsValid(namespaceId))
4111 conoid = InvalidOid;
4112 else
4114 PointerGetDatum(conversion_name),
4116 }
4117 else
4118 {
4119 /* search for it in search path */
4121
4122 foreach(l, activeSearchPath)
4123 {
4125
4127 continue; /* do not look in temp namespace */
4128
4130 PointerGetDatum(conversion_name),
4132 if (OidIsValid(conoid))
4133 return conoid;
4134 }
4135 }
4136
4137 /* Not found in path */
4138 if (!OidIsValid(conoid) && !missing_ok)
4139 ereport(ERROR,
4141 errmsg("conversion \"%s\" does not exist",
4142 NameListToString(conname))));
4143 return conoid;
4144}

References activeSearchPath, DeconstructQualifiedName(), ereport, errcode(), errmsg(), ERROR, fb(), GetSysCacheOid2, InvalidOid, lfirst_oid, LookupExplicitNamespace(), myTempNamespace, NameListToString(), ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), and recomputeNamespacePath().

Referenced by get_object_address().

◆ get_namespace_oid()

◆ get_statistics_object_oid()

Oid get_statistics_object_oid ( List names,
bool  missing_ok 
)
extern

Definition at line 2642 of file namespace.c.

2643{
2644 char *schemaname;
2645 char *stats_name;
2648 ListCell *l;
2649
2650 /* deconstruct the name list */
2651 DeconstructQualifiedName(names, &schemaname, &stats_name);
2652
2653 if (schemaname)
2654 {
2655 /* use exact schema given */
2656 namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
2657 if (missing_ok && !OidIsValid(namespaceId))
2659 else
2663 }
2664 else
2665 {
2666 /* search for it in search path */
2668
2669 foreach(l, activeSearchPath)
2670 {
2672
2674 continue; /* do not look in temp namespace */
2678 if (OidIsValid(stats_oid))
2679 break;
2680 }
2681 }
2682
2683 if (!OidIsValid(stats_oid) && !missing_ok)
2684 ereport(ERROR,
2686 errmsg("statistics object \"%s\" does not exist",
2687 NameListToString(names))));
2688
2689 return stats_oid;
2690}

References activeSearchPath, DeconstructQualifiedName(), ereport, errcode(), errmsg(), ERROR, fb(), GetSysCacheOid2, InvalidOid, lfirst_oid, LookupExplicitNamespace(), myTempNamespace, NameListToString(), ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), and recomputeNamespacePath().

Referenced by AlterStatistics(), and get_object_address().

◆ get_ts_config_oid()

Oid get_ts_config_oid ( List names,
bool  missing_ok 
)
extern

Definition at line 3222 of file namespace.c.

3223{
3224 char *schemaname;
3225 char *config_name;
3228 ListCell *l;
3229
3230 /* deconstruct the name list */
3231 DeconstructQualifiedName(names, &schemaname, &config_name);
3232
3233 if (schemaname)
3234 {
3235 /* use exact schema given */
3236 namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
3237 if (missing_ok && !OidIsValid(namespaceId))
3239 else
3243 }
3244 else
3245 {
3246 /* search for it in search path */
3248
3249 foreach(l, activeSearchPath)
3250 {
3252
3254 continue; /* do not look in temp namespace */
3255
3259 if (OidIsValid(cfgoid))
3260 break;
3261 }
3262 }
3263
3264 if (!OidIsValid(cfgoid) && !missing_ok)
3265 ereport(ERROR,
3267 errmsg("text search configuration \"%s\" does not exist",
3268 NameListToString(names))));
3269
3270 return cfgoid;
3271}

References activeSearchPath, DeconstructQualifiedName(), ereport, errcode(), errmsg(), ERROR, fb(), GetSysCacheOid2, InvalidOid, lfirst_oid, LookupExplicitNamespace(), myTempNamespace, NameListToString(), ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), and recomputeNamespacePath().

Referenced by check_default_text_search_config(), DefineTSConfiguration(), get_object_address(), GetTSConfigTuple(), getTSCurrentConfig(), regconfigin(), and tsvector_update_trigger().

◆ get_ts_dict_oid()

Oid get_ts_dict_oid ( List names,
bool  missing_ok 
)
extern

Definition at line 2931 of file namespace.c.

2932{
2933 char *schemaname;
2934 char *dict_name;
2937 ListCell *l;
2938
2939 /* deconstruct the name list */
2940 DeconstructQualifiedName(names, &schemaname, &dict_name);
2941
2942 if (schemaname)
2943 {
2944 /* use exact schema given */
2945 namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
2946 if (missing_ok && !OidIsValid(namespaceId))
2948 else
2952 }
2953 else
2954 {
2955 /* search for it in search path */
2957
2958 foreach(l, activeSearchPath)
2959 {
2961
2963 continue; /* do not look in temp namespace */
2964
2968 if (OidIsValid(dictoid))
2969 break;
2970 }
2971 }
2972
2973 if (!OidIsValid(dictoid) && !missing_ok)
2974 ereport(ERROR,
2976 errmsg("text search dictionary \"%s\" does not exist",
2977 NameListToString(names))));
2978
2979 return dictoid;
2980}

References activeSearchPath, DeconstructQualifiedName(), ereport, errcode(), errmsg(), ERROR, fb(), GetSysCacheOid2, InvalidOid, lfirst_oid, LookupExplicitNamespace(), myTempNamespace, NameListToString(), ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), and recomputeNamespacePath().

Referenced by AlterTSDictionary(), get_object_address(), MakeConfigurationMapping(), regdictionaryin(), and thesaurus_init().

◆ get_ts_parser_oid()

Oid get_ts_parser_oid ( List names,
bool  missing_ok 
)
extern

Definition at line 2786 of file namespace.c.

2787{
2788 char *schemaname;
2789 char *parser_name;
2792 ListCell *l;
2793
2794 /* deconstruct the name list */
2795 DeconstructQualifiedName(names, &schemaname, &parser_name);
2796
2797 if (schemaname)
2798 {
2799 /* use exact schema given */
2800 namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
2801 if (missing_ok && !OidIsValid(namespaceId))
2803 else
2807 }
2808 else
2809 {
2810 /* search for it in search path */
2812
2813 foreach(l, activeSearchPath)
2814 {
2816
2818 continue; /* do not look in temp namespace */
2819
2823 if (OidIsValid(prsoid))
2824 break;
2825 }
2826 }
2827
2828 if (!OidIsValid(prsoid) && !missing_ok)
2829 ereport(ERROR,
2831 errmsg("text search parser \"%s\" does not exist",
2832 NameListToString(names))));
2833
2834 return prsoid;
2835}

References activeSearchPath, DeconstructQualifiedName(), ereport, errcode(), errmsg(), ERROR, fb(), GetSysCacheOid2, InvalidOid, lfirst_oid, LookupExplicitNamespace(), myTempNamespace, NameListToString(), ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), and recomputeNamespacePath().

Referenced by DefineTSConfiguration(), get_object_address(), ts_parse_byname(), and ts_token_type_byname().

◆ get_ts_template_oid()

Oid get_ts_template_oid ( List names,
bool  missing_ok 
)
extern

Definition at line 3077 of file namespace.c.

3078{
3079 char *schemaname;
3080 char *template_name;
3083 ListCell *l;
3084
3085 /* deconstruct the name list */
3086 DeconstructQualifiedName(names, &schemaname, &template_name);
3087
3088 if (schemaname)
3089 {
3090 /* use exact schema given */
3091 namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
3092 if (missing_ok && !OidIsValid(namespaceId))
3094 else
3098 }
3099 else
3100 {
3101 /* search for it in search path */
3103
3104 foreach(l, activeSearchPath)
3105 {
3107
3109 continue; /* do not look in temp namespace */
3110
3114 if (OidIsValid(tmploid))
3115 break;
3116 }
3117 }
3118
3119 if (!OidIsValid(tmploid) && !missing_ok)
3120 ereport(ERROR,
3122 errmsg("text search template \"%s\" does not exist",
3123 NameListToString(names))));
3124
3125 return tmploid;
3126}

References activeSearchPath, DeconstructQualifiedName(), ereport, errcode(), errmsg(), ERROR, fb(), GetSysCacheOid2, InvalidOid, lfirst_oid, LookupExplicitNamespace(), myTempNamespace, NameListToString(), ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), and recomputeNamespacePath().

Referenced by DefineTSDictionary(), and get_object_address().

◆ GetSearchPathMatcher()

SearchPathMatcher * GetSearchPathMatcher ( MemoryContext  context)
extern

Definition at line 3922 of file namespace.c.

3923{
3924 SearchPathMatcher *result;
3925 List *schemas;
3927
3929
3930 oldcxt = MemoryContextSwitchTo(context);
3931
3933 schemas = list_copy(activeSearchPath);
3934 while (schemas && linitial_oid(schemas) != activeCreationNamespace)
3935 {
3936 if (linitial_oid(schemas) == myTempNamespace)
3937 result->addTemp = true;
3938 else
3939 {
3941 result->addCatalog = true;
3942 }
3943 schemas = list_delete_first(schemas);
3944 }
3945 result->schemas = schemas;
3947
3949
3950 return result;
3951}
#define palloc0_object(type)
Definition fe_memutils.h:75
static uint64 activePathGeneration
Definition namespace.c:144
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124

References activeCreationNamespace, activePathGeneration, activeSearchPath, SearchPathMatcher::addCatalog, SearchPathMatcher::addTemp, Assert, fb(), SearchPathMatcher::generation, linitial_oid, list_copy(), list_delete_first(), MemoryContextSwitchTo(), myTempNamespace, palloc0_object, recomputeNamespacePath(), and SearchPathMatcher::schemas.

Referenced by CompleteCachedPlan(), and RevalidateCachedQuery().

◆ GetTempNamespaceProcNumber()

ProcNumber GetTempNamespaceProcNumber ( Oid  namespaceId)
extern

Definition at line 3836 of file namespace.c.

3837{
3838 int result;
3839 char *nspname;
3840
3841 /* See if the namespace name starts with "pg_temp_" or "pg_toast_temp_" */
3843 if (!nspname)
3844 return INVALID_PROC_NUMBER; /* no such namespace? */
3845 if (strncmp(nspname, "pg_temp_", 8) == 0)
3846 result = atoi(nspname + 8);
3847 else if (strncmp(nspname, "pg_toast_temp_", 14) == 0)
3848 result = atoi(nspname + 14);
3849 else
3850 result = INVALID_PROC_NUMBER;
3851 pfree(nspname);
3852 return result;
3853}
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3516

References fb(), get_namespace_name(), INVALID_PROC_NUMBER, and pfree().

Referenced by checkTempNamespaceStatus(), pg_relation_filepath(), and RelationBuildDesc().

◆ GetTempNamespaceState()

void GetTempNamespaceState ( Oid tempNamespaceId,
Oid tempToastNamespaceId 
)
extern

Definition at line 3875 of file namespace.c.

3876{
3877 /* Return namespace OIDs, or 0 if session has not created temp namespace */
3878 *tempNamespaceId = myTempNamespace;
3880}

References fb(), myTempNamespace, and myTempToastNamespace.

Referenced by InitializeParallelDSM().

◆ GetTempToastNamespace()

Oid GetTempToastNamespace ( void  )
extern

Definition at line 3861 of file namespace.c.

3862{
3864 return myTempToastNamespace;
3865}

References Assert, myTempToastNamespace, and OidIsValid.

Referenced by create_toast_table().

◆ InitializeSearchPath()

void InitializeSearchPath ( void  )
extern

Definition at line 4806 of file namespace.c.

4807{
4809 {
4810 /*
4811 * In bootstrap mode, the search path must be 'pg_catalog' so that
4812 * tables are created in the proper namespace; ignore the GUC setting.
4813 */
4815
4821 baseSearchPathValid = true;
4826 activePathGeneration++; /* pro forma */
4827 }
4828 else
4829 {
4830 /*
4831 * In normal mode, arrange for a callback on any syscache invalidation
4832 * that will affect the search_path cache.
4833 */
4834
4835 /* namespace name or ACLs may have changed */
4838 (Datum) 0);
4839
4840 /* role name may affect the meaning of "$user" */
4843 (Datum) 0);
4844
4845 /* role membership may affect ACLs */
4848 (Datum) 0);
4849
4850 /* database owner may affect ACLs */
4853 (Datum) 0);
4854
4855 /* Force search path to be recomputed on next use */
4856 baseSearchPathValid = false;
4857 searchPathCacheValid = false;
4858 }
4859}
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Definition inval.c:1816
MemoryContext TopMemoryContext
Definition mcxt.c:166
#define IsBootstrapProcessingMode()
Definition miscadmin.h:477
Oid GetUserId(void)
Definition miscinit.c:469
static bool baseTempCreationPending
Definition namespace.c:152
static Oid baseCreationNamespace
Definition namespace.c:150
static Oid namespaceUser
Definition namespace.c:154
static void InvalidationCallback(Datum arg, int cacheid, uint32 hashvalue)
Definition namespace.c:4866
static List * baseSearchPath
Definition namespace.c:148
#define list_make1_oid(x1)
Definition pg_list.h:242

References activeCreationNamespace, activePathGeneration, activeSearchPath, activeTempCreationPending, baseCreationNamespace, baseSearchPath, baseSearchPathValid, baseTempCreationPending, CacheRegisterSyscacheCallback(), fb(), GetUserId(), InvalidationCallback(), IsBootstrapProcessingMode, list_make1_oid, MemoryContextSwitchTo(), namespaceUser, searchPathCacheValid, and TopMemoryContext.

Referenced by InitPostgres().

◆ isAnyTempNamespace()

bool isAnyTempNamespace ( Oid  namespaceId)
extern

Definition at line 3757 of file namespace.c.

3758{
3759 bool result;
3760 char *nspname;
3761
3762 /* True if the namespace name starts with "pg_temp_" or "pg_toast_temp_" */
3764 if (!nspname)
3765 return false; /* no such namespace? */
3766 result = (strncmp(nspname, "pg_temp_", 8) == 0) ||
3767 (strncmp(nspname, "pg_toast_temp_", 14) == 0);
3768 pfree(nspname);
3769 return result;
3770}

References fb(), get_namespace_name(), and pfree().

Referenced by AlterTableMoveAll(), check_publication_add_schema(), CheckSetNamespace(), EventTriggerSQLDropAddObject(), find_temp_object(), isOtherTempNamespace(), obtain_object_name_namespace(), and RangeVarAdjustRelationPersistence().

◆ isOtherTempNamespace()

bool isOtherTempNamespace ( Oid  namespaceId)
extern

Definition at line 3780 of file namespace.c.

3781{
3782 /* If it's my own temp namespace, say "false" */
3784 return false;
3785 /* Else, if it's any temp namespace, say "true" */
3787}
bool isTempOrTempToastNamespace(Oid namespaceId)
Definition namespace.c:3743

References fb(), isAnyTempNamespace(), and isTempOrTempToastNamespace().

Referenced by pg_is_other_temp_schema().

◆ isTempNamespace()

◆ isTempOrTempToastNamespace()

bool isTempOrTempToastNamespace ( Oid  namespaceId)
extern

◆ isTempToastNamespace()

bool isTempToastNamespace ( Oid  namespaceId)
extern

Definition at line 3731 of file namespace.c.

3732{
3734 return true;
3735 return false;
3736}

References fb(), myTempToastNamespace, and OidIsValid.

Referenced by IsToastNamespace().

◆ LookupCreationNamespace()

Oid LookupCreationNamespace ( const char nspname)
extern

Definition at line 3498 of file namespace.c.

3499{
3502
3503 /* check for pg_temp alias */
3504 if (strcmp(nspname, "pg_temp") == 0)
3505 {
3506 /* Initialize temp namespace */
3508 return myTempNamespace;
3509 }
3510
3511 namespaceId = get_namespace_oid(nspname, false);
3512
3514 if (aclresult != ACLCHECK_OK)
3516 nspname);
3517
3518 return namespaceId;
3519}
AclResult
Definition acl.h:182
@ ACLCHECK_OK
Definition acl.h:183
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2654
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3836
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition namespace.c:3605
@ OBJECT_SCHEMA
#define ACL_CREATE
Definition parsenodes.h:85

References AccessTempTableNamespace(), ACL_CREATE, aclcheck_error(), ACLCHECK_OK, fb(), get_namespace_oid(), GetUserId(), myTempNamespace, object_aclcheck(), and OBJECT_SCHEMA.

Referenced by AlterExtensionNamespace(), AlterTypeNamespace(), ExecAlterObjectSchemaStmt(), ImportForeignSchema(), and make_new_heap().

◆ LookupExplicitNamespace()

Oid LookupExplicitNamespace ( const char nspname,
bool  missing_ok 
)
extern

Definition at line 3455 of file namespace.c.

3456{
3459
3460 /* check for pg_temp alias */
3461 if (strcmp(nspname, "pg_temp") == 0)
3462 {
3464 return myTempNamespace;
3465
3466 /*
3467 * Since this is used only for looking up existing objects, there is
3468 * no point in trying to initialize the temp namespace here; and doing
3469 * so might create problems for some callers --- just fall through.
3470 */
3471 }
3472
3473 namespaceId = get_namespace_oid(nspname, missing_ok);
3474 if (missing_ok && !OidIsValid(namespaceId))
3475 return InvalidOid;
3476
3478 if (aclresult != ACLCHECK_OK)
3480 nspname);
3481 /* Schema search hook for this lookup */
3483
3484 return namespaceId;
3485}
#define InvokeNamespaceSearchHook(objectId, ereport_on_violation)
#define ACL_USAGE
Definition parsenodes.h:84

References ACL_USAGE, aclcheck_error(), ACLCHECK_OK, fb(), get_namespace_oid(), GetUserId(), InvalidOid, InvokeNamespaceSearchHook, myTempNamespace, object_aclcheck(), OBJECT_SCHEMA, and OidIsValid.

Referenced by AfterTriggerSetState(), FuncnameGetCandidates(), get_collation_oid(), get_conversion_oid(), get_statistics_object_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), LookupTypeNameExtended(), make_oper_cache_key(), objectsInSchemaToOids(), OpClassCacheLookup(), OpernameGetCandidates(), OpernameGetOprid(), OpFamilyCacheLookup(), RangeVarGetRelidExtended(), ResolveOpClass(), schema_to_xml(), schema_to_xml_and_xmlschema(), and schema_to_xmlschema_internal().

◆ LookupNamespaceNoError()

Oid LookupNamespaceNoError ( const char nspname)
extern

Definition at line 3425 of file namespace.c.

3426{
3427 /* check for pg_temp alias */
3428 if (strcmp(nspname, "pg_temp") == 0)
3429 {
3431 {
3433 return myTempNamespace;
3434 }
3435
3436 /*
3437 * Since this is used only for looking up existing objects, there is
3438 * no point in trying to initialize the temp namespace here; and doing
3439 * so might create problems for some callers. Just report "not found".
3440 */
3441 return InvalidOid;
3442 }
3443
3444 return get_namespace_oid(nspname, true);
3445}

References fb(), get_namespace_oid(), InvalidOid, InvokeNamespaceSearchHook, myTempNamespace, and OidIsValid.

Referenced by DropErrorMsgNonExistent(), refnameNamespaceItem(), and schema_does_not_exist_skipping().

◆ makeRangeVarFromNameList()

RangeVar * makeRangeVarFromNameList ( const List names)
extern

Definition at line 3624 of file namespace.c.

3625{
3626 RangeVar *rel = makeRangeVar(NULL, NULL, -1);
3627
3628 switch (list_length(names))
3629 {
3630 case 1:
3631 rel->relname = strVal(linitial(names));
3632 break;
3633 case 2:
3634 rel->schemaname = strVal(linitial(names));
3635 rel->relname = strVal(lsecond(names));
3636 break;
3637 case 3:
3638 rel->catalogname = strVal(linitial(names));
3639 rel->schemaname = strVal(lsecond(names));
3640 rel->relname = strVal(lthird(names));
3641 break;
3642 default:
3643 ereport(ERROR,
3645 errmsg("improper relation name (too many dotted names): %s",
3646 NameListToString(names))));
3647 break;
3648 }
3649
3650 return rel;
3651}
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition makefuncs.c:473
char * relname
Definition primnodes.h:83
char * catalogname
Definition primnodes.h:77
char * schemaname
Definition primnodes.h:80

References RangeVar::catalogname, ereport, errcode(), errmsg(), ERROR, fb(), linitial, list_length(), lsecond, lthird, makeRangeVar(), NameListToString(), RangeVar::relname, RangeVar::schemaname, and strVal.

Referenced by bt_metap(), bt_multi_page_stats(), bt_page_items_internal(), bt_page_stats_internal(), convert_table_name(), currtid_byrelname(), generateSerialExtraStmts(), get_object_address_attrdef(), get_object_address_attribute(), get_object_address_publication_rel(), get_object_address_relobject(), get_raw_page_internal(), get_rel_from_relname(), get_relation_by_qualified_name(), nextval(), owningrel_does_not_exist_skipping(), pg_get_serial_sequence(), pg_get_viewdef_name(), pg_get_viewdef_name_ext(), pg_relpages(), pg_relpages_v1_5(), pgrowlocks(), pgstatindex(), pgstatindex_v1_5(), pgstattuple(), pgstattuple_v1_5(), plpgsql_parse_cwordrowtype(), plpgsql_parse_cwordtype(), process_owned_by(), regclassin(), RelationNameGetTupleDesc(), RemoveRelations(), row_security_active_name(), schema_does_not_exist_skipping(), and text_regclass().

◆ NameListToQuotedString()

char * NameListToQuotedString ( const List names)
extern

Definition at line 3698 of file namespace.c.

3699{
3701 ListCell *l;
3702
3703 initStringInfo(&string);
3704
3705 foreach(l, names)
3706 {
3707 if (l != list_head(names))
3708 appendStringInfoChar(&string, '.');
3710 }
3711
3712 return string.data;
3713}
#define lfirst(lc)
Definition pg_list.h:172
static ListCell * list_head(const List *l)
Definition pg_list.h:128
char string[11]
const char * quote_identifier(const char *ident)
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
void initStringInfo(StringInfo str)
Definition stringinfo.c:97

References appendStringInfoChar(), appendStringInfoString(), initStringInfo(), lfirst, list_head(), quote_identifier(), and strVal.

◆ NameListToString()

char * NameListToString ( const List names)
extern

Definition at line 3664 of file namespace.c.

3665{
3667 ListCell *l;
3668
3669 initStringInfo(&string);
3670
3671 foreach(l, names)
3672 {
3673 Node *name = (Node *) lfirst(l);
3674
3675 if (l != list_head(names))
3676 appendStringInfoChar(&string, '.');
3677
3678 if (IsA(name, String))
3680 else if (IsA(name, A_Star))
3681 appendStringInfoChar(&string, '*');
3682 else
3683 elog(ERROR, "unexpected node type in name list: %d",
3684 (int) nodeTag(name));
3685 }
3686
3687 return string.data;
3688}
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define nodeTag(nodeptr)
Definition nodes.h:139
Definition nodes.h:135
Definition value.h:64
const char * name

References appendStringInfoChar(), appendStringInfoString(), elog, ERROR, initStringInfo(), IsA, lfirst, list_head(), name, nodeTag, and strVal.

Referenced by AggregateCreate(), AlterCollation(), AlterFunction(), AlterStatistics(), AlterTSConfiguration(), AlterTSDictionary(), check_object_ownership(), CreateConversionCommand(), CreateEventTrigger(), CreateProceduralLanguage(), CreateTransform(), CreateTriggerFiringOn(), DeconstructQualifiedName(), defGetString(), DefineOperator(), DefineType(), does_not_exist_skipping(), dropOperators(), dropProcedures(), ExpandColumnRefStar(), findRangeSubOpclass(), findTypeAnalyzeFunction(), findTypeInputFunction(), findTypeOutputFunction(), findTypeReceiveFunction(), findTypeSendFunction(), findTypeSubscriptingFunction(), findTypeTypmodinFunction(), findTypeTypmodoutFunction(), func_signature_string(), get_collation_oid(), get_conversion_oid(), get_object_address_attrdef(), get_object_address_attribute(), get_statistics_object_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), interpret_func_support(), lookup_fdw_handler_func(), LookupFuncName(), LookupFuncWithArgs(), LookupTypeNameExtended(), makeRangeVarFromNameList(), op_signature_string(), OpClassCacheLookup(), OperatorCreate(), OpFamilyCacheLookup(), owningrel_does_not_exist_skipping(), ParseFuncOrColumn(), plpgsql_post_column_ref(), regclassin(), regcollationin(), regconfigin(), regdictionaryin(), RemoveObjects(), ResolveOpClass(), storeOperators(), storeProcedures(), transformColumnRef(), transformRangeTableSample(), ValidateJoinEstimator(), ValidateOperatorReference(), and ValidateRestrictionEstimator().

◆ OpclassIsVisible()

bool OpclassIsVisible ( Oid  opcid)
extern

Definition at line 2221 of file namespace.c.

2222{
2224}
static bool OpclassIsVisibleExt(Oid opcid, bool *is_missing)
Definition namespace.c:2233

References fb(), and OpclassIsVisibleExt().

Referenced by get_opclass_name(), and getObjectDescription().

◆ OpclassnameGetOpcid()

Oid OpclassnameGetOpcid ( Oid  amid,
const char opcname 
)
extern

Definition at line 2188 of file namespace.c.

2189{
2190 Oid opcid;
2191 ListCell *l;
2192
2194
2195 foreach(l, activeSearchPath)
2196 {
2198
2200 continue; /* do not look in temp namespace */
2201
2206 if (OidIsValid(opcid))
2207 return opcid;
2208 }
2209
2210 /* Not found in path */
2211 return InvalidOid;
2212}
#define GetSysCacheOid3(cacheId, oidcol, key1, key2, key3)
Definition syscache.h:113

References activeSearchPath, fb(), GetSysCacheOid3, InvalidOid, lfirst_oid, myTempNamespace, ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), and recomputeNamespacePath().

Referenced by OpClassCacheLookup(), OpclassIsVisibleExt(), and ResolveOpClass().

◆ OperatorIsVisible()

bool OperatorIsVisible ( Oid  oprid)
extern

Definition at line 2116 of file namespace.c.

2117{
2119}
static bool OperatorIsVisibleExt(Oid oprid, bool *is_missing)
Definition namespace.c:2128
Oid oprid(Operator op)
Definition parse_oper.c:239

References fb(), OperatorIsVisibleExt(), and oprid().

Referenced by format_operator_extended().

◆ OpernameGetCandidates()

FuncCandidateList OpernameGetCandidates ( List names,
char  oprkind,
bool  missing_schema_ok,
int fgc_flags 
)
extern

Definition at line 1945 of file namespace.c.

1947{
1949 char *resultSpace = NULL;
1950 int nextResult = 0;
1951 char *schemaname;
1952 char *opername;
1955 int i;
1956
1957 /* initialize output fgc_flags to empty */
1958 *fgc_flags = 0;
1959
1960 /* deconstruct the name list */
1961 DeconstructQualifiedName(names, &schemaname, &opername);
1962
1963 if (schemaname)
1964 {
1965 /* use exact schema given */
1966 *fgc_flags |= FGC_SCHEMA_GIVEN; /* report that a schema is given */
1968 if (!OidIsValid(namespaceId))
1969 return NULL;
1970 *fgc_flags |= FGC_SCHEMA_EXISTS; /* report that the schema exists */
1971 }
1972 else
1973 {
1974 /* flag to indicate we need namespace search */
1977 }
1978
1979 /* Search syscache by name only */
1981
1982 /*
1983 * In typical scenarios, most if not all of the operators found by the
1984 * catcache search will end up getting returned; and there can be quite a
1985 * few, for common operator names such as '=' or '+'. To reduce the time
1986 * spent in palloc, we allocate the result space as an array large enough
1987 * to hold all the operators. The original coding of this routine did a
1988 * separate palloc for each operator, but profiling revealed that the
1989 * pallocs used an unreasonably large fraction of parsing time.
1990 */
1991#define SPACE_PER_OP MAXALIGN(offsetof(struct _FuncCandidateList, args) + \
1992 2 * sizeof(Oid))
1993
1994 if (catlist->n_members > 0)
1995 resultSpace = palloc(catlist->n_members * SPACE_PER_OP);
1996
1997 for (i = 0; i < catlist->n_members; i++)
1998 {
1999 HeapTuple opertup = &catlist->members[i]->tuple;
2001 int pathpos = 0;
2003
2004 /* Ignore operators of wrong kind, if specific kind requested */
2005 if (oprkind && operform->oprkind != oprkind)
2006 continue;
2007
2008 *fgc_flags |= FGC_NAME_EXISTS; /* the name is present in pg_operator */
2009
2011 {
2012 /* Consider only opers in specified namespace */
2013 if (operform->oprnamespace != namespaceId)
2014 continue;
2015 /* No need to check args, they must all be different */
2016 }
2017 else
2018 {
2019 /*
2020 * Consider only opers that are in the search path and are not in
2021 * the temp namespace.
2022 */
2023 ListCell *nsp;
2024
2025 foreach(nsp, activeSearchPath)
2026 {
2027 if (operform->oprnamespace == lfirst_oid(nsp) &&
2028 operform->oprnamespace != myTempNamespace)
2029 break;
2030 pathpos++;
2031 }
2032 if (nsp == NULL)
2033 continue; /* oper is not in search path */
2034
2035 /*
2036 * Okay, it's in the search path, but does it have the same
2037 * arguments as something we already accepted? If so, keep only
2038 * the one that appears earlier in the search path.
2039 *
2040 * If we have an ordered list from SearchSysCacheList (the normal
2041 * case), then any conflicting oper must immediately adjoin this
2042 * one in the list, so we only need to look at the newest result
2043 * item. If we have an unordered list, we have to scan the whole
2044 * result list.
2045 */
2046 if (resultList)
2047 {
2049
2050 if (catlist->ordered)
2051 {
2052 if (operform->oprleft == resultList->args[0] &&
2053 operform->oprright == resultList->args[1])
2055 else
2056 prevResult = NULL;
2057 }
2058 else
2059 {
2060 for (prevResult = resultList;
2061 prevResult;
2062 prevResult = prevResult->next)
2063 {
2064 if (operform->oprleft == prevResult->args[0] &&
2065 operform->oprright == prevResult->args[1])
2066 break;
2067 }
2068 }
2069 if (prevResult)
2070 {
2071 /* We have a match with a previous result */
2072 Assert(pathpos != prevResult->pathpos);
2073 if (pathpos > prevResult->pathpos)
2074 continue; /* keep previous result */
2075 /* replace previous result */
2076 prevResult->pathpos = pathpos;
2077 prevResult->oid = operform->oid;
2078 continue; /* args are same, of course */
2079 }
2080 }
2081 }
2082
2083 *fgc_flags |= FGC_NAME_VISIBLE; /* operator is in the right schema */
2084
2085 /*
2086 * Okay to add it to result list
2087 */
2090
2091 newResult->pathpos = pathpos;
2092 newResult->oid = operform->oid;
2093 newResult->nominalnargs = 2;
2094 newResult->nargs = 2;
2095 newResult->nvargs = 0;
2096 newResult->ndargs = 0;
2097 newResult->argnumbers = NULL;
2098 newResult->args[0] = operform->oprleft;
2099 newResult->args[1] = operform->oprright;
2100 newResult->next = resultList;
2102 }
2103
2105
2106 return resultList;
2107}
#define SPACE_PER_OP
FormData_pg_operator * Form_pg_operator
Definition pg_operator.h:83

References activeSearchPath, Assert, CStringGetDatum(), DeconstructQualifiedName(), fb(), FGC_NAME_EXISTS, FGC_NAME_VISIBLE, FGC_SCHEMA_EXISTS, FGC_SCHEMA_GIVEN, GETSTRUCT(), i, InvalidOid, lfirst_oid, LookupExplicitNamespace(), myTempNamespace, OidIsValid, palloc(), recomputeNamespacePath(), ReleaseSysCacheList, SearchSysCacheList1, and SPACE_PER_OP.

Referenced by left_oper(), oper(), regoperin(), and regoperout().

◆ OpernameGetOprid()

Oid OpernameGetOprid ( List names,
Oid  oprleft,
Oid  oprright 
)
extern

Definition at line 1832 of file namespace.c.

1833{
1834 char *schemaname;
1835 char *opername;
1837 ListCell *l;
1838
1839 /* deconstruct the name list */
1840 DeconstructQualifiedName(names, &schemaname, &opername);
1841
1842 if (schemaname)
1843 {
1844 /* search only in exact schema given */
1846
1847 namespaceId = LookupExplicitNamespace(schemaname, true);
1849 {
1851
1853 CStringGetDatum(opername),
1854 ObjectIdGetDatum(oprleft),
1855 ObjectIdGetDatum(oprright),
1858 {
1860 Oid result = operclass->oid;
1861
1863 return result;
1864 }
1865 }
1866
1867 return InvalidOid;
1868 }
1869
1870 /* Search syscache by name and argument types */
1872 CStringGetDatum(opername),
1873 ObjectIdGetDatum(oprleft),
1874 ObjectIdGetDatum(oprright));
1875
1876 if (catlist->n_members == 0)
1877 {
1878 /* no hope, fall out early */
1880 return InvalidOid;
1881 }
1882
1883 /*
1884 * We have to find the list member that is first in the search path, if
1885 * there's more than one. This doubly-nested loop looks ugly, but in
1886 * practice there should usually be few catlist members.
1887 */
1889
1890 foreach(l, activeSearchPath)
1891 {
1893 int i;
1894
1896 continue; /* do not look in temp namespace */
1897
1898 for (i = 0; i < catlist->n_members; i++)
1899 {
1900 HeapTuple opertup = &catlist->members[i]->tuple;
1902
1903 if (operform->oprnamespace == namespaceId)
1904 {
1905 Oid result = operform->oid;
1906
1908 return result;
1909 }
1910 }
1911 }
1912
1914 return InvalidOid;
1915}
#define HeapTupleIsValid(tuple)
Definition htup.h:78
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition syscache.c:250
#define SearchSysCacheList3(cacheId, key1, key2, key3)
Definition syscache.h:131

References activeSearchPath, CStringGetDatum(), DeconstructQualifiedName(), fb(), GETSTRUCT(), HeapTupleIsValid, i, InvalidOid, lfirst_oid, LookupExplicitNamespace(), myTempNamespace, ObjectIdGetDatum(), OidIsValid, recomputeNamespacePath(), ReleaseSysCache(), ReleaseSysCacheList, SearchSysCache4(), and SearchSysCacheList3.

Referenced by binary_oper_exact(), left_oper(), LookupOperName(), OperatorIsVisibleExt(), and regoperatorin().

◆ OpfamilyIsVisible()

bool OpfamilyIsVisible ( Oid  opfid)
extern

Definition at line 2323 of file namespace.c.

2324{
2326}
static bool OpfamilyIsVisibleExt(Oid opfid, bool *is_missing)
Definition namespace.c:2335

References fb(), and OpfamilyIsVisibleExt().

Referenced by getOpFamilyDescription().

◆ OpfamilynameGetOpfid()

Oid OpfamilynameGetOpfid ( Oid  amid,
const char opfname 
)
extern

Definition at line 2290 of file namespace.c.

2291{
2292 Oid opfid;
2293 ListCell *l;
2294
2296
2297 foreach(l, activeSearchPath)
2298 {
2300
2302 continue; /* do not look in temp namespace */
2303
2308 if (OidIsValid(opfid))
2309 return opfid;
2310 }
2311
2312 /* Not found in path */
2313 return InvalidOid;
2314}

References activeSearchPath, fb(), GetSysCacheOid3, InvalidOid, lfirst_oid, myTempNamespace, ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), and recomputeNamespacePath().

Referenced by OpFamilyCacheLookup(), and OpfamilyIsVisibleExt().

◆ QualifiedNameGetCreationNamespace()

Oid QualifiedNameGetCreationNamespace ( const List names,
char **  objname_p 
)
extern

Definition at line 3557 of file namespace.c.

3558{
3559 char *schemaname;
3561
3562 /* deconstruct the name list */
3563 DeconstructQualifiedName(names, &schemaname, objname_p);
3564
3565 if (schemaname)
3566 {
3567 /* check for pg_temp alias */
3568 if (strcmp(schemaname, "pg_temp") == 0)
3569 {
3570 /* Initialize temp namespace */
3572 return myTempNamespace;
3573 }
3574 /* use exact schema given */
3575 namespaceId = get_namespace_oid(schemaname, false);
3576 /* we do not check for USAGE rights here! */
3577 }
3578 else
3579 {
3580 /* use the default creation namespace */
3583 {
3584 /* Need to initialize temp namespace */
3586 return myTempNamespace;
3587 }
3589 if (!OidIsValid(namespaceId))
3590 ereport(ERROR,
3592 errmsg("no schema has been selected to create in")));
3593 }
3594
3595 return namespaceId;
3596}

References AccessTempTableNamespace(), activeCreationNamespace, activeTempCreationPending, DeconstructQualifiedName(), ereport, errcode(), errmsg(), ERROR, fb(), get_namespace_oid(), myTempNamespace, OidIsValid, and recomputeNamespacePath().

Referenced by compute_return_type(), CreateConversionCommand(), CreateFunction(), CreateStatistics(), DefineAggregate(), DefineCollation(), DefineDomain(), DefineEnum(), DefineOpClass(), DefineOperator(), DefineOpFamily(), DefineRange(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), DefineType(), and get_other_operator().

◆ RangeVarAdjustRelationPersistence()

void RangeVarAdjustRelationPersistence ( RangeVar newRelation,
Oid  nspid 
)
extern

Definition at line 845 of file namespace.c.

846{
847 switch (newRelation->relpersistence)
848 {
851 {
855 errmsg("cannot create relations in temporary schemas of other sessions")));
856 else
859 errmsg("cannot create temporary relation in non-temporary schema")));
860 }
861 break;
864 newRelation->relpersistence = RELPERSISTENCE_TEMP;
865 else if (isAnyTempNamespace(nspid))
868 errmsg("cannot create relations in temporary schemas of other sessions")));
869 break;
870 default:
874 errmsg("only temporary relations may be created in temporary schemas")));
875 }
876}
int nspid

References ereport, errcode(), errmsg(), ERROR, fb(), isAnyTempNamespace(), isTempOrTempToastNamespace(), and nspid.

Referenced by DefineCompositeType(), generateSerialExtraStmts(), and RangeVarGetAndCheckCreationNamespace().

◆ RangeVarGetAndCheckCreationNamespace()

Oid RangeVarGetAndCheckCreationNamespace ( RangeVar relation,
LOCKMODE  lockmode,
Oid existing_relation_id 
)
extern

Definition at line 738 of file namespace.c.

741{
743 Oid relid;
745 Oid nspid;
747 bool retry = false;
748
749 /*
750 * We check the catalog name and then ignore it.
751 */
752 if (relation->catalogname)
753 {
754 if (strcmp(relation->catalogname, get_database_name(MyDatabaseId)) != 0)
757 errmsg("cross-database references are not implemented: \"%s.%s.%s\"",
758 relation->catalogname, relation->schemaname,
759 relation->relname)));
760 }
761
762 /*
763 * As in RangeVarGetRelidExtended(), we guard against concurrent DDL
764 * operations by tracking whether any invalidation messages are processed
765 * while we're doing the name lookups and acquiring locks. See comments
766 * in that function for a more detailed explanation of this logic.
767 */
768 for (;;)
769 {
771
773
774 /* Look up creation namespace and check for existing relation. */
778 relid = get_relname_relid(relation->relname, nspid);
779 else
780 relid = InvalidOid;
781
782 /*
783 * In bootstrap processing mode, we don't bother with permissions or
784 * locking. Permissions might not be working yet, and locking is
785 * unnecessary.
786 */
788 break;
789
790 /* Check namespace permissions. */
792 if (aclresult != ACLCHECK_OK)
795
796 if (retry)
797 {
798 /* If nothing changed, we're done. */
799 if (relid == oldrelid && nspid == oldnspid)
800 break;
801 /* If creation namespace has changed, give up old lock. */
802 if (nspid != oldnspid)
805 /* If name points to something different, give up old lock. */
806 if (relid != oldrelid && OidIsValid(oldrelid) && lockmode != NoLock)
807 UnlockRelationOid(oldrelid, lockmode);
808 }
809
810 /* Lock namespace. */
811 if (nspid != oldnspid)
813
814 /* Lock relation, if required if and we have permission. */
815 if (lockmode != NoLock && OidIsValid(relid))
816 {
819 relation->relname);
820 if (relid != oldrelid)
821 LockRelationOid(relid, lockmode);
822 }
823
824 /* If no invalidation message were processed, we're done! */
826 break;
827
828 /* Something may have changed, so recheck our work. */
829 retry = true;
830 oldrelid = relid;
831 oldnspid = nspid;
832 }
833
836 *existing_relation_id = relid;
837 return nspid;
838}
@ ACLCHECK_NOT_OWNER
Definition acl.h:185
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition aclchk.c:4090
uint64_t uint64
Definition c.h:547
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition lmgr.c:229
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1008
void LockRelationOid(Oid relid, LOCKMODE lockmode)
Definition lmgr.c:107
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1068
#define NoLock
Definition lockdefs.h:34
#define AccessShareLock
Definition lockdefs.h:36
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2153
Oid get_relname_relid(const char *relname, Oid relnamespace)
Definition lsyscache.c:2035
void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid)
Definition namespace.c:845
Oid RangeVarGetCreationNamespace(const RangeVar *newRelation)
Definition namespace.c:653
ObjectType get_relkind_objtype(char relkind)
uint64 SharedInvalidMessageCounter
Definition sinval.c:24

References AccessShareLock, ACL_CREATE, aclcheck_error(), ACLCHECK_NOT_OWNER, ACLCHECK_OK, Assert, RangeVar::catalogname, ereport, errcode(), errmsg(), ERROR, fb(), get_database_name(), get_namespace_name(), get_rel_relkind(), get_relkind_objtype(), get_relname_relid(), GetUserId(), InvalidOid, IsBootstrapProcessingMode, LockDatabaseObject(), LockRelationOid(), MyDatabaseId, NoLock, nspid, object_aclcheck(), object_ownercheck(), OBJECT_SCHEMA, OidIsValid, RangeVarAdjustRelationPersistence(), RangeVarGetCreationNamespace(), RangeVar::relname, RangeVar::schemaname, SharedInvalidMessageCounter, UnlockDatabaseObject(), and UnlockRelationOid().

Referenced by AlterTableNamespace(), ATExecMergePartitions(), ATExecSplitPartition(), createPartitionTable(), DefineCompositeType(), DefineRelation(), DefineSequence(), DefineVirtualRelation(), and transformCreateStmt().

◆ RangeVarGetCreationNamespace()

Oid RangeVarGetCreationNamespace ( const RangeVar newRelation)
extern

Definition at line 653 of file namespace.c.

654{
656
657 /*
658 * We check the catalog name and then ignore it.
659 */
660 if (newRelation->catalogname)
661 {
662 if (strcmp(newRelation->catalogname, get_database_name(MyDatabaseId)) != 0)
665 errmsg("cross-database references are not implemented: \"%s.%s.%s\"",
666 newRelation->catalogname, newRelation->schemaname,
667 newRelation->relname)));
668 }
669
670 if (newRelation->schemaname)
671 {
672 /* check for pg_temp alias */
673 if (strcmp(newRelation->schemaname, "pg_temp") == 0)
674 {
675 /* Initialize temp namespace */
677 return myTempNamespace;
678 }
679 /* use exact schema given */
680 namespaceId = get_namespace_oid(newRelation->schemaname, false);
681 /* we do not check for USAGE rights here! */
682 }
683 else if (newRelation->relpersistence == RELPERSISTENCE_TEMP)
684 {
685 /* Initialize temp namespace */
687 return myTempNamespace;
688 }
689 else
690 {
691 /* use the default creation namespace */
694 {
695 /* Need to initialize temp namespace */
697 return myTempNamespace;
698 }
703 errmsg("no schema has been selected to create in")));
704 }
705
706 /* Note: callers will check for CREATE rights when appropriate */
707
708 return namespaceId;
709}

References AccessTempTableNamespace(), activeCreationNamespace, activeTempCreationPending, ereport, errcode(), errmsg(), ERROR, fb(), get_database_name(), get_namespace_oid(), MyDatabaseId, myTempNamespace, OidIsValid, and recomputeNamespacePath().

Referenced by CreateTableAsRelExists(), generateSerialExtraStmts(), RangeVarGetAndCheckCreationNamespace(), and transformPartitionCmdForSplit().

◆ RangeVarGetRelidExtended()

Oid RangeVarGetRelidExtended ( const RangeVar relation,
LOCKMODE  lockmode,
uint32  flags,
RangeVarGetRelidCallback  callback,
void callback_arg 
)
extern

Definition at line 440 of file namespace.c.

443{
445 Oid relId;
447 bool retry = false;
448 bool missing_ok = (flags & RVR_MISSING_OK) != 0;
449
450 /* verify that flags do no conflict */
451 Assert(!((flags & RVR_NOWAIT) && (flags & RVR_SKIP_LOCKED)));
452
453 /*
454 * We check the catalog name and then ignore it.
455 */
456 if (relation->catalogname)
457 {
458 if (strcmp(relation->catalogname, get_database_name(MyDatabaseId)) != 0)
461 errmsg("cross-database references are not implemented: \"%s.%s.%s\"",
462 relation->catalogname, relation->schemaname,
463 relation->relname)));
464 }
465
466 /*
467 * DDL operations can change the results of a name lookup. Since all such
468 * operations will generate invalidation messages, we keep track of
469 * whether any such messages show up while we're performing the operation,
470 * and retry until either (1) no more invalidation messages show up or (2)
471 * the answer doesn't change.
472 *
473 * But if lockmode = NoLock, then we assume that either the caller is OK
474 * with the answer changing under them, or that they already hold some
475 * appropriate lock, and therefore return the first answer we get without
476 * checking for invalidation messages. Also, if the requested lock is
477 * already held, LockRelationOid will not AcceptInvalidationMessages, so
478 * we may fail to notice a change. We could protect against that case by
479 * calling AcceptInvalidationMessages() before beginning this loop, but
480 * that would add a significant amount overhead, so for now we don't.
481 */
482 for (;;)
483 {
484 /*
485 * Remember this value, so that, after looking up the relation name
486 * and locking its OID, we can check whether any invalidation messages
487 * have been processed that might require a do-over.
488 */
490
491 /*
492 * Some non-default relpersistence value may have been specified. The
493 * parser never generates such a RangeVar in simple DML, but it can
494 * happen in contexts such as "CREATE TEMP TABLE foo (f1 int PRIMARY
495 * KEY)". Such a command will generate an added CREATE INDEX
496 * operation, which must be careful to find the temp table, even when
497 * pg_temp is not first in the search path.
498 */
499 if (relation->relpersistence == RELPERSISTENCE_TEMP)
500 {
502 relId = InvalidOid; /* this probably can't happen? */
503 else
504 {
505 if (relation->schemaname)
506 {
508
509 namespaceId = LookupExplicitNamespace(relation->schemaname, missing_ok);
510
511 /*
512 * For missing_ok, allow a non-existent schema name to
513 * return InvalidOid.
514 */
518 errmsg("temporary tables cannot specify a schema name")));
519 }
520
521 relId = get_relname_relid(relation->relname, myTempNamespace);
522 }
523 }
524 else if (relation->schemaname)
525 {
527
528 /* use exact schema given */
529 namespaceId = LookupExplicitNamespace(relation->schemaname, missing_ok);
530 if (missing_ok && !OidIsValid(namespaceId))
531 relId = InvalidOid;
532 else
533 relId = get_relname_relid(relation->relname, namespaceId);
534 }
535 else
536 {
537 /* search the namespace path */
538 relId = RelnameGetRelid(relation->relname);
539 }
540
541 /*
542 * Invoke caller-supplied callback, if any.
543 *
544 * This callback is a good place to check permissions: we haven't
545 * taken the table lock yet (and it's really best to check permissions
546 * before locking anything!), but we've gotten far enough to know what
547 * OID we think we should lock. Of course, concurrent DDL might
548 * change things while we're waiting for the lock, but in that case
549 * the callback will be invoked again for the new OID.
550 */
551 if (callback)
552 callback(relation, relId, oldRelId, callback_arg);
553
554 /*
555 * If no lock requested, we assume the caller knows what they're
556 * doing. They should have already acquired a heavyweight lock on
557 * this relation earlier in the processing of this same statement, so
558 * it wouldn't be appropriate to AcceptInvalidationMessages() here, as
559 * that might pull the rug out from under them.
560 */
561 if (lockmode == NoLock)
562 break;
563
564 /*
565 * If, upon retry, we get back the same OID we did last time, then the
566 * invalidation messages we processed did not change the final answer.
567 * So we're done.
568 *
569 * If we got a different OID, we've locked the relation that used to
570 * have this name rather than the one that does now. So release the
571 * lock.
572 */
573 if (retry)
574 {
575 if (relId == oldRelId)
576 break;
577 if (OidIsValid(oldRelId))
578 UnlockRelationOid(oldRelId, lockmode);
579 }
580
581 /*
582 * Lock relation. This will also accept any pending invalidation
583 * messages. If we got back InvalidOid, indicating not found, then
584 * there's nothing to lock, but we accept invalidation messages
585 * anyway, to flush any negative catcache entries that may be
586 * lingering.
587 */
588 if (!OidIsValid(relId))
590 else if (!(flags & (RVR_NOWAIT | RVR_SKIP_LOCKED)))
591 LockRelationOid(relId, lockmode);
592 else if (!ConditionalLockRelationOid(relId, lockmode))
593 {
594 int elevel = (flags & RVR_SKIP_LOCKED) ? DEBUG1 : ERROR;
595
596 if (relation->schemaname)
597 ereport(elevel,
599 errmsg("could not obtain lock on relation \"%s.%s\"",
600 relation->schemaname, relation->relname)));
601 else
602 ereport(elevel,
604 errmsg("could not obtain lock on relation \"%s\"",
605 relation->relname)));
606
607 return InvalidOid;
608 }
609
610 /*
611 * If no invalidation message were processed, we're done!
612 */
614 break;
615
616 /*
617 * Something may have changed. Let's repeat the name lookup, to make
618 * sure this name still references the same relation it did
619 * previously.
620 */
621 retry = true;
622 oldRelId = relId;
623 }
624
625 if (!OidIsValid(relId))
626 {
627 int elevel = missing_ok ? DEBUG1 : ERROR;
628
629 if (relation->schemaname)
630 ereport(elevel,
632 errmsg("relation \"%s.%s\" does not exist",
633 relation->schemaname, relation->relname)));
634 else
635 ereport(elevel,
637 errmsg("relation \"%s\" does not exist",
638 relation->relname)));
639 }
640 return relId;
641}
#define DEBUG1
Definition elog.h:30
void AcceptInvalidationMessages(void)
Definition inval.c:930
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
Definition lmgr.c:151
Oid RelnameGetRelid(const char *relname)
Definition namespace.c:884
#define ERRCODE_UNDEFINED_TABLE
Definition pgbench.c:79
char relpersistence
Definition primnodes.h:89
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)

References AcceptInvalidationMessages(), Assert, callback(), RangeVar::catalogname, ConditionalLockRelationOid(), DEBUG1, ereport, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), ERROR, fb(), get_database_name(), get_relname_relid(), InvalidOid, LockRelationOid(), LookupExplicitNamespace(), MyDatabaseId, myTempNamespace, NoLock, OidIsValid, RangeVar::relname, RelnameGetRelid(), RangeVar::relpersistence, RVR_MISSING_OK, RVR_NOWAIT, RVR_SKIP_LOCKED, RangeVar::schemaname, SharedInvalidMessageCounter, and UnlockRelationOid().

Referenced by AlterPolicy(), AlterSequence(), AlterTableLookupRelation(), AlterTableNamespace(), ATExecAttachPartitionIdx(), attribute_statistics_update(), cluster(), CreatePolicy(), ExecRefreshMatView(), ExecuteTruncate(), expand_vacuum_rel(), extended_statistics_update(), get_rel_from_relname(), LockTableCommand(), pg_clear_attribute_stats(), pg_clear_extended_stats(), ProcessUtilitySlow(), ReindexIndex(), ReindexTable(), relation_statistics_update(), RemoveRelations(), rename_policy(), renameatt(), RenameConstraint(), RenameRelation(), RenameRewriteRule(), renametrig(), transformPartitionCmdForMerge(), and transformPartitionCmdForSplit().

◆ RelationIsVisible()

bool RelationIsVisible ( Oid  relid)
extern

Definition at line 912 of file namespace.c.

913{
914 return RelationIsVisibleExt(relid, NULL);
915}
static bool RelationIsVisibleExt(Oid relid, bool *is_missing)
Definition namespace.c:924

References fb(), and RelationIsVisibleExt().

Referenced by generate_relation_name(), generate_relation_name(), getRelationDescription(), and regclassout().

◆ RelnameGetRelid()

Oid RelnameGetRelid ( const char relname)
extern

Definition at line 884 of file namespace.c.

885{
886 Oid relid;
887 ListCell *l;
888
890
891 foreach(l, activeSearchPath)
892 {
894
896 if (OidIsValid(relid))
897 return relid;
898 }
899
900 /* Not found in path */
901 return InvalidOid;
902}
NameData relname
Definition pg_class.h:38

References activeSearchPath, fb(), get_relname_relid(), InvalidOid, lfirst_oid, OidIsValid, recomputeNamespacePath(), and relname.

Referenced by plpgsql_parse_wordrowtype(), and RangeVarGetRelidExtended().

◆ ResetTempTableNamespace()

void ResetTempTableNamespace ( void  )
extern

Definition at line 4714 of file namespace.c.

4715{
4718}
static void RemoveTempRelations(Oid tempNamespaceId)
Definition namespace.c:4668

References myTempNamespace, OidIsValid, and RemoveTempRelations().

Referenced by DiscardAll(), and DiscardCommand().

◆ SearchPathMatchesCurrentEnvironment()

bool SearchPathMatchesCurrentEnvironment ( SearchPathMatcher path)
extern

Definition at line 3981 of file namespace.c.

3982{
3983 ListCell *lc,
3984 *lcp;
3985
3987
3988 /* Quick out if already known equal to active path. */
3989 if (path->generation == activePathGeneration)
3990 return true;
3991
3992 /* We scan down the activeSearchPath to see if it matches the input. */
3994
3995 /* If path->addTemp, first item should be my temp namespace. */
3996 if (path->addTemp)
3997 {
3998 if (lc && lfirst_oid(lc) == myTempNamespace)
4000 else
4001 return false;
4002 }
4003 /* If path->addCatalog, next item should be pg_catalog. */
4004 if (path->addCatalog)
4005 {
4008 else
4009 return false;
4010 }
4011 /* We should now be looking at the activeCreationNamespace. */
4013 return false;
4014 /* The remainder of activeSearchPath should match path->schemas. */
4015 foreach(lcp, path->schemas)
4016 {
4017 if (lc && lfirst_oid(lc) == lfirst_oid(lcp))
4019 else
4020 return false;
4021 }
4022 if (lc)
4023 return false;
4024
4025 /*
4026 * Update path->generation so that future tests will return quickly, so
4027 * long as the active search path doesn't change.
4028 */
4030
4031 return true;
4032}
#define false
static ListCell * lnext(const List *l, const ListCell *c)
Definition pg_list.h:343

References activeCreationNamespace, activePathGeneration, activeSearchPath, SearchPathMatcher::addCatalog, SearchPathMatcher::addTemp, fb(), SearchPathMatcher::generation, InvalidOid, lfirst_oid, list_head(), lnext(), myTempNamespace, recomputeNamespacePath(), and SearchPathMatcher::schemas.

Referenced by CachedPlanAllowsSimpleValidityCheck(), CachedPlanIsSimplyValid(), and RevalidateCachedQuery().

◆ SetTempNamespaceState()

void SetTempNamespaceState ( Oid  tempNamespaceId,
Oid  tempToastNamespaceId 
)
extern

Definition at line 3891 of file namespace.c.

3892{
3893 /* Worker should not have created its own namespaces ... */
3897
3898 /* Assign same namespace OIDs that leader has */
3899 myTempNamespace = tempNamespaceId;
3901
3902 /*
3903 * It's fine to leave myTempNamespaceSubID == InvalidSubTransactionId.
3904 * Even if the namespace is new so far as the leader is concerned, it's
3905 * not new to the worker, and we certainly wouldn't want the worker trying
3906 * to destroy it.
3907 */
3908
3909 baseSearchPathValid = false; /* may need to rebuild list */
3910 searchPathCacheValid = false;
3911}

References Assert, baseSearchPathValid, fb(), InvalidOid, InvalidSubTransactionId, myTempNamespace, myTempNamespaceSubID, myTempToastNamespace, and searchPathCacheValid.

Referenced by ParallelWorkerMain().

◆ StatisticsObjIsVisible()

bool StatisticsObjIsVisible ( Oid  stxid)
extern

Definition at line 2699 of file namespace.c.

2700{
2702}
static bool StatisticsObjIsVisibleExt(Oid stxid, bool *is_missing)
Definition namespace.c:2711

References fb(), and StatisticsObjIsVisibleExt().

Referenced by getObjectDescription().

◆ TSConfigIsVisible()

bool TSConfigIsVisible ( Oid  cfgid)
extern

Definition at line 3280 of file namespace.c.

3281{
3283}
static bool TSConfigIsVisibleExt(Oid cfgid, bool *is_missing)
Definition namespace.c:3292

References fb(), and TSConfigIsVisibleExt().

Referenced by getObjectDescription(), and regconfigout().

◆ TSDictionaryIsVisible()

bool TSDictionaryIsVisible ( Oid  dictId)
extern

Definition at line 2989 of file namespace.c.

2990{
2991 return TSDictionaryIsVisibleExt(dictId, NULL);
2992}
static bool TSDictionaryIsVisibleExt(Oid dictId, bool *is_missing)
Definition namespace.c:3001

References fb(), and TSDictionaryIsVisibleExt().

Referenced by getObjectDescription(), and regdictionaryout().

◆ TSParserIsVisible()

bool TSParserIsVisible ( Oid  prsId)
extern

Definition at line 2844 of file namespace.c.

2845{
2846 return TSParserIsVisibleExt(prsId, NULL);
2847}
static bool TSParserIsVisibleExt(Oid prsId, bool *is_missing)
Definition namespace.c:2856

References fb(), and TSParserIsVisibleExt().

Referenced by getObjectDescription().

◆ TSTemplateIsVisible()

bool TSTemplateIsVisible ( Oid  tmplId)
extern

Definition at line 3135 of file namespace.c.

3136{
3138}
static bool TSTemplateIsVisibleExt(Oid tmplId, bool *is_missing)
Definition namespace.c:3147

References fb(), and TSTemplateIsVisibleExt().

Referenced by getObjectDescription().

◆ TypeIsVisible()

bool TypeIsVisible ( Oid  typid)
extern

Definition at line 1039 of file namespace.c.

1040{
1041 return TypeIsVisibleExt(typid, NULL);
1042}
static bool TypeIsVisibleExt(Oid typid, bool *is_missing)
Definition namespace.c:1051

References fb(), and TypeIsVisibleExt().

Referenced by format_type_extended().

◆ TypenameGetTypid()

Oid TypenameGetTypid ( const char typname)
extern

Definition at line 994 of file namespace.c.

995{
996 return TypenameGetTypidExtended(typname, true);
997}
Oid TypenameGetTypidExtended(const char *typname, bool temp_ok)
Definition namespace.c:1007
NameData typname
Definition pg_type.h:41

References TypenameGetTypidExtended(), and typname.

◆ TypenameGetTypidExtended()

Oid TypenameGetTypidExtended ( const char typname,
bool  temp_ok 
)
extern

Definition at line 1007 of file namespace.c.

1008{
1009 Oid typid;
1010 ListCell *l;
1011
1013
1014 foreach(l, activeSearchPath)
1015 {
1017
1019 continue; /* do not look in temp namespace */
1020
1024 if (OidIsValid(typid))
1025 return typid;
1026 }
1027
1028 /* Not found in path */
1029 return InvalidOid;
1030}

References activeSearchPath, fb(), GetSysCacheOid2, InvalidOid, lfirst_oid, myTempNamespace, ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), recomputeNamespacePath(), and typname.

Referenced by LookupTypeNameExtended(), and TypenameGetTypid().

Variable Documentation

◆ namespace_search_path

PGDLLIMPORT char* namespace_search_path
extern

Definition at line 210 of file namespace.c.

Referenced by CreateSchemaCommand(), and recomputeNamespacePath().