mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
Silently ignore any nonexistent schemas that are listed in search_path.
Previously we attempted to throw an error or at least warning for missing schemas, but this was done inconsistently because of implementation restrictions (in many cases, GUC settings are applied outside transactions so that we can't do system catalog lookups). Furthermore, there were exceptions to the rule even in the beginning, and we'd been poking more and more holes in it as time went on, because it turns out that there are lots of use-cases for having some irrelevant items in a common search_path value. It seems better to just adopt a philosophy similar to what's always been done with Unix PATH settings, wherein nonexistent or unreadable directories are silently ignored. This commit also fixes the documentation to point out that schemas for which the user lacks USAGE privilege are silently ignored. That's always been true but was previously not documented. This is mostly in response to Robert Haas' complaint that 9.1 started to throw errors or warnings for missing schemas in cases where prior releases had not. We won't adopt such a significant behavioral change in a back branch, so something different will be needed in 9.1.
This commit is contained in:
@@ -3773,14 +3773,12 @@ ResetTempTableNamespace(void)
|
||||
* Routines for handling the GUC variable 'search_path'.
|
||||
*/
|
||||
|
||||
/* check_hook: validate new search_path, if possible */
|
||||
/* check_hook: validate new search_path value */
|
||||
bool
|
||||
check_search_path(char **newval, void **extra, GucSource source)
|
||||
{
|
||||
bool result = true;
|
||||
char *rawname;
|
||||
List *namelist;
|
||||
ListCell *l;
|
||||
|
||||
/* Need a modifiable copy of string */
|
||||
rawname = pstrdup(*newval);
|
||||
@@ -3796,52 +3794,17 @@ check_search_path(char **newval, void **extra, GucSource source)
|
||||
}
|
||||
|
||||
/*
|
||||
* If we aren't inside a transaction, we cannot do database access so
|
||||
* cannot verify the individual names. Must accept the list on faith.
|
||||
* We used to try to check that the named schemas exist, but there are
|
||||
* many valid use-cases for having search_path settings that include
|
||||
* schemas that don't exist; and often, we are not inside a transaction
|
||||
* here and so can't consult the system catalogs anyway. So now, the only
|
||||
* requirement is syntactic validity of the identifier list.
|
||||
*/
|
||||
if (IsTransactionState())
|
||||
{
|
||||
/*
|
||||
* Verify that all the names are either valid namespace names or
|
||||
* "$user" or "pg_temp". We do not require $user to correspond to a
|
||||
* valid namespace, and pg_temp might not exist yet. We do not check
|
||||
* for USAGE rights, either; should we?
|
||||
*
|
||||
* When source == PGC_S_TEST, we are checking the argument of an ALTER
|
||||
* DATABASE SET or ALTER USER SET command. It could be that the
|
||||
* intended use of the search path is for some other database, so we
|
||||
* should not error out if it mentions schemas not present in the
|
||||
* current database. We issue a NOTICE instead.
|
||||
*/
|
||||
foreach(l, namelist)
|
||||
{
|
||||
char *curname = (char *) lfirst(l);
|
||||
|
||||
if (strcmp(curname, "$user") == 0)
|
||||
continue;
|
||||
if (strcmp(curname, "pg_temp") == 0)
|
||||
continue;
|
||||
if (!SearchSysCacheExists1(NAMESPACENAME,
|
||||
CStringGetDatum(curname)))
|
||||
{
|
||||
if (source == PGC_S_TEST)
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_UNDEFINED_SCHEMA),
|
||||
errmsg("schema \"%s\" does not exist", curname)));
|
||||
else
|
||||
{
|
||||
GUC_check_errdetail("schema \"%s\" does not exist", curname);
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pfree(rawname);
|
||||
list_free(namelist);
|
||||
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* assign_hook: do extra actions as needed */
|
||||
|
||||
Reference in New Issue
Block a user