mirror of
https://github.com/postgres/postgres.git
synced 2025-09-05 02:22:28 +03:00
Eliminate cache lookup errors in SQL functions for object addresses
When using the following functions, users could see various types of errors of the type "cache lookup failed for OID XXX" with elog(), that can only be used for internal errors: * pg_describe_object() * pg_identify_object() * pg_identify_object_as_address() The set of APIs managing object addresses for all object types are made smarter by gaining a new argument "missing_ok" that allows any caller to control if an error is raised or not on an undefined object. The SQL functions listed above are changed to handle the case where an object is missing. Regression tests are added for all object types for the cases where these are undefined. Before this commit, these cases failed with cache lookup errors, and now they basically return NULL (minus the name of the object type requested). Author: Michael Paquier Reviewed-by: Aleksander Alekseev, Dmitry Dolgov, Daniel Gustafsson, Álvaro Herrera, Kyotaro Horiguchi Discussion: https://postgr.es/m/CAB7nPqSZxrSmdHK-rny7z8mi=EAFXJ5J-0RbzDw6aus=wB5azQ@mail.gmail.com
This commit is contained in:
@@ -1267,10 +1267,11 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
|
||||
|
||||
/* object identity, objname and objargs */
|
||||
obj->objidentity =
|
||||
getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs);
|
||||
getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs,
|
||||
false);
|
||||
|
||||
/* object type */
|
||||
obj->objecttype = getObjectTypeDescription(&obj->address);
|
||||
obj->objecttype = getObjectTypeDescription(&obj->address, false);
|
||||
|
||||
slist_push_head(&(currentEventTriggerState->SQLDropList), &obj->next);
|
||||
|
||||
@@ -1929,8 +1930,8 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
|
||||
else if (cmd->type == SCT_AlterTSConfig)
|
||||
addr = cmd->d.atscfg.address;
|
||||
|
||||
type = getObjectTypeDescription(&addr);
|
||||
identity = getObjectIdentity(&addr);
|
||||
type = getObjectTypeDescription(&addr, false);
|
||||
identity = getObjectIdentity(&addr, false);
|
||||
|
||||
/*
|
||||
* Obtain schema name, if any ("pg_temp" if a temp
|
||||
|
@@ -2919,7 +2919,7 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
|
||||
errmsg("extension \"%s\" does not support SET SCHEMA",
|
||||
NameStr(extForm->extname)),
|
||||
errdetail("%s is not in the extension's schema \"%s\"",
|
||||
getObjectDescription(&dep),
|
||||
getObjectDescription(&dep, false),
|
||||
get_namespace_name(oldNspOid))));
|
||||
}
|
||||
|
||||
@@ -3328,7 +3328,7 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt,
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("%s is already a member of extension \"%s\"",
|
||||
getObjectDescription(&object),
|
||||
getObjectDescription(&object, false),
|
||||
get_extension_name(oldExtension))));
|
||||
|
||||
/*
|
||||
@@ -3368,7 +3368,7 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt,
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("%s is not a member of extension \"%s\"",
|
||||
getObjectDescription(&object),
|
||||
getObjectDescription(&object, false),
|
||||
stmt->extname)));
|
||||
|
||||
/*
|
||||
|
@@ -11304,7 +11304,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
|
||||
{
|
||||
/* Not expecting any other direct dependencies... */
|
||||
elog(ERROR, "unexpected object depending on column: %s",
|
||||
getObjectDescription(&foundObject));
|
||||
getObjectDescription(&foundObject, false));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -11320,7 +11320,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot alter type of a column used by a view or rule"),
|
||||
errdetail("%s depends on column \"%s\"",
|
||||
getObjectDescription(&foundObject),
|
||||
getObjectDescription(&foundObject, false),
|
||||
colName)));
|
||||
break;
|
||||
|
||||
@@ -11339,7 +11339,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot alter type of a column used in a trigger definition"),
|
||||
errdetail("%s depends on column \"%s\"",
|
||||
getObjectDescription(&foundObject),
|
||||
getObjectDescription(&foundObject, false),
|
||||
colName)));
|
||||
break;
|
||||
|
||||
@@ -11357,7 +11357,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot alter type of a column used in a policy definition"),
|
||||
errdetail("%s depends on column \"%s\"",
|
||||
getObjectDescription(&foundObject),
|
||||
getObjectDescription(&foundObject, false),
|
||||
colName)));
|
||||
break;
|
||||
|
||||
@@ -11418,7 +11418,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
|
||||
* a column.
|
||||
*/
|
||||
elog(ERROR, "unexpected object depending on column: %s",
|
||||
getObjectDescription(&foundObject));
|
||||
getObjectDescription(&foundObject, false));
|
||||
break;
|
||||
|
||||
/*
|
||||
@@ -11474,7 +11474,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
|
||||
foundDep->refobjsubid != 0)
|
||||
)
|
||||
elog(ERROR, "found unexpected dependency for column: %s",
|
||||
getObjectDescription(&foundObject));
|
||||
getObjectDescription(&foundObject, false));
|
||||
|
||||
CatalogTupleDelete(depRel, &depTup->t_self);
|
||||
}
|
||||
|
Reference in New Issue
Block a user