PostgreSQL Source Code  git master
objectaddress.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/relation.h"
#include "access/sysattr.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/indexing.h"
#include "catalog/objectaddress.h"
#include "catalog/pg_am.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_attrdef.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_cast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_database.h"
#include "catalog/pg_default_acl.h"
#include "catalog/pg_enum.h"
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_extension.h"
#include "catalog/pg_foreign_data_wrapper.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_language.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_policy.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_publication.h"
#include "catalog/pg_publication_rel.h"
#include "catalog/pg_rewrite.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_ts_parser.h"
#include "catalog/pg_ts_template.h"
#include "catalog/pg_type.h"
#include "catalog/pg_user_mapping.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/event_trigger.h"
#include "commands/extension.h"
#include "commands/policy.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_type.h"
#include "rewrite/rewriteSupport.h"
#include "storage/large_object.h"
#include "storage/lmgr.h"
#include "storage/sinval.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/regproc.h"
#include "utils/syscache.h"
Include dependency graph for objectaddress.c:

Go to the source code of this file.

Data Structures

struct  ObjectPropertyType
 
struct  object_type_map
 

Functions

static ObjectAddress get_object_address_unqualified (ObjectType objtype, Value *strval, bool missing_ok)
 
static ObjectAddress get_relation_by_qualified_name (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_relobject (ObjectType objtype, List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_attribute (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_attrdef (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_type (ObjectType objtype, TypeName *typename, bool missing_ok)
 
static ObjectAddress get_object_address_opcf (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_opf_member (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_usermapping (List *object, bool missing_ok)
 
static ObjectAddress get_object_address_publication_rel (List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_defacl (List *object, bool missing_ok)
 
static const ObjectPropertyTypeget_object_property_data (Oid class_id)
 
static void getRelationDescription (StringInfo buffer, Oid relid)
 
static void getOpFamilyDescription (StringInfo buffer, Oid opfid)
 
static void getRelationTypeDescription (StringInfo buffer, Oid relid, int32 objectSubId)
 
static void getProcedureTypeDescription (StringInfo buffer, Oid procid)
 
static void getConstraintTypeDescription (StringInfo buffer, Oid constroid)
 
static void getOpFamilyIdentity (StringInfo buffer, Oid opfid, List **object)
 
static void getRelationIdentity (StringInfo buffer, Oid relid, List **object)
 
ObjectAddress get_object_address (ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static Listtextarray_to_strvaluelist (ArrayType *arr)
 
Datum pg_get_object_address (PG_FUNCTION_ARGS)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
int read_objtype_from_string (const char *objtype)
 
Oid get_object_oid_index (Oid class_id)
 
int get_object_catcache_oid (Oid class_id)
 
int get_object_catcache_name (Oid class_id)
 
AttrNumber get_object_attnum_oid (Oid class_id)
 
AttrNumber get_object_attnum_name (Oid class_id)
 
AttrNumber get_object_attnum_namespace (Oid class_id)
 
AttrNumber get_object_attnum_owner (Oid class_id)
 
AttrNumber get_object_attnum_acl (Oid class_id)
 
ObjectType get_object_type (Oid class_id, Oid object_id)
 
bool get_object_namensp_unique (Oid class_id)
 
bool is_objectclass_supported (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, AttrNumber oidcol, Oid objectId)
 
char * getObjectDescription (const ObjectAddress *object)
 
char * getObjectDescriptionOids (Oid classid, Oid objid)
 
Datum pg_describe_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object_as_address (PG_FUNCTION_ARGS)
 
char * getObjectTypeDescription (const ObjectAddress *object)
 
char * getObjectIdentity (const ObjectAddress *object)
 
char * getObjectIdentityParts (const ObjectAddress *object, List **objname, List **objargs)
 
ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

static const ObjectPropertyType ObjectProperty []
 
static const struct object_type_map ObjectTypeMap []
 
const ObjectAddress InvalidObjectAddress
 

Function Documentation

◆ check_object_ownership()

void check_object_ownership ( Oid  roleid,
ObjectType  objtype,
ObjectAddress  address,
Node object,
Relation  relation 
)

Definition at line 2271 of file objectaddress.c.

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, CONSTROID, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), GETSTRUCT, has_createrole_privilege(), HeapTupleIsValid, linitial_node, lo_compat_privileges, lsecond_node, NameListToString(), OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ObjectAddress::objectId, ObjectIdGetDatum, pg_class_ownercheck(), pg_collation_ownercheck(), pg_conversion_ownercheck(), pg_database_ownercheck(), pg_event_trigger_ownercheck(), pg_extension_ownercheck(), pg_foreign_data_wrapper_ownercheck(), pg_foreign_server_ownercheck(), pg_language_ownercheck(), pg_largeobject_ownercheck(), pg_namespace_ownercheck(), pg_opclass_ownercheck(), pg_oper_ownercheck(), pg_opfamily_ownercheck(), pg_proc_ownercheck(), pg_publication_ownercheck(), pg_statistics_object_ownercheck(), pg_subscription_ownercheck(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_ownercheck(), RelationGetRelationName, RelationGetRelid, ReleaseSysCache(), SearchSysCache1(), strVal, superuser_arg(), and typenameTypeId().

Referenced by CommentObject(), ExecAlterExtensionContentsStmt(), ExecAlterObjectDependsStmt(), ExecSecLabelStmt(), and RemoveObjects().

2273 {
2274  switch (objtype)
2275  {
2276  case OBJECT_INDEX:
2277  case OBJECT_SEQUENCE:
2278  case OBJECT_TABLE:
2279  case OBJECT_VIEW:
2280  case OBJECT_MATVIEW:
2281  case OBJECT_FOREIGN_TABLE:
2282  case OBJECT_COLUMN:
2283  case OBJECT_RULE:
2284  case OBJECT_TRIGGER:
2285  case OBJECT_POLICY:
2286  case OBJECT_TABCONSTRAINT:
2287  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2289  RelationGetRelationName(relation));
2290  break;
2291  case OBJECT_DATABASE:
2292  if (!pg_database_ownercheck(address.objectId, roleid))
2294  strVal((Value *) object));
2295  break;
2296  case OBJECT_TYPE:
2297  case OBJECT_DOMAIN:
2298  case OBJECT_ATTRIBUTE:
2299  if (!pg_type_ownercheck(address.objectId, roleid))
2301  break;
2302  case OBJECT_DOMCONSTRAINT:
2303  {
2304  HeapTuple tuple;
2305  Oid contypid;
2306 
2307  tuple = SearchSysCache1(CONSTROID,
2308  ObjectIdGetDatum(address.objectId));
2309  if (!HeapTupleIsValid(tuple))
2310  elog(ERROR, "constraint with OID %u does not exist",
2311  address.objectId);
2312 
2313  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2314 
2315  ReleaseSysCache(tuple);
2316 
2317  /*
2318  * Fallback to type ownership check in this case as this is
2319  * what domain constraints rely on.
2320  */
2321  if (!pg_type_ownercheck(contypid, roleid))
2323  }
2324  break;
2325  case OBJECT_AGGREGATE:
2326  case OBJECT_FUNCTION:
2327  case OBJECT_PROCEDURE:
2328  case OBJECT_ROUTINE:
2329  if (!pg_proc_ownercheck(address.objectId, roleid))
2331  NameListToString((castNode(ObjectWithArgs, object))->objname));
2332  break;
2333  case OBJECT_OPERATOR:
2334  if (!pg_oper_ownercheck(address.objectId, roleid))
2336  NameListToString((castNode(ObjectWithArgs, object))->objname));
2337  break;
2338  case OBJECT_SCHEMA:
2339  if (!pg_namespace_ownercheck(address.objectId, roleid))
2341  strVal((Value *) object));
2342  break;
2343  case OBJECT_COLLATION:
2344  if (!pg_collation_ownercheck(address.objectId, roleid))
2346  NameListToString(castNode(List, object)));
2347  break;
2348  case OBJECT_CONVERSION:
2349  if (!pg_conversion_ownercheck(address.objectId, roleid))
2351  NameListToString(castNode(List, object)));
2352  break;
2353  case OBJECT_EXTENSION:
2354  if (!pg_extension_ownercheck(address.objectId, roleid))
2356  strVal((Value *) object));
2357  break;
2358  case OBJECT_FDW:
2359  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2361  strVal((Value *) object));
2362  break;
2363  case OBJECT_FOREIGN_SERVER:
2364  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2366  strVal((Value *) object));
2367  break;
2368  case OBJECT_EVENT_TRIGGER:
2369  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2371  strVal((Value *) object));
2372  break;
2373  case OBJECT_LANGUAGE:
2374  if (!pg_language_ownercheck(address.objectId, roleid))
2376  strVal((Value *) object));
2377  break;
2378  case OBJECT_OPCLASS:
2379  if (!pg_opclass_ownercheck(address.objectId, roleid))
2381  NameListToString(castNode(List, object)));
2382  break;
2383  case OBJECT_OPFAMILY:
2384  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2386  NameListToString(castNode(List, object)));
2387  break;
2388  case OBJECT_LARGEOBJECT:
2389  if (!lo_compat_privileges &&
2390  !pg_largeobject_ownercheck(address.objectId, roleid))
2391  ereport(ERROR,
2392  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2393  errmsg("must be owner of large object %u",
2394  address.objectId)));
2395  break;
2396  case OBJECT_CAST:
2397  {
2398  /* We can only check permissions on the source/target types */
2399  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2400  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2401  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2402  Oid targettypeid = typenameTypeId(NULL, targettype);
2403 
2404  if (!pg_type_ownercheck(sourcetypeid, roleid)
2405  && !pg_type_ownercheck(targettypeid, roleid))
2406  ereport(ERROR,
2407  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2408  errmsg("must be owner of type %s or type %s",
2409  format_type_be(sourcetypeid),
2410  format_type_be(targettypeid))));
2411  }
2412  break;
2413  case OBJECT_PUBLICATION:
2414  if (!pg_publication_ownercheck(address.objectId, roleid))
2416  strVal((Value *) object));
2417  break;
2418  case OBJECT_SUBSCRIPTION:
2419  if (!pg_subscription_ownercheck(address.objectId, roleid))
2421  strVal((Value *) object));
2422  break;
2423  case OBJECT_TRANSFORM:
2424  {
2425  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2426  Oid typeid = typenameTypeId(NULL, typename);
2427 
2428  if (!pg_type_ownercheck(typeid, roleid))
2430  }
2431  break;
2432  case OBJECT_TABLESPACE:
2433  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2435  strVal((Value *) object));
2436  break;
2437  case OBJECT_TSDICTIONARY:
2438  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2440  NameListToString(castNode(List, object)));
2441  break;
2443  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2445  NameListToString(castNode(List, object)));
2446  break;
2447  case OBJECT_ROLE:
2448 
2449  /*
2450  * We treat roles as being "owned" by those with CREATEROLE priv,
2451  * except that superusers are only owned by superusers.
2452  */
2453  if (superuser_arg(address.objectId))
2454  {
2455  if (!superuser_arg(roleid))
2456  ereport(ERROR,
2457  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2458  errmsg("must be superuser")));
2459  }
2460  else
2461  {
2462  if (!has_createrole_privilege(roleid))
2463  ereport(ERROR,
2464  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2465  errmsg("must have CREATEROLE privilege")));
2466  }
2467  break;
2468  case OBJECT_TSPARSER:
2469  case OBJECT_TSTEMPLATE:
2470  case OBJECT_ACCESS_METHOD:
2471  /* We treat these object types as being owned by superusers */
2472  if (!superuser_arg(roleid))
2473  ereport(ERROR,
2474  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2475  errmsg("must be superuser")));
2476  break;
2477  case OBJECT_STATISTIC_EXT:
2478  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2480  break;
2481  default:
2482  elog(ERROR, "unrecognized object type: %d",
2483  (int) objtype);
2484  }
2485 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5378
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5197
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
bool lo_compat_privileges
Definition: inv_api.c:58
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4886
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:5036
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4857
#define castNode(_type_, nodeptr)
Definition: nodes.h:595
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5063
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5117
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5291
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4805
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:327
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4929
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4779
#define linitial_node(type, l)
Definition: pg_list.h:198
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3665
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3352
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5144
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5249
#define RelationGetRelationName(relation)
Definition: rel.h:490
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4955
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:5009
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5171
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
char * NameListToString(List *names)
Definition: namespace.c:3102
#define lsecond_node(type, l)
Definition: pg_list.h:203
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4982
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5223
#define ereport(elevel,...)
Definition: elog.h:144
FormData_pg_constraint * Form_pg_constraint
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
Definition: value.h:42
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4753
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5090
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:456
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4831
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5317
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5343

◆ get_catalog_object_by_oid()

HeapTuple get_catalog_object_by_oid ( Relation  catalog,
AttrNumber  oidcol,
Oid  objectId 
)

Definition at line 2706 of file objectaddress.c.

References Assert, BTEqualStrategyNumber, get_object_catcache_oid(), get_object_oid_index(), heap_copytuple(), HeapTupleIsValid, ObjectIdGetDatum, OidIsValid, RelationGetRelid, ScanKeyInit(), SearchSysCacheCopy1, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AlterObjectOwner_internal(), EventTriggerSQLDropAddObject(), getConstraintTypeDescription(), getObjectIdentityParts(), pg_event_trigger_ddl_commands(), and pg_identify_object().

2707 {
2708  HeapTuple tuple;
2709  Oid classId = RelationGetRelid(catalog);
2710  int oidCacheId = get_object_catcache_oid(classId);
2711 
2712  if (oidCacheId > 0)
2713  {
2714  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2715  if (!HeapTupleIsValid(tuple)) /* should not happen */
2716  return NULL;
2717  }
2718  else
2719  {
2720  Oid oidIndexId = get_object_oid_index(classId);
2721  SysScanDesc scan;
2722  ScanKeyData skey;
2723 
2724  Assert(OidIsValid(oidIndexId));
2725 
2726  ScanKeyInit(&skey,
2727  oidcol,
2728  BTEqualStrategyNumber, F_OIDEQ,
2729  ObjectIdGetDatum(objectId));
2730 
2731  scan = systable_beginscan(catalog, oidIndexId, true,
2732  NULL, 1, &skey);
2733  tuple = systable_getnext(scan);
2734  if (!HeapTupleIsValid(tuple))
2735  {
2736  systable_endscan(scan);
2737  return NULL;
2738  }
2739  tuple = heap_copytuple(tuple);
2740 
2741  systable_endscan(scan);
2742  }
2743 
2744  return tuple;
2745 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:529
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:356
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:448
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:738
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:456
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ get_object_address()

ObjectAddress get_object_address ( ObjectType  objtype,
Node object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 834 of file objectaddress.c.

References Assert, castNode, ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, get_cast_oid(), get_collation_oid(), get_conversion_oid(), get_domain_constraint_oid(), get_language_oid(), get_object_address_attrdef(), get_object_address_attribute(), get_object_address_defacl(), get_object_address_opcf(), get_object_address_opf_member(), get_object_address_publication_rel(), get_object_address_relobject(), get_object_address_type(), get_object_address_unqualified(), get_object_address_usermapping(), get_relation_by_qualified_name(), get_statistics_object_oid(), get_transform_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), InvalidOid, IsSharedRelation(), LargeObjectExists(), linitial_node, LockDatabaseObject(), LockSharedObject(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, lsecond_node, NoLock, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, oidparse(), SharedInvalidMessageCounter, strVal, UnlockDatabaseObject(), and UnlockSharedObject().

Referenced by CommentObject(), ExecAlterExtensionContentsStmt(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecRenameStmt(), ExecSecLabelStmt(), get_object_address_rv(), pg_get_object_address(), and RemoveObjects().

836 {
837  ObjectAddress address;
838  ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
839  Relation relation = NULL;
840  uint64 inval_count;
841 
842  /* Some kind of lock must be taken. */
843  Assert(lockmode != NoLock);
844 
845  for (;;)
846  {
847  /*
848  * Remember this value, so that, after looking up the object name and
849  * locking it, we can check whether any invalidation messages have
850  * been processed that might require a do-over.
851  */
852  inval_count = SharedInvalidMessageCounter;
853 
854  /* Look up object address. */
855  switch (objtype)
856  {
857  case OBJECT_INDEX:
858  case OBJECT_SEQUENCE:
859  case OBJECT_TABLE:
860  case OBJECT_VIEW:
861  case OBJECT_MATVIEW:
863  address =
864  get_relation_by_qualified_name(objtype, castNode(List, object),
865  &relation, lockmode,
866  missing_ok);
867  break;
868  case OBJECT_COLUMN:
869  address =
870  get_object_address_attribute(objtype, castNode(List, object),
871  &relation, lockmode,
872  missing_ok);
873  break;
874  case OBJECT_DEFAULT:
875  address =
876  get_object_address_attrdef(objtype, castNode(List, object),
877  &relation, lockmode,
878  missing_ok);
879  break;
880  case OBJECT_RULE:
881  case OBJECT_TRIGGER:
883  case OBJECT_POLICY:
884  address = get_object_address_relobject(objtype, castNode(List, object),
885  &relation, missing_ok);
886  break;
888  {
889  List *objlist;
890  ObjectAddress domaddr;
891  char *constrname;
892 
893  objlist = castNode(List, object);
895  linitial_node(TypeName, objlist),
896  missing_ok);
897  constrname = strVal(lsecond(objlist));
898 
899  address.classId = ConstraintRelationId;
900  address.objectId = get_domain_constraint_oid(domaddr.objectId,
901  constrname, missing_ok);
902  address.objectSubId = 0;
903 
904  }
905  break;
906  case OBJECT_DATABASE:
907  case OBJECT_EXTENSION:
908  case OBJECT_TABLESPACE:
909  case OBJECT_ROLE:
910  case OBJECT_SCHEMA:
911  case OBJECT_LANGUAGE:
912  case OBJECT_FDW:
916  case OBJECT_PUBLICATION:
917  case OBJECT_SUBSCRIPTION:
918  address = get_object_address_unqualified(objtype,
919  (Value *) object, missing_ok);
920  break;
921  case OBJECT_TYPE:
922  case OBJECT_DOMAIN:
923  address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
924  break;
925  case OBJECT_AGGREGATE:
926  case OBJECT_FUNCTION:
927  case OBJECT_PROCEDURE:
928  case OBJECT_ROUTINE:
929  address.classId = ProcedureRelationId;
930  address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
931  address.objectSubId = 0;
932  break;
933  case OBJECT_OPERATOR:
934  address.classId = OperatorRelationId;
935  address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
936  address.objectSubId = 0;
937  break;
938  case OBJECT_COLLATION:
939  address.classId = CollationRelationId;
940  address.objectId = get_collation_oid(castNode(List, object), missing_ok);
941  address.objectSubId = 0;
942  break;
943  case OBJECT_CONVERSION:
944  address.classId = ConversionRelationId;
945  address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
946  address.objectSubId = 0;
947  break;
948  case OBJECT_OPCLASS:
949  case OBJECT_OPFAMILY:
950  address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
951  break;
952  case OBJECT_AMOP:
953  case OBJECT_AMPROC:
954  address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
955  break;
956  case OBJECT_LARGEOBJECT:
957  address.classId = LargeObjectRelationId;
958  address.objectId = oidparse(object);
959  address.objectSubId = 0;
960  if (!LargeObjectExists(address.objectId))
961  {
962  if (!missing_ok)
963  ereport(ERROR,
964  (errcode(ERRCODE_UNDEFINED_OBJECT),
965  errmsg("large object %u does not exist",
966  address.objectId)));
967  }
968  break;
969  case OBJECT_CAST:
970  {
971  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
972  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
973  Oid sourcetypeid;
974  Oid targettypeid;
975 
976  sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
977  targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
978  address.classId = CastRelationId;
979  address.objectId =
980  get_cast_oid(sourcetypeid, targettypeid, missing_ok);
981  address.objectSubId = 0;
982  }
983  break;
984  case OBJECT_TRANSFORM:
985  {
986  TypeName *typename = linitial_node(TypeName, castNode(List, object));
987  char *langname = strVal(lsecond(castNode(List, object)));
988  Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
989  Oid lang_id = get_language_oid(langname, missing_ok);
990 
991  address.classId = TransformRelationId;
992  address.objectId =
993  get_transform_oid(type_id, lang_id, missing_ok);
994  address.objectSubId = 0;
995  }
996  break;
997  case OBJECT_TSPARSER:
998  address.classId = TSParserRelationId;
999  address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
1000  address.objectSubId = 0;
1001  break;
1002  case OBJECT_TSDICTIONARY:
1003  address.classId = TSDictionaryRelationId;
1004  address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
1005  address.objectSubId = 0;
1006  break;
1007  case OBJECT_TSTEMPLATE:
1008  address.classId = TSTemplateRelationId;
1009  address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
1010  address.objectSubId = 0;
1011  break;
1013  address.classId = TSConfigRelationId;
1014  address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
1015  address.objectSubId = 0;
1016  break;
1017  case OBJECT_USER_MAPPING:
1018  address = get_object_address_usermapping(castNode(List, object),
1019  missing_ok);
1020  break;
1023  &relation,
1024  missing_ok);
1025  break;
1026  case OBJECT_DEFACL:
1027  address = get_object_address_defacl(castNode(List, object),
1028  missing_ok);
1029  break;
1030  case OBJECT_STATISTIC_EXT:
1031  address.classId = StatisticExtRelationId;
1032  address.objectId = get_statistics_object_oid(castNode(List, object),
1033  missing_ok);
1034  address.objectSubId = 0;
1035  break;
1036  default:
1037  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1038  /* placate compiler, in case it thinks elog might return */
1039  address.classId = InvalidOid;
1040  address.objectId = InvalidOid;
1041  address.objectSubId = 0;
1042  }
1043 
1044  /*
1045  * If we could not find the supplied object, return without locking.
1046  */
1047  if (!OidIsValid(address.objectId))
1048  {
1049  Assert(missing_ok);
1050  return address;
1051  }
1052 
1053  /*
1054  * If we're retrying, see if we got the same answer as last time. If
1055  * so, we're done; if not, we locked the wrong thing, so give up our
1056  * lock.
1057  */
1058  if (OidIsValid(old_address.classId))
1059  {
1060  if (old_address.classId == address.classId
1061  && old_address.objectId == address.objectId
1062  && old_address.objectSubId == address.objectSubId)
1063  break;
1064  if (old_address.classId != RelationRelationId)
1065  {
1066  if (IsSharedRelation(old_address.classId))
1067  UnlockSharedObject(old_address.classId,
1068  old_address.objectId,
1069  0, lockmode);
1070  else
1071  UnlockDatabaseObject(old_address.classId,
1072  old_address.objectId,
1073  0, lockmode);
1074  }
1075  }
1076 
1077  /*
1078  * If we're dealing with a relation or attribute, then the relation is
1079  * already locked. Otherwise, we lock it now.
1080  */
1081  if (address.classId != RelationRelationId)
1082  {
1083  if (IsSharedRelation(address.classId))
1084  LockSharedObject(address.classId, address.objectId, 0,
1085  lockmode);
1086  else
1087  LockDatabaseObject(address.classId, address.objectId, 0,
1088  lockmode);
1089  }
1090 
1091  /*
1092  * At this point, we've resolved the name to an OID and locked the
1093  * corresponding database object. However, it's possible that by the
1094  * time we acquire the lock on the object, concurrent DDL has modified
1095  * the database in such a way that the name we originally looked up no
1096  * longer resolves to that OID.
1097  *
1098  * We can be certain that this isn't an issue if (a) no shared
1099  * invalidation messages have been processed or (b) we've locked a
1100  * relation somewhere along the line. All the relation name lookups
1101  * in this module ultimately use RangeVarGetRelid() to acquire a
1102  * relation lock, and that function protects against the same kinds of
1103  * races we're worried about here. Even when operating on a
1104  * constraint, rule, or trigger, we still acquire AccessShareLock on
1105  * the relation, which is enough to freeze out any concurrent DDL.
1106  *
1107  * In all other cases, however, it's possible that the name we looked
1108  * up no longer refers to the object we locked, so we retry the lookup
1109  * and see whether we get the same answer.
1110  */
1111  if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1112  break;
1113  old_address = address;
1114  }
1115 
1116  /* Return the object address and the relation. */
1117  *relp = relation;
1118  return address;
1119 }
Oid LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
Definition: parse_oper.c:140
static ObjectAddress get_object_address_usermapping(List *object, bool missing_ok)
static ObjectAddress get_object_address_publication_rel(List *object, Relation *relp, bool missing_ok)
Oid oidparse(Node *node)
Definition: oid.c:314
static ObjectAddress get_object_address_attribute(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define castNode(_type_, nodeptr)
Definition: nodes.h:595
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:250
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2679
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial_node(type, l)
Definition: pg_list.h:198
static ObjectAddress get_object_address_unqualified(ObjectType objtype, Value *strval, bool missing_ok)
#define OidIsValid(objectId)
Definition: c.h:644
#define lsecond(l)
Definition: pg_list.h:200
static ObjectAddress get_relation_by_qualified_name(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static ObjectAddress get_object_address_attrdef(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2426
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
#define ERROR
Definition: elog.h:43
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1023
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2178
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2553
#define NoLock
Definition: lockdefs.h:34
static ObjectAddress get_object_address_relobject(ObjectType objtype, List *object, Relation *relp, bool missing_ok)
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:961
static ObjectAddress get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
static ObjectAddress get_object_address_defacl(List *object, bool missing_ok)
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:982
#define lsecond_node(type, l)
Definition: pg_list.h:203
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:238
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1002
uint64 SharedInvalidMessageCounter
Definition: sinval.c:26
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2300
#define Assert(condition)
Definition: c.h:738
Definition: value.h:42
static ObjectAddress get_object_address_opf_member(ObjectType objtype, List *object, bool missing_ok)
Oid get_conversion_oid(List *name, bool missing_ok)
Definition: namespace.c:3655
bool LargeObjectExists(Oid loid)
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
Definition: parse_func.c:2163
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
Definition: lsyscache.c:956
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3601
Definition: pg_list.h:50
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition: parse_type.c:232

◆ get_object_address_attrdef()

static ObjectAddress get_object_address_attrdef ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1449 of file objectaddress.c.

References AccessShareLock, attname, attnum, AttrDefaultIndexId, BTEqualStrategyNumber, ObjectAddress::classId, TupleDescData::constr, ereport, errcode(), errmsg(), ERROR, get_attnum(), GETSTRUCT, HeapTupleIsValid, Int16GetDatum, InvalidAttrNumber, InvalidOid, list_copy(), list_length(), list_truncate(), llast, makeRangeVarFromNameList(), NameListToString(), ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OidIsValid, relation_close(), relation_open(), relation_openrv(), RelationGetDescr, RelationGetRelid, relname, ScanKeyInit(), strVal, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by get_object_address().

1452 {
1453  ObjectAddress address;
1454  List *relname;
1455  Oid reloid;
1456  Relation relation;
1457  const char *attname;
1459  TupleDesc tupdesc;
1460  Oid defoid;
1461 
1462  /* Extract relation name and open relation. */
1463  if (list_length(object) < 2)
1464  ereport(ERROR,
1465  (errcode(ERRCODE_SYNTAX_ERROR),
1466  errmsg("column name must be qualified")));
1467  attname = strVal(llast(object));
1468  relname = list_truncate(list_copy(object), list_length(object) - 1);
1469  /* XXX no missing_ok support here */
1470  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1471  reloid = RelationGetRelid(relation);
1472 
1473  tupdesc = RelationGetDescr(relation);
1474 
1475  /* Look up attribute number and scan pg_attrdef to find its tuple */
1476  attnum = get_attnum(reloid, attname);
1477  defoid = InvalidOid;
1478  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1479  {
1480  Relation attrdef;
1481  ScanKeyData keys[2];
1482  SysScanDesc scan;
1483  HeapTuple tup;
1484 
1485  attrdef = relation_open(AttrDefaultRelationId, AccessShareLock);
1486  ScanKeyInit(&keys[0],
1487  Anum_pg_attrdef_adrelid,
1489  F_OIDEQ,
1490  ObjectIdGetDatum(reloid));
1491  ScanKeyInit(&keys[1],
1492  Anum_pg_attrdef_adnum,
1494  F_INT2EQ,
1495  Int16GetDatum(attnum));
1496  scan = systable_beginscan(attrdef, AttrDefaultIndexId, true,
1497  NULL, 2, keys);
1498  if (HeapTupleIsValid(tup = systable_getnext(scan)))
1499  {
1500  Form_pg_attrdef atdform = (Form_pg_attrdef) GETSTRUCT(tup);
1501 
1502  defoid = atdform->oid;
1503  }
1504 
1505  systable_endscan(scan);
1506  relation_close(attrdef, AccessShareLock);
1507  }
1508  if (!OidIsValid(defoid))
1509  {
1510  if (!missing_ok)
1511  ereport(ERROR,
1512  (errcode(ERRCODE_UNDEFINED_COLUMN),
1513  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1514  attname, NameListToString(relname))));
1515 
1516  address.classId = AttrDefaultRelationId;
1517  address.objectId = InvalidOid;
1518  address.objectSubId = InvalidAttrNumber;
1519  relation_close(relation, lockmode);
1520  return address;
1521  }
1522 
1523  address.classId = AttrDefaultRelationId;
1524  address.objectId = defoid;
1525  address.objectSubId = 0;
1526 
1527  *relp = relation;
1528  return address;
1529 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:529
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define RelationGetDescr(relation)
Definition: rel.h:482
#define llast(l)
Definition: pg_list.h:215
#define Int16GetDatum(X)
Definition: postgres.h:451
List * list_truncate(List *list, int new_size)
Definition: list.c:586
#define AccessShareLock
Definition: lockdefs.h:36
List * list_copy(const List *oldlist)
Definition: list.c:1404
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:356
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:448
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
NameData attname
Definition: pg_attribute.h:40
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
#define AttrDefaultIndexId
Definition: indexing.h:89
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:807
TupleConstr * constr
Definition: tupdesc.h:85
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * NameListToString(List *names)
Definition: namespace.c:3102
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
static int list_length(const List *l)
Definition: pg_list.h:169
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:824
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:456
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ get_object_address_attribute()

static ObjectAddress get_object_address_attribute ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1398 of file objectaddress.c.

References attname, attnum, ObjectAddress::classId, ereport, errcode(), errmsg(), ERROR, get_attnum(), InvalidAttrNumber, InvalidOid, lfirst, list_copy(), list_length(), list_tail(), list_truncate(), makeRangeVarFromNameList(), NameListToString(), ObjectAddress::objectId, ObjectAddress::objectSubId, relation_close(), relation_openrv(), RelationGetRelid, relname, and strVal.

Referenced by get_object_address().

1401 {
1402  ObjectAddress address;
1403  List *relname;
1404  Oid reloid;
1405  Relation relation;
1406  const char *attname;
1408 
1409  /* Extract relation name and open relation. */
1410  if (list_length(object) < 2)
1411  ereport(ERROR,
1412  (errcode(ERRCODE_SYNTAX_ERROR),
1413  errmsg("column name must be qualified")));
1414  attname = strVal(lfirst(list_tail(object)));
1415  relname = list_truncate(list_copy(object), list_length(object) - 1);
1416  /* XXX no missing_ok support here */
1417  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1418  reloid = RelationGetRelid(relation);
1419 
1420  /* Look up attribute and construct return value. */
1421  attnum = get_attnum(reloid, attname);
1422  if (attnum == InvalidAttrNumber)
1423  {
1424  if (!missing_ok)
1425  ereport(ERROR,
1426  (errcode(ERRCODE_UNDEFINED_COLUMN),
1427  errmsg("column \"%s\" of relation \"%s\" does not exist",
1428  attname, NameListToString(relname))));
1429 
1430  address.classId = RelationRelationId;
1431  address.objectId = InvalidOid;
1432  address.objectSubId = InvalidAttrNumber;
1433  relation_close(relation, lockmode);
1434  return address;
1435  }
1436 
1437  address.classId = RelationRelationId;
1438  address.objectId = reloid;
1439  address.objectSubId = attnum;
1440 
1441  *relp = relation;
1442  return address;
1443 }
List * list_truncate(List *list, int new_size)
Definition: list.c:586
List * list_copy(const List *oldlist)
Definition: list.c:1404
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
NameData attname
Definition: pg_attribute.h:40
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:807
char * NameListToString(List *names)
Definition: namespace.c:3102
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define ereport(elevel,...)
Definition: elog.h:144
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define lfirst(lc)
Definition: pg_list.h:190
static int list_length(const List *l)
Definition: pg_list.h:169
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:824
static ListCell * list_tail(const List *l)
Definition: pg_list.h:132
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:456

◆ get_object_address_defacl()

static ObjectAddress get_object_address_defacl ( List object,
bool  missing_ok 
)
static

Definition at line 1847 of file objectaddress.c.

References AUTHNAME, CharGetDatum, CStringGetDatum, DEFACLROLENSPOBJ, ereport, errcode(), errhint(), errmsg(), ERROR, get_namespace_oid(), GETSTRUCT, HeapTupleIsValid, InvalidOid, linitial, list_length(), lsecond, lthird, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1(), SearchSysCache3(), strVal, and username.

Referenced by get_object_address().

1848 {
1849  HeapTuple tp;
1850  Oid userid;
1851  Oid schemaid;
1852  char *username;
1853  char *schema;
1854  char objtype;
1855  char *objtype_str;
1856  ObjectAddress address;
1857 
1858  ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
1859 
1860  /*
1861  * First figure out the textual attributes so that they can be used for
1862  * error reporting.
1863  */
1864  username = strVal(lsecond(object));
1865  if (list_length(object) >= 3)
1866  schema = (char *) strVal(lthird(object));
1867  else
1868  schema = NULL;
1869 
1870  /*
1871  * Decode defaclobjtype. Only first char is considered; the rest of the
1872  * string, if any, is blissfully ignored.
1873  */
1874  objtype = ((char *) strVal(linitial(object)))[0];
1875  switch (objtype)
1876  {
1877  case DEFACLOBJ_RELATION:
1878  objtype_str = "tables";
1879  break;
1880  case DEFACLOBJ_SEQUENCE:
1881  objtype_str = "sequences";
1882  break;
1883  case DEFACLOBJ_FUNCTION:
1884  objtype_str = "functions";
1885  break;
1886  case DEFACLOBJ_TYPE:
1887  objtype_str = "types";
1888  break;
1889  case DEFACLOBJ_NAMESPACE:
1890  objtype_str = "schemas";
1891  break;
1892  default:
1893  ereport(ERROR,
1894  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1895  errmsg("unrecognized default ACL object type \"%c\"", objtype),
1896  errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
1897  DEFACLOBJ_RELATION,
1898  DEFACLOBJ_SEQUENCE,
1899  DEFACLOBJ_FUNCTION,
1900  DEFACLOBJ_TYPE,
1901  DEFACLOBJ_NAMESPACE)));
1902  }
1903 
1904  /*
1905  * Look up user ID. Behave as "default ACL not found" if the user doesn't
1906  * exist.
1907  */
1909  CStringGetDatum(username));
1910  if (!HeapTupleIsValid(tp))
1911  goto not_found;
1912  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1913  ReleaseSysCache(tp);
1914 
1915  /*
1916  * If a schema name was given, look up its OID. If it doesn't exist,
1917  * behave as "default ACL not found".
1918  */
1919  if (schema)
1920  {
1921  schemaid = get_namespace_oid(schema, true);
1922  if (schemaid == InvalidOid)
1923  goto not_found;
1924  }
1925  else
1926  schemaid = InvalidOid;
1927 
1928  /* Finally, look up the pg_default_acl object */
1930  ObjectIdGetDatum(userid),
1931  ObjectIdGetDatum(schemaid),
1932  CharGetDatum(objtype));
1933  if (!HeapTupleIsValid(tp))
1934  goto not_found;
1935 
1936  address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
1937  ReleaseSysCache(tp);
1938 
1939  return address;
1940 
1941 not_found:
1942  if (!missing_ok)
1943  {
1944  if (schema)
1945  ereport(ERROR,
1946  (errcode(ERRCODE_UNDEFINED_OBJECT),
1947  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
1948  username, schema, objtype_str)));
1949  else
1950  ereport(ERROR,
1951  (errcode(ERRCODE_UNDEFINED_OBJECT),
1952  errmsg("default ACL for user \"%s\" on %s does not exist",
1953  username, objtype_str)));
1954  }
1955  return address;
1956 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3043
int errhint(const char *fmt,...)
Definition: elog.c:1071
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:200
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
#define linitial(l)
Definition: pg_list.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Definition: syscache.c:1138
FormData_pg_default_acl * Form_pg_default_acl
#define CStringGetDatum(X)
Definition: postgres.h:578
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
static char * username
Definition: initdb.c:133
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static int list_length(const List *l)
Definition: pg_list.h:169
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define CharGetDatum(X)
Definition: postgres.h:416
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define lthird(l)
Definition: pg_list.h:205

◆ get_object_address_opcf()

static ObjectAddress get_object_address_opcf ( ObjectType  objtype,
List object,
bool  missing_ok 
)
static

Definition at line 1574 of file objectaddress.c.

References ObjectAddress::classId, elog, ERROR, get_index_am_oid(), get_opclass_oid(), get_opfamily_oid(), InvalidOid, linitial, list_copy_tail(), OBJECT_OPCLASS, OBJECT_OPFAMILY, ObjectAddress::objectId, ObjectAddress::objectSubId, and strVal.

Referenced by get_object_address(), and get_object_address_opf_member().

1575 {
1576  Oid amoid;
1577  ObjectAddress address;
1578 
1579  /* XXX no missing_ok support here */
1580  amoid = get_index_am_oid(strVal(linitial(object)), false);
1581  object = list_copy_tail(object, 1);
1582 
1583  switch (objtype)
1584  {
1585  case OBJECT_OPCLASS:
1586  address.classId = OperatorClassRelationId;
1587  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1588  address.objectSubId = 0;
1589  break;
1590  case OBJECT_OPFAMILY:
1591  address.classId = OperatorFamilyRelationId;
1592  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1593  address.objectSubId = 0;
1594  break;
1595  default:
1596  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1597  /* placate compiler, which doesn't know elog won't return */
1598  address.classId = InvalidOid;
1599  address.objectId = InvalidOid;
1600  address.objectSubId = 0;
1601  }
1602 
1603  return address;
1604 }
#define strVal(v)
Definition: value.h:54
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c:223
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1423
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
Oid get_index_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:187
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)
Definition: opclasscmds.c:142
#define elog(elevel,...)
Definition: elog.h:214

◆ get_object_address_opf_member()

static ObjectAddress get_object_address_opf_member ( ObjectType  objtype,
List object,
bool  missing_ok 
)
static

Definition at line 1612 of file objectaddress.c.

References AMOPSTRATEGY, AMPROCNUM, elog, ereport, errcode(), errmsg(), ERROR, get_object_address_opcf(), get_object_address_type(), getObjectDescription(), GETSTRUCT, HeapTupleIsValid, i, Int16GetDatum, InvalidOid, lfirst_node, linitial, list_copy(), list_length(), list_truncate(), llast, lsecond, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_OPFAMILY, OBJECT_TYPE, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache4(), strVal, and TypeNameToString().

Referenced by get_object_address().

1614 {
1615  ObjectAddress famaddr;
1616  ObjectAddress address;
1617  ListCell *cell;
1618  List *copy;
1619  TypeName *typenames[2];
1620  Oid typeoids[2];
1621  int membernum;
1622  int i;
1623 
1624  /*
1625  * The last element of the object list contains the strategy or procedure
1626  * number. We need to strip that out before getting the opclass/family
1627  * address. The rest can be used directly by get_object_address_opcf().
1628  */
1629  membernum = atoi(strVal(llast(linitial(object))));
1630  copy = list_truncate(list_copy(linitial(object)), list_length(linitial(object)) - 1);
1631 
1632  /* no missing_ok support here */
1633  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1634 
1635  /* find out left/right type names and OIDs */
1636  typenames[0] = typenames[1] = NULL;
1637  typeoids[0] = typeoids[1] = InvalidOid;
1638  i = 0;
1639  foreach(cell, lsecond(object))
1640  {
1641  ObjectAddress typaddr;
1642 
1643  typenames[i] = lfirst_node(TypeName, cell);
1644  typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
1645  typeoids[i] = typaddr.objectId;
1646  if (++i >= 2)
1647  break;
1648  }
1649 
1650  switch (objtype)
1651  {
1652  case OBJECT_AMOP:
1653  {
1654  HeapTuple tp;
1655 
1656  ObjectAddressSet(address, AccessMethodOperatorRelationId,
1657  InvalidOid);
1658 
1660  ObjectIdGetDatum(famaddr.objectId),
1661  ObjectIdGetDatum(typeoids[0]),
1662  ObjectIdGetDatum(typeoids[1]),
1663  Int16GetDatum(membernum));
1664  if (!HeapTupleIsValid(tp))
1665  {
1666  if (!missing_ok)
1667  ereport(ERROR,
1668  (errcode(ERRCODE_UNDEFINED_OBJECT),
1669  errmsg("operator %d (%s, %s) of %s does not exist",
1670  membernum,
1671  TypeNameToString(typenames[0]),
1672  TypeNameToString(typenames[1]),
1673  getObjectDescription(&famaddr))));
1674  }
1675  else
1676  {
1677  address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
1678  ReleaseSysCache(tp);
1679  }
1680  }
1681  break;
1682 
1683  case OBJECT_AMPROC:
1684  {
1685  HeapTuple tp;
1686 
1687  ObjectAddressSet(address, AccessMethodProcedureRelationId,
1688  InvalidOid);
1689 
1691  ObjectIdGetDatum(famaddr.objectId),
1692  ObjectIdGetDatum(typeoids[0]),
1693  ObjectIdGetDatum(typeoids[1]),
1694  Int16GetDatum(membernum));
1695  if (!HeapTupleIsValid(tp))
1696  {
1697  if (!missing_ok)
1698  ereport(ERROR,
1699  (errcode(ERRCODE_UNDEFINED_OBJECT),
1700  errmsg("function %d (%s, %s) of %s does not exist",
1701  membernum,
1702  TypeNameToString(typenames[0]),
1703  TypeNameToString(typenames[1]),
1704  getObjectDescription(&famaddr))));
1705  }
1706  else
1707  {
1708  address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
1709  ReleaseSysCache(tp);
1710  }
1711  }
1712  break;
1713  default:
1714  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1715  }
1716 
1717  return address;
1718 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:476
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
#define llast(l)
Definition: pg_list.h:215
#define Int16GetDatum(X)
Definition: postgres.h:451
List * list_truncate(List *list, int new_size)
Definition: list.c:586
List * list_copy(const List *oldlist)
Definition: list.c:1404
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:200
char * getObjectDescription(const ObjectAddress *object)
#define linitial(l)
Definition: pg_list.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define lfirst_node(type, lc)
Definition: pg_list.h:193
static ObjectAddress get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:1149
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static int list_length(const List *l)
Definition: pg_list.h:169
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:824
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
#define elog(elevel,...)
Definition: elog.h:214
int i
Definition: pg_list.h:50

◆ get_object_address_publication_rel()

static ObjectAddress get_object_address_publication_rel ( List object,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1795 of file objectaddress.c.

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, makeRangeVarFromNameList(), ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, Publication::oid, OidIsValid, PUBLICATIONRELMAP, relation_close(), relation_openrv_extended(), RelationGetRelationName, RelationGetRelid, relname, and strVal.

Referenced by get_object_address().

1797 {
1798  ObjectAddress address;
1799  Relation relation;
1800  List *relname;
1801  char *pubname;
1802  Publication *pub;
1803 
1804  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1805 
1806  relname = linitial(object);
1808  AccessShareLock, missing_ok);
1809  if (!relation)
1810  return address;
1811 
1812  /* fetch publication name from input list */
1813  pubname = strVal(lsecond(object));
1814 
1815  /* Now look up the pg_publication tuple */
1816  pub = GetPublicationByName(pubname, missing_ok);
1817  if (!pub)
1818  {
1819  relation_close(relation, AccessShareLock);
1820  return address;
1821  }
1822 
1823  /* Find the publication relation mapping in syscache. */
1824  address.objectId =
1825  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1827  ObjectIdGetDatum(pub->oid));
1828  if (!OidIsValid(address.objectId))
1829  {
1830  if (!missing_ok)
1831  ereport(ERROR,
1832  (errcode(ERRCODE_UNDEFINED_OBJECT),
1833  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1834  RelationGetRelationName(relation), pubname)));
1835  relation_close(relation, AccessShareLock);
1836  return address;
1837  }
1838 
1839  *relp = relation;
1840  return address;
1841 }
#define AccessShareLock
Definition: lockdefs.h:36
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
NameData relname
Definition: pg_class.h:38
#define OidIsValid(objectId)
Definition: c.h:644
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
#define lsecond(l)
Definition: pg_list.h:200
#define linitial(l)
Definition: pg_list.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:490
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:194
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:456
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: relation.c:173

◆ get_object_address_relobject()

static ObjectAddress get_object_address_relobject ( ObjectType  objtype,
List object,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1319 of file objectaddress.c.

References AccessShareLock, ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, get_relation_constraint_oid(), get_relation_policy_oid(), get_rewrite_oid(), get_trigger_oid(), InvalidOid, list_copy(), list_length(), list_truncate(), llast, makeRangeVarFromNameList(), OBJECT_POLICY, OBJECT_RULE, OBJECT_TABCONSTRAINT, OBJECT_TRIGGER, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, RelationGetRelid, relname, strVal, table_close(), and table_openrv_extended().

Referenced by get_object_address().

1321 {
1322  ObjectAddress address;
1323  Relation relation = NULL;
1324  int nnames;
1325  const char *depname;
1326  List *relname;
1327  Oid reloid;
1328 
1329  /* Extract name of dependent object. */
1330  depname = strVal(llast(object));
1331 
1332  /* Separate relation name from dependent object name. */
1333  nnames = list_length(object);
1334  if (nnames < 2)
1335  ereport(ERROR,
1336  (errcode(ERRCODE_SYNTAX_ERROR),
1337  errmsg("must specify relation and object name")));
1338 
1339  /* Extract relation name and open relation. */
1340  relname = list_truncate(list_copy(object), nnames - 1);
1341  relation = table_openrv_extended(makeRangeVarFromNameList(relname),
1343  missing_ok);
1344 
1345  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1346 
1347  switch (objtype)
1348  {
1349  case OBJECT_RULE:
1350  address.classId = RewriteRelationId;
1351  address.objectId = relation ?
1352  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1353  address.objectSubId = 0;
1354  break;
1355  case OBJECT_TRIGGER:
1356  address.classId = TriggerRelationId;
1357  address.objectId = relation ?
1358  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1359  address.objectSubId = 0;
1360  break;
1361  case OBJECT_TABCONSTRAINT:
1362  address.classId = ConstraintRelationId;
1363  address.objectId = relation ?
1364  get_relation_constraint_oid(reloid, depname, missing_ok) :
1365  InvalidOid;
1366  address.objectSubId = 0;
1367  break;
1368  case OBJECT_POLICY:
1369  address.classId = PolicyRelationId;
1370  address.objectId = relation ?
1371  get_relation_policy_oid(reloid, depname, missing_ok) :
1372  InvalidOid;
1373  address.objectSubId = 0;
1374  break;
1375  default:
1376  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1377  }
1378 
1379  /* Avoid relcache leak when object not found. */
1380  if (!OidIsValid(address.objectId))
1381  {
1382  if (relation != NULL)
1383  table_close(relation, AccessShareLock);
1384 
1385  relation = NULL; /* department of accident prevention */
1386  return address;
1387  }
1388 
1389  /* Done. */
1390  *relp = relation;
1391  return address;
1392 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
Relation table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: table.c:98
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
#define llast(l)
Definition: pg_list.h:215
List * list_truncate(List *list, int new_size)
Definition: list.c:586
#define AccessShareLock
Definition: lockdefs.h:36
List * list_copy(const List *oldlist)
Definition: list.c:1404
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
#define ERROR
Definition: elog.h:43
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
Oid get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
Definition: policy.c:1327
static int list_length(const List *l)
Definition: pg_list.h:169
Oid get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
Definition: trigger.c:1239
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:456

◆ get_object_address_rv()

ObjectAddress get_object_address_rv ( ObjectType  objtype,
RangeVar rel,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 1129 of file objectaddress.c.

References RangeVar::catalogname, get_object_address(), lcons(), makeString(), RangeVar::relname, and RangeVar::schemaname.

Referenced by ExecAlterObjectDependsStmt().

1132 {
1133  if (rel)
1134  {
1135  object = lcons(makeString(rel->relname), object);
1136  if (rel->schemaname)
1137  object = lcons(makeString(rel->schemaname), object);
1138  if (rel->catalogname)
1139  object = lcons(makeString(rel->catalogname), object);
1140  }
1141 
1142  return get_object_address(objtype, (Node *) object,
1143  relp, lockmode, missing_ok);
1144 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:526
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
List * lcons(void *datum, List *list)
Definition: list.c:454
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
char * catalogname
Definition: primnodes.h:66

◆ get_object_address_type()

static ObjectAddress get_object_address_type ( ObjectType  objtype,
TypeName typename,
bool  missing_ok 
)
static

Definition at line 1535 of file objectaddress.c.

References ObjectAddress::classId, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, HeapTupleIsValid, InvalidOid, LookupTypeName(), OBJECT_DOMAIN, ObjectAddress::objectId, ObjectAddress::objectSubId, ReleaseSysCache(), TypeNameToString(), and typeTypeId().

Referenced by get_object_address(), and get_object_address_opf_member().

1536 {
1537  ObjectAddress address;
1538  Type tup;
1539 
1540  address.classId = TypeRelationId;
1541  address.objectId = InvalidOid;
1542  address.objectSubId = 0;
1543 
1544  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1545  if (!HeapTupleIsValid(tup))
1546  {
1547  if (!missing_ok)
1548  ereport(ERROR,
1549  (errcode(ERRCODE_UNDEFINED_OBJECT),
1550  errmsg("type \"%s\" does not exist",
1551  TypeNameToString(typename))));
1552  return address;
1553  }
1554  address.objectId = typeTypeId(tup);
1555 
1556  if (objtype == OBJECT_DOMAIN)
1557  {
1558  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1559  ereport(ERROR,
1560  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1561  errmsg("\"%s\" is not a domain",
1562  TypeNameToString(typename))));
1563  }
1564 
1565  ReleaseSysCache(tup);
1566 
1567  return address;
1568 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:38
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:476
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
int errmsg(const char *fmt,...)
Definition: elog.c:824
Oid typeTypeId(Type tp)
Definition: parse_type.c:588

◆ get_object_address_unqualified()

static ObjectAddress get_object_address_unqualified ( ObjectType  objtype,
Value strval,
bool  missing_ok 
)
static

Definition at line 1151 of file objectaddress.c.

References ObjectAddress::classId, elog, ERROR, get_am_oid(), get_database_oid(), get_event_trigger_oid(), get_extension_oid(), get_foreign_data_wrapper_oid(), get_foreign_server_oid(), get_language_oid(), get_namespace_oid(), get_publication_oid(), get_role_oid(), get_subscription_oid(), get_tablespace_oid(), InvalidOid, name, OBJECT_ACCESS_METHOD, OBJECT_DATABASE, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_LANGUAGE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_SCHEMA, OBJECT_SUBSCRIPTION, OBJECT_TABLESPACE, ObjectAddress::objectId, ObjectAddress::objectSubId, and strVal.

Referenced by get_object_address().

1153 {
1154  const char *name;
1155  ObjectAddress address;
1156 
1157  name = strVal(strval);
1158 
1159  /* Translate name to OID. */
1160  switch (objtype)
1161  {
1162  case OBJECT_ACCESS_METHOD:
1163  address.classId = AccessMethodRelationId;
1164  address.objectId = get_am_oid(name, missing_ok);
1165  address.objectSubId = 0;
1166  break;
1167  case OBJECT_DATABASE:
1168  address.classId = DatabaseRelationId;
1169  address.objectId = get_database_oid(name, missing_ok);
1170  address.objectSubId = 0;
1171  break;
1172  case OBJECT_EXTENSION:
1173  address.classId = ExtensionRelationId;
1174  address.objectId = get_extension_oid(name, missing_ok);
1175  address.objectSubId = 0;
1176  break;
1177  case OBJECT_TABLESPACE:
1178  address.classId = TableSpaceRelationId;
1179  address.objectId = get_tablespace_oid(name, missing_ok);
1180  address.objectSubId = 0;
1181  break;
1182  case OBJECT_ROLE:
1183  address.classId = AuthIdRelationId;
1184  address.objectId = get_role_oid(name, missing_ok);
1185  address.objectSubId = 0;
1186  break;
1187  case OBJECT_SCHEMA:
1188  address.classId = NamespaceRelationId;
1189  address.objectId = get_namespace_oid(name, missing_ok);
1190  address.objectSubId = 0;
1191  break;
1192  case OBJECT_LANGUAGE:
1193  address.classId = LanguageRelationId;
1194  address.objectId = get_language_oid(name, missing_ok);
1195  address.objectSubId = 0;
1196  break;
1197  case OBJECT_FDW:
1198  address.classId = ForeignDataWrapperRelationId;
1199  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1200  address.objectSubId = 0;
1201  break;
1202  case OBJECT_FOREIGN_SERVER:
1203  address.classId = ForeignServerRelationId;
1204  address.objectId = get_foreign_server_oid(name, missing_ok);
1205  address.objectSubId = 0;
1206  break;
1207  case OBJECT_EVENT_TRIGGER:
1208  address.classId = EventTriggerRelationId;
1209  address.objectId = get_event_trigger_oid(name, missing_ok);
1210  address.objectSubId = 0;
1211  break;
1212  case OBJECT_PUBLICATION:
1213  address.classId = PublicationRelationId;
1214  address.objectId = get_publication_oid(name, missing_ok);
1215  address.objectSubId = 0;
1216  break;
1217  case OBJECT_SUBSCRIPTION:
1218  address.classId = SubscriptionRelationId;
1219  address.objectId = get_subscription_oid(name, missing_ok);
1220  address.objectSubId = 0;
1221  break;
1222  default:
1223  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1224  /* placate compiler, which doesn't know elog won't return */
1225  address.classId = InvalidOid;
1226  address.objectId = InvalidOid;
1227  address.objectSubId = 0;
1228  }
1229 
1230  return address;
1231 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1416
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3043
Oid get_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:207
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:250
#define strVal(v)
Definition: value.h:54
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5183
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:691
#define ERROR
Definition: elog.h:43
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2108
Oid get_subscription_oid(const char *subname, bool missing_ok)
const char * name
Definition: encode.c:521
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:140
#define elog(elevel,...)
Definition: elog.h:214
Oid get_publication_oid(const char *pubname, bool missing_ok)
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:714

◆ get_object_address_usermapping()

static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

Definition at line 1724 of file objectaddress.c.

References AUTHNAME, CStringGetDatum, ereport, errcode(), errmsg(), ERROR, GetForeignServerByName(), GETSTRUCT, HeapTupleIsValid, InvalidOid, linitial, lsecond, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1(), SearchSysCache2(), ForeignServer::serverid, strVal, and username.

Referenced by get_object_address().

1725 {
1726  ObjectAddress address;
1727  Oid userid;
1728  char *username;
1729  char *servername;
1730  ForeignServer *server;
1731  HeapTuple tp;
1732 
1733  ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1734 
1735  /* fetch string names from input lists, for error messages */
1736  username = strVal(linitial(object));
1737  servername = strVal(lsecond(object));
1738 
1739  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1740  if (strcmp(username, "public") == 0)
1741  userid = InvalidOid;
1742  else
1743  {
1745  CStringGetDatum(username));
1746  if (!HeapTupleIsValid(tp))
1747  {
1748  if (!missing_ok)
1749  ereport(ERROR,
1750  (errcode(ERRCODE_UNDEFINED_OBJECT),
1751  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1752  username, servername)));
1753  return address;
1754  }
1755  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1756  ReleaseSysCache(tp);
1757  }
1758 
1759  /* Now look up the pg_user_mapping tuple */
1760  server = GetForeignServerByName(servername, true);
1761  if (!server)
1762  {
1763  if (!missing_ok)
1764  ereport(ERROR,
1765  (errcode(ERRCODE_UNDEFINED_OBJECT),
1766  errmsg("server \"%s\" does not exist", servername)));
1767  return address;
1768  }
1769  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1770  ObjectIdGetDatum(userid),
1771  ObjectIdGetDatum(server->serverid));
1772  if (!HeapTupleIsValid(tp))
1773  {
1774  if (!missing_ok)
1775  ereport(ERROR,
1776  (errcode(ERRCODE_UNDEFINED_OBJECT),
1777  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1778  username, servername)));
1779  return address;
1780  }
1781 
1782  address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1783 
1784  ReleaseSysCache(tp);
1785 
1786  return address;
1787 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:200
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
#define linitial(l)
Definition: pg_list.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
FormData_pg_user_mapping * Form_pg_user_mapping
#define CStringGetDatum(X)
Definition: postgres.h:578
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
Definition: foreign.c:180
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
static char * username
Definition: initdb.c:133
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1127
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:824
Oid serverid
Definition: foreign.h:36

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2609 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2610 {
2611  const ObjectPropertyType *prop = get_object_property_data(class_id);
2612 
2613  return prop->attnum_acl;
2614 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl

◆ get_object_attnum_name()

AttrNumber get_object_attnum_name ( Oid  class_id)

Definition at line 2585 of file objectaddress.c.

References ObjectPropertyType::attnum_name, and get_object_property_data().

Referenced by AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), EventTriggerSQLDropAddObject(), and pg_identify_object().

2586 {
2587  const ObjectPropertyType *prop = get_object_property_data(class_id);
2588 
2589  return prop->attnum_name;
2590 }
AttrNumber attnum_name
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_attnum_namespace()

AttrNumber get_object_attnum_namespace ( Oid  class_id)

Definition at line 2593 of file objectaddress.c.

References ObjectPropertyType::attnum_namespace, and get_object_property_data().

Referenced by AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), EventTriggerSQLDropAddObject(), pg_event_trigger_ddl_commands(), and pg_identify_object().

2594 {
2595  const ObjectPropertyType *prop = get_object_property_data(class_id);
2596 
2597  return prop->attnum_namespace;
2598 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace

◆ get_object_attnum_oid()

AttrNumber get_object_attnum_oid ( Oid  class_id)

Definition at line 2577 of file objectaddress.c.

References ObjectPropertyType::attnum_oid, and get_object_property_data().

Referenced by AlterObjectOwner_internal(), EventTriggerSQLDropAddObject(), pg_event_trigger_ddl_commands(), and pg_identify_object().

2578 {
2579  const ObjectPropertyType *prop = get_object_property_data(class_id);
2580 
2581  return prop->attnum_oid;
2582 }
AttrNumber attnum_oid
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_attnum_owner()

AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2601 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

Referenced by AlterObjectNamespace_internal(), AlterObjectOwner_internal(), and AlterObjectRename_internal().

2602 {
2603  const ObjectPropertyType *prop = get_object_property_data(class_id);
2604 
2605  return prop->attnum_owner;
2606 }
AttrNumber attnum_owner
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2569 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2570 {
2571  const ObjectPropertyType *prop = get_object_property_data(class_id);
2572 
2573  return prop->name_catcache_id;
2574 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_catcache_oid()

int get_object_catcache_oid ( Oid  class_id)

Definition at line 2561 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_catcache_id.

Referenced by AlterObjectNamespace_internal(), AlterObjectRename_internal(), and get_catalog_object_by_oid().

2562 {
2563  const ObjectPropertyType *prop = get_object_property_data(class_id);
2564 
2565  return prop->oid_catcache_id;
2566 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2642 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2643 {
2644  const ObjectPropertyType *prop = get_object_property_data(class_id);
2645 
2646  return prop->is_nsp_name_unique;
2647 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

Definition at line 2494 of file objectaddress.c.

References Assert, ObjectPropertyType::attnum_namespace, ObjectAddress::classId, DatumGetObjectId, elog, ERROR, get_object_property_data(), HeapTupleIsValid, InvalidAttrNumber, InvalidOid, ObjectAddress::objectId, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1(), and SysCacheGetAttr().

Referenced by RemoveObjects().

2495 {
2496  int cache;
2497  HeapTuple tuple;
2498  bool isnull;
2499  Oid oid;
2500  const ObjectPropertyType *property;
2501 
2502  /* If not owned by a namespace, just return InvalidOid. */
2503  property = get_object_property_data(address->classId);
2504  if (property->attnum_namespace == InvalidAttrNumber)
2505  return InvalidOid;
2506 
2507  /* Currently, we can only handle object types with system caches. */
2508  cache = property->oid_catcache_id;
2509  Assert(cache != -1);
2510 
2511  /* Fetch tuple from syscache and extract namespace attribute. */
2512  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2513  if (!HeapTupleIsValid(tuple))
2514  elog(ERROR, "cache lookup failed for cache %d oid %u",
2515  cache, address->objectId);
2516  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2517  tuple,
2518  property->attnum_namespace,
2519  &isnull));
2520  Assert(!isnull);
2521  ReleaseSysCache(tuple);
2522 
2523  return oid;
2524 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1377
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:738
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog(elevel,...)
Definition: elog.h:214

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2553 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2554 {
2555  const ObjectPropertyType *prop = get_object_property_data(class_id);
2556 
2557  return prop->oid_index_oid;
2558 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_property_data()

static const ObjectPropertyType * get_object_property_data ( Oid  class_id)
static

Definition at line 2671 of file objectaddress.c.

References ObjectPropertyType::class_oid, ereport, errmsg_internal(), ERROR, and lengthof.

Referenced by get_object_attnum_acl(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_oid(), get_object_attnum_owner(), get_object_catcache_name(), get_object_catcache_oid(), get_object_namensp_unique(), get_object_namespace(), get_object_oid_index(), and get_object_type().

2672 {
2673  static const ObjectPropertyType *prop_last = NULL;
2674  int index;
2675 
2676  /*
2677  * A shortcut to speed up multiple consecutive lookups of a particular
2678  * object class.
2679  */
2680  if (prop_last && prop_last->class_oid == class_id)
2681  return prop_last;
2682 
2683  for (index = 0; index < lengthof(ObjectProperty); index++)
2684  {
2685  if (ObjectProperty[index].class_oid == class_id)
2686  {
2687  prop_last = &ObjectProperty[index];
2688  return &ObjectProperty[index];
2689  }
2690  }
2691 
2692  ereport(ERROR,
2693  (errmsg_internal("unrecognized class ID: %u", class_id)));
2694 
2695  return NULL; /* keep MSC compiler happy */
2696 }
#define lengthof(array)
Definition: c.h:668
Definition: type.h:89
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType ObjectProperty[]
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:911

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

Definition at line 2624 of file objectaddress.c.

References get_object_property_data(), get_rel_relkind(), get_relkind_objtype(), OBJECT_TABLE, and ObjectPropertyType::objtype.

Referenced by AlterObjectNamespace_internal(), AlterObjectOwner_internal(), and AlterObjectRename_internal().

2625 {
2626  const ObjectPropertyType *prop = get_object_property_data(class_id);
2627 
2628  if (prop->objtype == OBJECT_TABLE)
2629  {
2630  /*
2631  * If the property data says it's a table, dig a little deeper to get
2632  * the real relation kind, so that callers can produce more precise
2633  * error messages.
2634  */
2635  return get_relkind_objtype(get_rel_relkind(object_id));
2636  }
2637  else
2638  return prop->objtype;
2639 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1866
static const ObjectPropertyType * get_object_property_data(Oid class_id)
ObjectType get_relkind_objtype(char relkind)

◆ get_relation_by_qualified_name()

static ObjectAddress get_relation_by_qualified_name ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1237 of file objectaddress.c.

References ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, InvalidOid, makeRangeVarFromNameList(), OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, RelationData::rd_rel, relation_openrv_extended(), RelationGetRelationName, and RelationGetRelid.

Referenced by get_object_address().

1240 {
1241  Relation relation;
1242  ObjectAddress address;
1243 
1244  address.classId = RelationRelationId;
1245  address.objectId = InvalidOid;
1246  address.objectSubId = 0;
1247 
1249  lockmode, missing_ok);
1250  if (!relation)
1251  return address;
1252 
1253  switch (objtype)
1254  {
1255  case OBJECT_INDEX:
1256  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1257  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1258  ereport(ERROR,
1259  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1260  errmsg("\"%s\" is not an index",
1261  RelationGetRelationName(relation))));
1262  break;
1263  case OBJECT_SEQUENCE:
1264  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1265  ereport(ERROR,
1266  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1267  errmsg("\"%s\" is not a sequence",
1268  RelationGetRelationName(relation))));
1269  break;
1270  case OBJECT_TABLE:
1271  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1272  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1273  ereport(ERROR,
1274  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1275  errmsg("\"%s\" is not a table",
1276  RelationGetRelationName(relation))));
1277  break;
1278  case OBJECT_VIEW:
1279  if (relation->rd_rel->relkind != RELKIND_VIEW)
1280  ereport(ERROR,
1281  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1282  errmsg("\"%s\" is not a view",
1283  RelationGetRelationName(relation))));
1284  break;
1285  case OBJECT_MATVIEW:
1286  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1287  ereport(ERROR,
1288  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1289  errmsg("\"%s\" is not a materialized view",
1290  RelationGetRelationName(relation))));
1291  break;
1292  case OBJECT_FOREIGN_TABLE:
1293  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1294  ereport(ERROR,
1295  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1296  errmsg("\"%s\" is not a foreign table",
1297  RelationGetRelationName(relation))));
1298  break;
1299  default:
1300  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1301  break;
1302  }
1303 
1304  /* Done. */
1305  address.objectId = RelationGetRelid(relation);
1306  *relp = relation;
1307 
1308  return address;
1309 }
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
Form_pg_class rd_rel
Definition: rel.h:109
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:490
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define RelationGetRelid(relation)
Definition: rel.h:456
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: relation.c:173

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 5355 of file objectaddress.c.

References OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, and OBJECT_VIEW.

Referenced by AlterTableMoveAll(), ATExecChangeOwner(), ATSimplePermissions(), checkFkeyPermissions(), CreateStatistics(), CreateTrigger(), currtid_byrelname(), currtid_byreloid(), DefineQueryRewrite(), EnableDisableRule(), ExecCheckRTPerms(), get_object_type(), get_rel_from_relname(), LockViewRecurse_walker(), MergeAttributes(), pg_prewarm(), pgrowlocks(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), transformTableLikeClause(), and truncate_check_perms().

5356 {
5357  switch (relkind)
5358  {
5359  case RELKIND_RELATION:
5360  case RELKIND_PARTITIONED_TABLE:
5361  return OBJECT_TABLE;
5362  case RELKIND_INDEX:
5363  case RELKIND_PARTITIONED_INDEX:
5364  return OBJECT_INDEX;
5365  case RELKIND_SEQUENCE:
5366  return OBJECT_SEQUENCE;
5367  case RELKIND_VIEW:
5368  return OBJECT_VIEW;
5369  case RELKIND_MATVIEW:
5370  return OBJECT_MATVIEW;
5371  case RELKIND_FOREIGN_TABLE:
5372  return OBJECT_FOREIGN_TABLE;
5373  case RELKIND_TOASTVALUE:
5374  return OBJECT_TABLE;
5375  default:
5376  /* Per above, don't raise an error */
5377  return OBJECT_TABLE;
5378  }
5379 }

◆ getConstraintTypeDescription()

static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid 
)
static

Definition at line 4226 of file objectaddress.c.

References AccessShareLock, appendStringInfoString(), elog, ERROR, get_catalog_object_by_oid(), GETSTRUCT, HeapTupleIsValid, OidIsValid, table_close(), and table_open().

Referenced by getObjectTypeDescription().

4227 {
4228  Relation constrRel;
4229  HeapTuple constrTup;
4230  Form_pg_constraint constrForm;
4231 
4232  constrRel = table_open(ConstraintRelationId, AccessShareLock);
4233  constrTup = get_catalog_object_by_oid(constrRel, Anum_pg_constraint_oid,
4234  constroid);
4235  if (!HeapTupleIsValid(constrTup))
4236  elog(ERROR, "cache lookup failed for constraint %u", constroid);
4237 
4238  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4239 
4240  if (OidIsValid(constrForm->conrelid))
4241  appendStringInfoString(buffer, "table constraint");
4242  else if (OidIsValid(constrForm->contypid))
4243  appendStringInfoString(buffer, "domain constraint");
4244  else
4245  elog(ERROR, "invalid constraint %u", constrForm->oid);
4246 
4247  table_close(constrRel, AccessShareLock);
4248 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define AccessShareLock
Definition: lockdefs.h:36
#define OidIsValid(objectId)
Definition: c.h:644
#define ERROR
Definition: elog.h:43
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
FormData_pg_constraint * Form_pg_constraint
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:214
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object)

Definition at line 2753 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), Assert, AttrDefaultOidIndexId, BTEqualStrategyNumber, CastOidIndexId, CLAOID, ObjectAddress::classId, CollationIsVisible(), COLLOID, CONSTROID, ConversionIsVisible(), CONVOID, StringInfoData::data, datname, DefaultAclOidIndexId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_procedure(), format_type_be(), get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectDescription(), getOpFamilyDescription(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), NameStr, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, OpclassIsVisible(), pfree(), PolicyOidIndexId, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), RewriteOidIndexId, ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, StatisticsObjIsVisible(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TRFOID, TriggerOidIndexId, TSConfigIsVisible(), TSCONFIGOID, TSDictionaryIsVisible(), TSDICTOID, TSParserIsVisible(), TSPARSEROID, TSTemplateIsVisible(), TSTEMPLATEOID, and USERMAPPINGOID.

Referenced by AlterExtensionNamespace(), ATExecAlterColumnType(), changeDependenciesOn(), check_relation_privileges(), checkSharedDependencies(), ExecAlterExtensionContentsStmt(), findDependentObjects(), get_object_address_opf_member(), getObjectDescription(), getObjectDescriptionOids(), pg_describe_object(), recordDependencyOnCurrentExtension(), reportDependentObjects(), sepgsql_fmgr_hook(), shdepDropOwned(), shdepReassignOwned(), and storeObjectDescription().

2754 {
2755  StringInfoData buffer;
2756 
2757  initStringInfo(&buffer);
2758 
2759  switch (getObjectClass(object))
2760  {
2761  case OCLASS_CLASS:
2762  if (object->objectSubId == 0)
2763  getRelationDescription(&buffer, object->objectId);
2764  else
2765  {
2766  /* column, not whole relation */
2767  StringInfoData rel;
2768 
2769  initStringInfo(&rel);
2770  getRelationDescription(&rel, object->objectId);
2771  /* translator: second %s is, e.g., "table %s" */
2772  appendStringInfo(&buffer, _("column %s of %s"),
2773  get_attname(object->objectId,
2774  object->objectSubId,
2775  false),
2776  rel.data);
2777  pfree(rel.data);
2778  }
2779  break;
2780 
2781  case OCLASS_PROC:
2782  appendStringInfo(&buffer, _("function %s"),
2783  format_procedure(object->objectId));
2784  break;
2785 
2786  case OCLASS_TYPE:
2787  appendStringInfo(&buffer, _("type %s"),
2788  format_type_be(object->objectId));
2789  break;
2790 
2791  case OCLASS_CAST:
2792  {
2793  Relation castDesc;
2794  ScanKeyData skey[1];
2795  SysScanDesc rcscan;
2796  HeapTuple tup;
2797  Form_pg_cast castForm;
2798 
2799  castDesc = table_open(CastRelationId, AccessShareLock);
2800 
2801  ScanKeyInit(&skey[0],
2802  Anum_pg_cast_oid,
2803  BTEqualStrategyNumber, F_OIDEQ,
2804  ObjectIdGetDatum(object->objectId));
2805 
2806  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2807  NULL, 1, skey);
2808 
2809  tup = systable_getnext(rcscan);
2810 
2811  if (!HeapTupleIsValid(tup))
2812  elog(ERROR, "could not find tuple for cast %u",
2813  object->objectId);
2814 
2815  castForm = (Form_pg_cast) GETSTRUCT(tup);
2816 
2817  appendStringInfo(&buffer, _("cast from %s to %s"),
2818  format_type_be(castForm->castsource),
2819  format_type_be(castForm->casttarget));
2820 
2821  systable_endscan(rcscan);
2822  table_close(castDesc, AccessShareLock);
2823  break;
2824  }
2825 
2826  case OCLASS_COLLATION:
2827  {
2828  HeapTuple collTup;
2829  Form_pg_collation coll;
2830  char *nspname;
2831 
2832  collTup = SearchSysCache1(COLLOID,
2833  ObjectIdGetDatum(object->objectId));
2834  if (!HeapTupleIsValid(collTup))
2835  elog(ERROR, "cache lookup failed for collation %u",
2836  object->objectId);
2837  coll = (Form_pg_collation) GETSTRUCT(collTup);
2838 
2839  /* Qualify the name if not visible in search path */
2840  if (CollationIsVisible(object->objectId))
2841  nspname = NULL;
2842  else
2843  nspname = get_namespace_name(coll->collnamespace);
2844 
2845  appendStringInfo(&buffer, _("collation %s"),
2847  NameStr(coll->collname)));
2848  ReleaseSysCache(collTup);
2849  break;
2850  }
2851 
2852  case OCLASS_CONSTRAINT:
2853  {
2854  HeapTuple conTup;
2855  Form_pg_constraint con;
2856 
2857  conTup = SearchSysCache1(CONSTROID,
2858  ObjectIdGetDatum(object->objectId));
2859  if (!HeapTupleIsValid(conTup))
2860  elog(ERROR, "cache lookup failed for constraint %u",
2861  object->objectId);
2862  con = (Form_pg_constraint) GETSTRUCT(conTup);
2863 
2864  if (OidIsValid(con->conrelid))
2865  {
2866  StringInfoData rel;
2867 
2868  initStringInfo(&rel);
2869  getRelationDescription(&rel, con->conrelid);
2870  /* translator: second %s is, e.g., "table %s" */
2871  appendStringInfo(&buffer, _("constraint %s on %s"),
2872  NameStr(con->conname), rel.data);
2873  pfree(rel.data);
2874  }
2875  else
2876  {
2877  appendStringInfo(&buffer, _("constraint %s"),
2878  NameStr(con->conname));
2879  }
2880 
2881  ReleaseSysCache(conTup);
2882  break;
2883  }
2884 
2885  case OCLASS_CONVERSION:
2886  {
2887  HeapTuple conTup;
2888  Form_pg_conversion conv;
2889  char *nspname;
2890 
2891  conTup = SearchSysCache1(CONVOID,
2892  ObjectIdGetDatum(object->objectId));
2893  if (!HeapTupleIsValid(conTup))
2894  elog(ERROR, "cache lookup failed for conversion %u",
2895  object->objectId);
2896  conv = (Form_pg_conversion) GETSTRUCT(conTup);
2897 
2898  /* Qualify the name if not visible in search path */
2899  if (ConversionIsVisible(object->objectId))
2900  nspname = NULL;
2901  else
2902  nspname = get_namespace_name(conv->connamespace);
2903 
2904  appendStringInfo(&buffer, _("conversion %s"),
2906  NameStr(conv->conname)));
2907  ReleaseSysCache(conTup);
2908  break;
2909  }
2910 
2911  case OCLASS_DEFAULT:
2912  {
2913  Relation attrdefDesc;
2914  ScanKeyData skey[1];
2915  SysScanDesc adscan;
2916  HeapTuple tup;
2917  Form_pg_attrdef attrdef;
2918  ObjectAddress colobject;
2919 
2920  attrdefDesc = table_open(AttrDefaultRelationId, AccessShareLock);
2921 
2922  ScanKeyInit(&skey[0],
2923  Anum_pg_attrdef_oid,
2924  BTEqualStrategyNumber, F_OIDEQ,
2925  ObjectIdGetDatum(object->objectId));
2926 
2927  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
2928  true, NULL, 1, skey);
2929 
2930  tup = systable_getnext(adscan);
2931 
2932  if (!HeapTupleIsValid(tup))
2933  elog(ERROR, "could not find tuple for attrdef %u",
2934  object->objectId);
2935 
2936  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
2937 
2938  colobject.classId = RelationRelationId;
2939  colobject.objectId = attrdef->adrelid;
2940  colobject.objectSubId = attrdef->adnum;
2941 
2942  /* translator: %s is typically "column %s of table %s" */
2943  appendStringInfo(&buffer, _("default value for %s"),
2944  getObjectDescription(&colobject));
2945 
2946  systable_endscan(adscan);
2947  table_close(attrdefDesc, AccessShareLock);
2948  break;
2949  }
2950 
2951  case OCLASS_LANGUAGE:
2952  appendStringInfo(&buffer, _("language %s"),
2953  get_language_name(object->objectId, false));
2954  break;
2955 
2956  case OCLASS_LARGEOBJECT:
2957  appendStringInfo(&buffer, _("large object %u"),
2958  object->objectId);
2959  break;
2960 
2961  case OCLASS_OPERATOR:
2962  appendStringInfo(&buffer, _("operator %s"),
2963  format_operator(object->objectId));
2964  break;
2965 
2966  case OCLASS_OPCLASS:
2967  {
2968  HeapTuple opcTup;
2969  Form_pg_opclass opcForm;
2970  HeapTuple amTup;
2971  Form_pg_am amForm;
2972  char *nspname;
2973 
2974  opcTup = SearchSysCache1(CLAOID,
2975  ObjectIdGetDatum(object->objectId));
2976  if (!HeapTupleIsValid(opcTup))
2977  elog(ERROR, "cache lookup failed for opclass %u",
2978  object->objectId);
2979  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
2980 
2981  amTup = SearchSysCache1(AMOID,
2982  ObjectIdGetDatum(opcForm->opcmethod));
2983  if (!HeapTupleIsValid(amTup))
2984  elog(ERROR, "cache lookup failed for access method %u",
2985  opcForm->opcmethod);
2986  amForm = (Form_pg_am) GETSTRUCT(amTup);
2987 
2988  /* Qualify the name if not visible in search path */
2989  if (OpclassIsVisible(object->objectId))
2990  nspname = NULL;
2991  else
2992  nspname = get_namespace_name(opcForm->opcnamespace);
2993 
2994  appendStringInfo(&buffer, _("operator class %s for access method %s"),
2996  NameStr(opcForm->opcname)),
2997  NameStr(amForm->amname));
2998 
2999  ReleaseSysCache(amTup);
3000  ReleaseSysCache(opcTup);
3001  break;
3002  }
3003 
3004  case OCLASS_OPFAMILY:
3005  getOpFamilyDescription(&buffer, object->objectId);
3006  break;
3007 
3008  case OCLASS_AM:
3009  {
3010  HeapTuple tup;
3011 
3012  tup = SearchSysCache1(AMOID,
3013  ObjectIdGetDatum(object->objectId));
3014  if (!HeapTupleIsValid(tup))
3015  elog(ERROR, "cache lookup failed for access method %u",
3016  object->objectId);
3017  appendStringInfo(&buffer, _("access method %s"),
3018  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3019  ReleaseSysCache(tup);
3020  break;
3021  }
3022 
3023  case OCLASS_AMOP:
3024  {
3025  Relation amopDesc;
3026  HeapTuple tup;
3027  ScanKeyData skey[1];
3028  SysScanDesc amscan;
3029  Form_pg_amop amopForm;
3030  StringInfoData opfam;
3031 
3032  amopDesc = table_open(AccessMethodOperatorRelationId,
3033  AccessShareLock);
3034 
3035  ScanKeyInit(&skey[0],
3036  Anum_pg_amop_oid,
3037  BTEqualStrategyNumber, F_OIDEQ,
3038  ObjectIdGetDatum(object->objectId));
3039 
3040  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
3041  NULL, 1, skey);
3042 
3043  tup = systable_getnext(amscan);
3044 
3045  if (!HeapTupleIsValid(tup))
3046  elog(ERROR, "could not find tuple for amop entry %u",
3047  object->objectId);
3048 
3049  amopForm = (Form_pg_amop) GETSTRUCT(tup);
3050 
3051  initStringInfo(&opfam);
3052  getOpFamilyDescription(&opfam, amopForm->amopfamily);
3053 
3054  /*------
3055  translator: %d is the operator strategy (a number), the
3056  first two %s's are data type names, the third %s is the
3057  description of the operator family, and the last %s is the
3058  textual form of the operator with arguments. */
3059  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3060  amopForm->amopstrategy,
3061  format_type_be(amopForm->amoplefttype),
3062  format_type_be(amopForm->amoprighttype),
3063  opfam.data,
3064  format_operator(amopForm->amopopr));
3065 
3066  pfree(opfam.data);
3067 
3068  systable_endscan(amscan);
3069  table_close(amopDesc, AccessShareLock);
3070  break;
3071  }
3072 
3073  case OCLASS_AMPROC:
3074  {
3075  Relation amprocDesc;
3076  ScanKeyData skey[1];
3077  SysScanDesc amscan;
3078  HeapTuple tup;
3079  Form_pg_amproc amprocForm;
3080  StringInfoData opfam;
3081 
3082  amprocDesc = table_open(AccessMethodProcedureRelationId,
3083  AccessShareLock);
3084 
3085  ScanKeyInit(&skey[0],
3086  Anum_pg_amproc_oid,
3087  BTEqualStrategyNumber, F_OIDEQ,
3088  ObjectIdGetDatum(object->objectId));
3089 
3090  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
3091  NULL, 1, skey);
3092 
3093  tup = systable_getnext(amscan);
3094 
3095  if (!HeapTupleIsValid(tup))
3096  elog(ERROR, "could not find tuple for amproc entry %u",
3097  object->objectId);
3098 
3099  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
3100 
3101  initStringInfo(&opfam);
3102  getOpFamilyDescription(&opfam, amprocForm->amprocfamily);
3103 
3104  /*------
3105  translator: %d is the function number, the first two %s's
3106  are data type names, the third %s is the description of the
3107  operator family, and the last %s is the textual form of the
3108  function with arguments. */
3109  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3110  amprocForm->amprocnum,
3111  format_type_be(amprocForm->amproclefttype),
3112  format_type_be(amprocForm->amprocrighttype),
3113  opfam.data,
3114  format_procedure(amprocForm->amproc));
3115 
3116  pfree(opfam.data);
3117 
3118  systable_endscan(amscan);
3119  table_close(amprocDesc, AccessShareLock);
3120  break;
3121  }
3122 
3123  case OCLASS_REWRITE:
3124  {
3125  Relation ruleDesc;
3126  ScanKeyData skey[1];
3127  SysScanDesc rcscan;
3128  HeapTuple tup;
3130  StringInfoData rel;
3131 
3132  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
3133 
3134  ScanKeyInit(&skey[0],
3135  Anum_pg_rewrite_oid,
3136  BTEqualStrategyNumber, F_OIDEQ,
3137  ObjectIdGetDatum(object->objectId));
3138 
3139  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3140  NULL, 1, skey);
3141 
3142  tup = systable_getnext(rcscan);
3143 
3144  if (!HeapTupleIsValid(tup))
3145  elog(ERROR, "could not find tuple for rule %u",
3146  object->objectId);
3147  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3148 
3149  initStringInfo(&rel);
3150  getRelationDescription(&rel, rule->ev_class);
3151 
3152  /* translator: second %s is, e.g., "table %s" */
3153  appendStringInfo(&buffer, _("rule %s on %s"),
3154  NameStr(rule->rulename), rel.data);
3155  pfree(rel.data);
3156  systable_endscan(rcscan);
3157  table_close(ruleDesc, AccessShareLock);
3158  break;
3159  }
3160 
3161  case OCLASS_TRIGGER:
3162  {
3163  Relation trigDesc;
3164  ScanKeyData skey[1];
3165  SysScanDesc tgscan;
3166  HeapTuple tup;
3167  Form_pg_trigger trig;
3168  StringInfoData rel;
3169 
3170  trigDesc = table_open(TriggerRelationId, AccessShareLock);
3171 
3172  ScanKeyInit(&skey[0],
3173  Anum_pg_trigger_oid,
3174  BTEqualStrategyNumber, F_OIDEQ,
3175  ObjectIdGetDatum(object->objectId));
3176 
3177  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3178  NULL, 1, skey);
3179 
3180  tup = systable_getnext(tgscan);
3181 
3182  if (!HeapTupleIsValid(tup))
3183  elog(ERROR, "could not find tuple for trigger %u",
3184  object->objectId);
3185  trig = (Form_pg_trigger) GETSTRUCT(tup);
3186 
3187  initStringInfo(&rel);
3188  getRelationDescription(&rel, trig->tgrelid);
3189 
3190  /* translator: second %s is, e.g., "table %s" */
3191  appendStringInfo(&buffer, _("trigger %s on %s"),
3192  NameStr(trig->tgname), rel.data);
3193  pfree(rel.data);
3194  systable_endscan(tgscan);
3195  table_close(trigDesc, AccessShareLock);
3196  break;
3197  }
3198 
3199  case OCLASS_SCHEMA:
3200  {
3201  char *nspname;
3202 
3203  nspname = get_namespace_name(object->objectId);
3204  if (!nspname)
3205  elog(ERROR, "cache lookup failed for namespace %u",
3206  object->objectId);
3207  appendStringInfo(&buffer, _("schema %s"), nspname);
3208  break;
3209  }
3210 
3211  case OCLASS_STATISTIC_EXT:
3212  {
3213  HeapTuple stxTup;
3214  Form_pg_statistic_ext stxForm;
3215  char *nspname;
3216 
3217  stxTup = SearchSysCache1(STATEXTOID,
3218  ObjectIdGetDatum(object->objectId));
3219  if (!HeapTupleIsValid(stxTup))
3220  elog(ERROR, "could not find tuple for statistics object %u",
3221  object->objectId);
3222  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3223 
3224  /* Qualify the name if not visible in search path */
3225  if (StatisticsObjIsVisible(object->objectId))
3226  nspname = NULL;
3227  else
3228  nspname = get_namespace_name(stxForm->stxnamespace);
3229 
3230  appendStringInfo(&buffer, _("statistics object %s"),
3232  NameStr(stxForm->stxname)));
3233 
3234  ReleaseSysCache(stxTup);
3235  break;
3236  }
3237 
3238  case OCLASS_TSPARSER:
3239  {
3240  HeapTuple tup;
3241  Form_pg_ts_parser prsForm;
3242  char *nspname;
3243 
3245  ObjectIdGetDatum(object->objectId));
3246  if (!HeapTupleIsValid(tup))
3247  elog(ERROR, "cache lookup failed for text search parser %u",
3248  object->objectId);
3249  prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3250 
3251  /* Qualify the name if not visible in search path */
3252  if (TSParserIsVisible(object->objectId))
3253  nspname = NULL;
3254  else
3255  nspname = get_namespace_name(prsForm->prsnamespace);
3256 
3257  appendStringInfo(&buffer, _("text search parser %s"),
3259  NameStr(prsForm->prsname)));
3260  ReleaseSysCache(tup);
3261  break;
3262  }
3263 
3264  case OCLASS_TSDICT:
3265  {
3266  HeapTuple tup;
3267  Form_pg_ts_dict dictForm;
3268  char *nspname;
3269 
3270  tup = SearchSysCache1(TSDICTOID,
3271  ObjectIdGetDatum(object->objectId));
3272  if (!HeapTupleIsValid(tup))
3273  elog(ERROR, "cache lookup failed for text search dictionary %u",
3274  object->objectId);
3275  dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3276 
3277  /* Qualify the name if not visible in search path */
3278  if (TSDictionaryIsVisible(object->objectId))
3279  nspname = NULL;
3280  else
3281  nspname = get_namespace_name(dictForm->dictnamespace);
3282 
3283  appendStringInfo(&buffer, _("text search dictionary %s"),
3285  NameStr(dictForm->dictname)));
3286  ReleaseSysCache(tup);
3287  break;
3288  }
3289 
3290  case OCLASS_TSTEMPLATE:
3291  {
3292  HeapTuple tup;
3293  Form_pg_ts_template tmplForm;
3294  char *nspname;
3295 
3297  ObjectIdGetDatum(object->objectId));
3298  if (!HeapTupleIsValid(tup))
3299  elog(ERROR, "cache lookup failed for text search template %u",
3300  object->objectId);
3301  tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3302 
3303  /* Qualify the name if not visible in search path */
3304  if (TSTemplateIsVisible(object->objectId))
3305  nspname = NULL;
3306  else
3307  nspname = get_namespace_name(tmplForm->tmplnamespace);
3308 
3309  appendStringInfo(&buffer, _("text search template %s"),
3311  NameStr(tmplForm->tmplname)));
3312  ReleaseSysCache(tup);
3313  break;
3314  }
3315 
3316  case OCLASS_TSCONFIG:
3317  {
3318  HeapTuple tup;
3319  Form_pg_ts_config cfgForm;
3320  char *nspname;
3321 
3323  ObjectIdGetDatum(object->objectId));
3324  if (!HeapTupleIsValid(tup))
3325  elog(ERROR, "cache lookup failed for text search configuration %u",
3326  object->objectId);
3327  cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3328 
3329  /* Qualify the name if not visible in search path */
3330  if (TSConfigIsVisible(object->objectId))
3331  nspname = NULL;
3332  else
3333  nspname = get_namespace_name(cfgForm->cfgnamespace);
3334 
3335  appendStringInfo(&buffer, _("text search configuration %s"),
3337  NameStr(cfgForm->cfgname)));
3338  ReleaseSysCache(tup);
3339  break;
3340  }
3341 
3342  case OCLASS_ROLE:
3343  {
3344  appendStringInfo(&buffer, _("role %s"),
3345  GetUserNameFromId(object->objectId, false));
3346  break;
3347  }
3348 
3349  case OCLASS_DATABASE:
3350  {
3351  char *datname;
3352 
3353  datname = get_database_name(object->objectId);
3354  if (!datname)
3355  elog(ERROR, "cache lookup failed for database %u",
3356  object->objectId);
3357  appendStringInfo(&buffer, _("database %s"), datname);
3358  break;
3359  }
3360 
3361  case OCLASS_TBLSPACE:
3362  {
3363  char *tblspace;
3364 
3365  tblspace = get_tablespace_name(object->objectId);
3366  if (!tblspace)
3367  elog(ERROR, "cache lookup failed for tablespace %u",
3368  object->objectId);
3369  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3370  break;
3371  }
3372 
3373  case OCLASS_FDW:
3374  {
3375  ForeignDataWrapper *fdw;
3376 
3377  fdw = GetForeignDataWrapper(object->objectId);
3378  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3379  break;
3380  }
3381 
3382  case OCLASS_FOREIGN_SERVER:
3383  {
3384  ForeignServer *srv;
3385 
3386  srv = GetForeignServer(object->objectId);
3387  appendStringInfo(&buffer, _("server %s"), srv->servername);
3388  break;
3389  }
3390 
3391  case OCLASS_USER_MAPPING:
3392  {
3393  HeapTuple tup;
3394  Oid useid;
3395  char *usename;
3396  Form_pg_user_mapping umform;
3397  ForeignServer *srv;
3398 
3400  ObjectIdGetDatum(object->objectId));
3401  if (!HeapTupleIsValid(tup))
3402  elog(ERROR, "cache lookup failed for user mapping %u",
3403  object->objectId);
3404  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3405  useid = umform->umuser;
3406  srv = GetForeignServer(umform->umserver);
3407 
3408  ReleaseSysCache(tup);
3409 
3410  if (OidIsValid(useid))
3411  usename = GetUserNameFromId(useid, false);
3412  else
3413  usename = "public";
3414 
3415  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3416  srv->servername);
3417  break;
3418  }
3419 
3420  case OCLASS_DEFACL:
3421  {
3422  Relation defaclrel;
3423  ScanKeyData skey[1];
3424  SysScanDesc rcscan;
3425  HeapTuple tup;
3426  Form_pg_default_acl defacl;
3427  char *rolename;
3428  char *nspname;
3429 
3430  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
3431 
3432  ScanKeyInit(&skey[0],
3433  Anum_pg_default_acl_oid,
3434  BTEqualStrategyNumber, F_OIDEQ,
3435  ObjectIdGetDatum(object->objectId));
3436 
3437  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3438  true, NULL, 1, skey);
3439 
3440  tup = systable_getnext(rcscan);
3441 
3442  if (!HeapTupleIsValid(tup))
3443  elog(ERROR, "could not find tuple for default ACL %u",
3444  object->objectId);
3445 
3446  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3447 
3448  rolename = GetUserNameFromId(defacl->defaclrole, false);
3449 
3450  if (OidIsValid(defacl->defaclnamespace))
3451  nspname = get_namespace_name(defacl->defaclnamespace);
3452  else
3453  nspname = NULL;
3454 
3455  switch (defacl->defaclobjtype)
3456  {
3457  case DEFACLOBJ_RELATION:
3458  if (nspname)
3459  appendStringInfo(&buffer,
3460  _("default privileges on new relations belonging to role %s in schema %s"),
3461  rolename, nspname);
3462  else
3463  appendStringInfo(&buffer,
3464  _("default privileges on new relations belonging to role %s"),
3465  rolename);
3466  break;
3467  case DEFACLOBJ_SEQUENCE:
3468  if (nspname)
3469  appendStringInfo(&buffer,
3470  _("default privileges on new sequences belonging to role %s in schema %s"),
3471  rolename, nspname);
3472  else
3473  appendStringInfo(&buffer,
3474  _("default privileges on new sequences belonging to role %s"),
3475  rolename);
3476  break;
3477  case DEFACLOBJ_FUNCTION:
3478  if (nspname)
3479  appendStringInfo(&buffer,
3480  _("default privileges on new functions belonging to role %s in schema %s"),
3481  rolename, nspname);
3482  else
3483  appendStringInfo(&buffer,
3484  _("default privileges on new functions belonging to role %s"),
3485  rolename);
3486  break;
3487  case DEFACLOBJ_TYPE:
3488  if (nspname)
3489  appendStringInfo(&buffer,
3490  _("default privileges on new types belonging to role %s in schema %s"),
3491  rolename, nspname);
3492  else
3493  appendStringInfo(&buffer,
3494  _("default privileges on new types belonging to role %s"),
3495  rolename);
3496  break;
3497  case DEFACLOBJ_NAMESPACE:
3498  Assert(!nspname);
3499  appendStringInfo(&buffer,
3500  _("default privileges on new schemas belonging to role %s"),
3501  rolename);
3502  break;
3503  default:
3504  /* shouldn't get here */
3505  if (nspname)
3506  appendStringInfo(&buffer,
3507  _("default privileges belonging to role %s in schema %s"),
3508  rolename, nspname);
3509  else
3510  appendStringInfo(&buffer,
3511  _("default privileges belonging to role %s"),
3512  rolename);
3513  break;
3514  }
3515 
3516  systable_endscan(rcscan);
3517  table_close(defaclrel, AccessShareLock);
3518  break;
3519  }
3520 
3521  case OCLASS_EXTENSION:
3522  {
3523  char *extname;
3524 
3525  extname = get_extension_name(object->objectId);
3526  if (!extname)
3527  elog(ERROR, "cache lookup failed for extension %u",
3528  object->objectId);
3529  appendStringInfo(&buffer, _("extension %s"), extname);
3530  break;
3531  }
3532 
3533  case OCLASS_EVENT_TRIGGER:
3534  {
3535  HeapTuple tup;
3536 
3538  ObjectIdGetDatum(object->objectId));
3539  if (!HeapTupleIsValid(tup))
3540  elog(ERROR, "cache lookup failed for event trigger %u",
3541  object->objectId);
3542  appendStringInfo(&buffer, _("event trigger %s"),
3543  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3544  ReleaseSysCache(tup);
3545  break;
3546  }
3547 
3548  case OCLASS_POLICY:
3549  {
3550  Relation policy_rel;
3551  ScanKeyData skey[1];
3552  SysScanDesc sscan;
3553  HeapTuple tuple;
3554  Form_pg_policy form_policy;
3555  StringInfoData rel;
3556 
3557  policy_rel = table_open(PolicyRelationId, AccessShareLock);
3558 
3559  ScanKeyInit(&skey[0],
3560  Anum_pg_policy_oid,
3561  BTEqualStrategyNumber, F_OIDEQ,
3562  ObjectIdGetDatum(object->objectId));
3563 
3564  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3565  true, NULL, 1, skey);
3566 
3567  tuple = systable_getnext(sscan);
3568 
3569  if (!HeapTupleIsValid(tuple))
3570  elog(ERROR, "could not find tuple for policy %u",
3571  object->objectId);
3572  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3573 
3574  initStringInfo(&rel);
3575  getRelationDescription(&rel, form_policy->polrelid);
3576 
3577  /* translator: second %s is, e.g., "table %s" */
3578  appendStringInfo(&buffer, _("policy %s on %s"),
3579  NameStr(form_policy->polname), rel.data);
3580  pfree(rel.data);
3581  systable_endscan(sscan);
3582  table_close(policy_rel, AccessShareLock);
3583  break;
3584  }
3585 
3586  case OCLASS_PUBLICATION:
3587  {
3588  appendStringInfo(&buffer, _("publication %s"),
3590  false));
3591  break;
3592  }
3593 
3595  {
3596  HeapTuple tup;
3597  char *pubname;
3598  Form_pg_publication_rel prform;
3599  StringInfoData rel;
3600 
3602  ObjectIdGetDatum(object->objectId));
3603  if (!HeapTupleIsValid(tup))
3604  elog(ERROR, "cache lookup failed for publication table %u",
3605  object->objectId);
3606 
3607  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3608  pubname = get_publication_name(prform->prpubid, false);
3609 
3610  initStringInfo(&rel);
3611  getRelationDescription(&rel, prform->prrelid);
3612 
3613  /* translator: first %s is, e.g., "table %s" */
3614  appendStringInfo(&buffer, _("publication of %s in publication %s"),
3615  rel.data, pubname);
3616  pfree(rel.data);
3617  ReleaseSysCache(tup);
3618  break;
3619  }
3620 
3621  case OCLASS_SUBSCRIPTION:
3622  {
3623  appendStringInfo(&buffer, _("subscription %s"),
3625  false));
3626  break;
3627  }
3628 
3629  case OCLASS_TRANSFORM:
3630  {
3631  HeapTuple trfTup;
3632  Form_pg_transform trfForm;
3633 
3634  trfTup = SearchSysCache1(TRFOID,
3635  ObjectIdGetDatum(object->objectId));
3636  if (!HeapTupleIsValid(trfTup))
3637  elog(ERROR, "could not find tuple for transform %u",
3638  object->objectId);
3639 
3640  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
3641 
3642  appendStringInfo(&buffer, _("transform for %s language %s"),
3643  format_type_be(trfForm->trftype),
3644  get_language_name(trfForm->trflang, false));
3645 
3646  ReleaseSysCache(trfTup);
3647  break;
3648  }
3649 
3650  /*
3651  * There's intentionally no default: case here; we want the
3652  * compiler to warn if a new OCLASS hasn't been handled above.
3653  */
3654  }
3655 
3656  return buffer.data;
3657 }
#define RewriteOidIndexId
Definition: indexing.h:215
#define TriggerOidIndexId
Definition: indexing.h:255
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:529
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Definition: syscache.h:36
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1051
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
char * fdwname
Definition: foreign.h:28
#define PolicyOidIndexId
Definition: indexing.h:331
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
char * get_extension_name(Oid ext_oid)
Definition: extension.c:185
#define DefaultAclOidIndexId
Definition: indexing.h:311
#define AccessShareLock
Definition: lockdefs.h:36
bool StatisticsObjIsVisible(Oid relid)
Definition: namespace.c:2235
static void getOpFamilyDescription(StringInfo buffer, Oid opfid)
#define AttrDefaultOidIndexId
Definition: indexing.h:91
#define AccessMethodOperatorOidIndexId
Definition: indexing.h:81
char * format_type_be(Oid type_oid)
Definition: format_type.c:327
NameData datname
Definition: pg_database.h:35
char * format_operator(Oid operator_oid)
Definition: regproc.c:821
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2725
#define OidIsValid(objectId)
Definition: c.h:644
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:356
char * get_publication_name(Oid pubid, bool missing_ok)
char * getObjectDescription(const ObjectAddress *object)
Definition: localtime.c:79
char * get_subscription_name(Oid subid, bool missing_ok)
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:86
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:448
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
void pfree(void *pointer)
Definition: mcxt.c:1056
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:43
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2737
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2155
FormData_pg_user_mapping * Form_pg_user_mapping
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52
FormData_pg_default_acl * Form_pg_default_acl
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3155
#define CastOidIndexId
Definition: indexing.h:109
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2048
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2484
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10808
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:109
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:55
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:61
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1833
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:50
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:324
static void getRelationDescription(StringInfo buffer, Oid relid)
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2131
FormData_pg_constraint * Form_pg_constraint
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:854
#define Assert(condition)
Definition: c.h:738
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:72
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:2611
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2358
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1462
char * servername
Definition: foreign.h:39
FormData_pg_ts_template * Form_pg_ts_template
#define elog(elevel,...)
Definition: elog.h:214
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:615
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:776
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:83
#define _(x)
Definition: elog.c:88
#define BTEqualStrategyNumber
Definition: stratnum.h:31
FormData_pg_statistic_ext * Form_pg_statistic_ext

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3663 of file objectaddress.c.

References ObjectAddress::classId, getObjectDescription(), ObjectAddress::objectId, and ObjectAddress::objectSubId.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3664 {
3665  ObjectAddress address;
3666 
3667  address.classId = classid;
3668  address.objectId = objid;
3669  address.objectSubId = 0;
3670 
3671  return getObjectDescription(&address);
3672 }
char * getObjectDescription(const ObjectAddress *object)

◆ getObjectIdentity()

◆ getObjectIdentityParts()

char* getObjectIdentityParts ( const ObjectAddress object,
List **  objname,
List **  objargs 
)

Definition at line 4296 of file objectaddress.c.

References AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert, AttrDefaultOidIndexId, BTEqualStrategyNumber, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, datname, DefaultAclOidIndexId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator_parts(), format_operator_qualified(), format_procedure_parts(), format_procedure_qualified(), format_type_be_qualified(), get_am_name(), get_attname(), get_catalog_object_by_oid(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name_or_temp(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectIdentityParts(), getOpFamilyIdentity(), getRelationIdentity(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LANGOID, lappend(), list_make1, list_make2, list_make3, NameStr, NIL, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, pfree(), PointerIsValid, psprintf(), pstrdup(), PUBLICATIONREL, quote_identifier(), quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, subname, systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TSCONFIGOID, TSDICTOID, TSPARSEROID, TSTEMPLATEOID, USERMAPPINGOID, and username.

Referenced by EventTriggerSQLDropAddObject(), getObjectIdentity(), getObjectIdentityParts(), and pg_identify_object_as_address().

4298 {
4299  StringInfoData buffer;
4300 
4301  initStringInfo(&buffer);
4302 
4303  /*
4304  * Make sure that both objname and objargs were passed, or none was; and
4305  * initialize them to empty lists. For objname this is useless because it
4306  * will be initialized in all cases inside the switch; but we do it anyway
4307  * so that we can test below that no branch leaves it unset.
4308  */
4309  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4310  if (objname)
4311  {
4312  *objname = NIL;
4313  *objargs = NIL;
4314  }
4315 
4316  switch (getObjectClass(object))
4317  {
4318  case OCLASS_CLASS:
4319  getRelationIdentity(&buffer, object->objectId, objname);
4320  if (object->objectSubId != 0)
4321  {
4322  char *attr;
4323 
4324  attr = get_attname(object->objectId, object->objectSubId,
4325  false);
4326  appendStringInfo(&buffer, ".%s", quote_identifier(attr));
4327  if (objname)
4328  *objname = lappend(*objname, attr);
4329  }
4330  break;
4331 
4332  case OCLASS_PROC:
4333  appendStringInfoString(&buffer,
4335  if (objname)
4336  format_procedure_parts(object->objectId, objname, objargs);
4337  break;
4338 
4339  case OCLASS_TYPE:
4340  {
4341  char *typeout;
4342 
4343  typeout = format_type_be_qualified(object->objectId);
4344  appendStringInfoString(&buffer, typeout);
4345  if (objname)
4346  *objname = list_make1(typeout);
4347  }
4348  break;
4349 
4350  case OCLASS_CAST:
4351  {
4352  Relation castRel;
4353  HeapTuple tup;
4354  Form_pg_cast castForm;
4355 
4356  castRel = table_open(CastRelationId, AccessShareLock);
4357 
4358  tup = get_catalog_object_by_oid(castRel, Anum_pg_cast_oid,
4359  object->objectId);
4360 
4361  if (!HeapTupleIsValid(tup))
4362  elog(ERROR, "could not find tuple for cast %u",
4363  object->objectId);
4364 
4365  castForm = (Form_pg_cast) GETSTRUCT(tup);
4366 
4367  appendStringInfo(&buffer, "(%s AS %s)",
4368  format_type_be_qualified(castForm->castsource),
4369  format_type_be_qualified(castForm->casttarget));
4370 
4371  if (objname)
4372  {
4373  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4374  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4375  }
4376 
4377  table_close(castRel, AccessShareLock);
4378  break;
4379  }
4380 
4381  case OCLASS_COLLATION:
4382  {
4383  HeapTuple collTup;
4384  Form_pg_collation coll;
4385  char *schema;
4386 
4387  collTup = SearchSysCache1(COLLOID,
4388  ObjectIdGetDatum(object->objectId));
4389  if (!HeapTupleIsValid(collTup))
4390  elog(ERROR, "cache lookup failed for collation %u",
4391  object->objectId);
4392  coll = (Form_pg_collation) GETSTRUCT(collTup);
4393  schema = get_namespace_name_or_temp(coll->collnamespace);
4394  appendStringInfoString(&buffer,
4396  NameStr(coll->collname)));
4397  if (objname)
4398  *objname = list_make2(schema,
4399  pstrdup(NameStr(coll->collname)));
4400  ReleaseSysCache(collTup);
4401  break;
4402  }
4403 
4404  case OCLASS_CONSTRAINT:
4405  {
4406  HeapTuple conTup;
4407  Form_pg_constraint con;
4408 
4409  conTup = SearchSysCache1(CONSTROID,
4410  ObjectIdGetDatum(object->objectId));
4411  if (!HeapTupleIsValid(conTup))
4412  elog(ERROR, "cache lookup failed for constraint %u",
4413  object->objectId);
4414  con = (Form_pg_constraint) GETSTRUCT(conTup);
4415 
4416  if (OidIsValid(con->conrelid))
4417  {
4418  appendStringInfo(&buffer, "%s on ",
4419  quote_identifier(NameStr(con->conname)));
4420  getRelationIdentity(&buffer, con->conrelid, objname);
4421  if (objname)
4422  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4423  }
4424  else
4425  {
4426  ObjectAddress domain;
4427 
4428  Assert(OidIsValid(con->contypid));
4429  domain.classId = TypeRelationId;
4430  domain.objectId = con->contypid;
4431  domain.objectSubId = 0;
4432 
4433  appendStringInfo(&buffer, "%s on %s",
4434  quote_identifier(NameStr(con->conname)),
4435  getObjectIdentityParts(&domain, objname, objargs));
4436 
4437  if (objname)
4438  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4439  }
4440 
4441  ReleaseSysCache(conTup);
4442  break;
4443  }
4444 
4445  case OCLASS_CONVERSION:
4446  {
4447  HeapTuple conTup;
4448  Form_pg_conversion conForm;
4449  char *schema;
4450 
4451  conTup = SearchSysCache1(CONVOID,
4452  ObjectIdGetDatum(object->objectId));
4453  if (!HeapTupleIsValid(conTup))
4454  elog(ERROR, "cache lookup failed for conversion %u",
4455  object->objectId);
4456  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4457  schema = get_namespace_name_or_temp(conForm->connamespace);
4458  appendStringInfoString(&buffer,
4460  NameStr(conForm->conname)));
4461  if (objname)
4462  *objname = list_make2(schema,
4463  pstrdup(NameStr(conForm->conname)));
4464  ReleaseSysCache(conTup);
4465  break;
4466  }
4467 
4468  case OCLASS_DEFAULT:
4469  {
4470  Relation attrdefDesc;
4471  ScanKeyData skey[1];
4472  SysScanDesc adscan;
4473 
4474  HeapTuple tup;
4475  Form_pg_attrdef attrdef;
4476  ObjectAddress colobject;
4477 
4478  attrdefDesc = table_open(AttrDefaultRelationId, AccessShareLock);
4479 
4480  ScanKeyInit(&skey[0],
4481  Anum_pg_attrdef_oid,
4482  BTEqualStrategyNumber, F_OIDEQ,
4483  ObjectIdGetDatum(object->objectId));
4484 
4485  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
4486  true, NULL, 1, skey);
4487 
4488  tup = systable_getnext(adscan);
4489 
4490  if (!HeapTupleIsValid(tup))
4491  elog(ERROR, "could not find tuple for attrdef %u",
4492  object->objectId);
4493 
4494  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
4495 
4496  colobject.classId = RelationRelationId;
4497  colobject.objectId = attrdef->adrelid;
4498  colobject.objectSubId = attrdef->adnum;
4499 
4500  appendStringInfo(&buffer, "for %s",
4501  getObjectIdentityParts(&colobject,
4502  objname, objargs));
4503 
4504  systable_endscan(adscan);
4505  table_close(attrdefDesc, AccessShareLock);
4506  break;
4507  }
4508 
4509  case OCLASS_LANGUAGE:
4510  {
4511  HeapTuple langTup;
4512  Form_pg_language langForm;
4513 
4514  langTup = SearchSysCache1(LANGOID,
4515  ObjectIdGetDatum(object->objectId));
4516  if (!HeapTupleIsValid(langTup))
4517  elog(ERROR, "cache lookup failed for language %u",
4518  object->objectId);
4519  langForm = (Form_pg_language) GETSTRUCT(langTup);
4520  appendStringInfoString(&buffer,
4521  quote_identifier(NameStr(langForm->lanname)));
4522  if (objname)
4523  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
4524  ReleaseSysCache(langTup);
4525  break;
4526  }
4527  case OCLASS_LARGEOBJECT:
4528  appendStringInfo(&buffer, "%u",
4529  object->objectId);
4530  if (objname)
4531  *objname = list_make1(psprintf("%u", object->objectId));
4532  break;
4533 
4534  case OCLASS_OPERATOR:
4535  appendStringInfoString(&buffer,
4537  if (objname)
4538  format_operator_parts(object->objectId, objname, objargs);
4539  break;
4540 
4541  case OCLASS_OPCLASS:
4542  {
4543  HeapTuple opcTup;
4544  Form_pg_opclass opcForm;
4545  HeapTuple amTup;
4546  Form_pg_am amForm;
4547  char *schema;
4548 
4549  opcTup = SearchSysCache1(CLAOID,
4550  ObjectIdGetDatum(object->objectId));
4551  if (!HeapTupleIsValid(opcTup))
4552  elog(ERROR, "cache lookup failed for opclass %u",
4553  object->objectId);
4554  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
4555  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
4556 
4557  amTup = SearchSysCache1(AMOID,
4558  ObjectIdGetDatum(opcForm->opcmethod));
4559  if (!HeapTupleIsValid(amTup))
4560  elog(ERROR, "cache lookup failed for access method %u",
4561  opcForm->opcmethod);
4562  amForm = (Form_pg_am) GETSTRUCT(amTup);
4563 
4564  appendStringInfo(&buffer, "%s USING %s",
4566  NameStr(opcForm->opcname)),
4567  quote_identifier(NameStr(amForm->amname)));
4568  if (objname)
4569  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
4570  schema,
4571  pstrdup(NameStr(opcForm->opcname)));
4572 
4573  ReleaseSysCache(amTup);
4574  ReleaseSysCache(opcTup);
4575  break;
4576  }
4577 
4578  case OCLASS_OPFAMILY:
4579  getOpFamilyIdentity(&buffer, object->objectId, objname);
4580  break;
4581 
4582  case OCLASS_AM:
4583  {
4584  char *amname;
4585 
4586  amname = get_am_name(object->objectId);
4587  if (!amname)
4588  elog(ERROR, "cache lookup failed for access method %u",
4589  object->objectId);
4590  appendStringInfoString(&buffer, quote_identifier(amname));
4591  if (objname)
4592  *objname = list_make1(amname);
4593  }
4594  break;
4595 
4596  case OCLASS_AMOP:
4597  {
4598  Relation amopDesc;
4599  HeapTuple tup;
4600  ScanKeyData skey[1];
4601  SysScanDesc amscan;
4602  Form_pg_amop amopForm;
4603  StringInfoData opfam;
4604  char *ltype;
4605  char *rtype;
4606 
4607  amopDesc = table_open(AccessMethodOperatorRelationId,
4608  AccessShareLock);
4609 
4610  ScanKeyInit(&skey[0],
4611  Anum_pg_amop_oid,
4612  BTEqualStrategyNumber, F_OIDEQ,
4613  ObjectIdGetDatum(object->objectId));
4614 
4615  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
4616  NULL, 1, skey);
4617 
4618  tup = systable_getnext(amscan);
4619 
4620  if (!HeapTupleIsValid(tup))
4621  elog(ERROR, "could not find tuple for amop entry %u",
4622  object->objectId);
4623 
4624  amopForm = (Form_pg_amop) GETSTRUCT(tup);
4625 
4626  initStringInfo(&opfam);
4627  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname);
4628 
4629  ltype = format_type_be_qualified(amopForm->amoplefttype);
4630  rtype = format_type_be_qualified(amopForm->amoprighttype);
4631 
4632  if (objname)
4633  {
4634  *objname = lappend(*objname,
4635  psprintf("%d", amopForm->amopstrategy));
4636  *objargs = list_make2(ltype, rtype);
4637  }
4638 
4639  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
4640  amopForm->amopstrategy,
4641  ltype, rtype, opfam.data);
4642 
4643  pfree(opfam.data);
4644 
4645  systable_endscan(amscan);
4646  table_close(amopDesc, AccessShareLock);
4647  break;
4648  }
4649 
4650  case OCLASS_AMPROC:
4651  {
4652  Relation amprocDesc;
4653  ScanKeyData skey[1];
4654  SysScanDesc amscan;
4655  HeapTuple tup;
4656  Form_pg_amproc amprocForm;
4657  StringInfoData opfam;
4658  char *ltype;
4659  char *rtype;
4660 
4661  amprocDesc = table_open(AccessMethodProcedureRelationId,
4662  AccessShareLock);
4663 
4664  ScanKeyInit(&skey[0],
4665  Anum_pg_amproc_oid,
4666  BTEqualStrategyNumber, F_OIDEQ,
4667  ObjectIdGetDatum(object->objectId));
4668 
4669  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
4670  NULL, 1, skey);
4671 
4672  tup = systable_getnext(amscan);
4673 
4674  if (!HeapTupleIsValid(tup))
4675  elog(ERROR, "could not find tuple for amproc entry %u",
4676  object->objectId);
4677 
4678  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
4679 
4680  initStringInfo(&opfam);
4681  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname);
4682 
4683  ltype = format_type_be_qualified(amprocForm->amproclefttype);
4684  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
4685 
4686  if (objname)
4687  {
4688  *objname = lappend(*objname,
4689  psprintf("%d", amprocForm->amprocnum));
4690  *objargs = list_make2(ltype, rtype);
4691  }
4692 
4693  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
4694  amprocForm->amprocnum,
4695  ltype, rtype, opfam.data);
4696 
4697  pfree(opfam.data);
4698 
4699  systable_endscan(amscan);
4700  table_close(amprocDesc, AccessShareLock);
4701  break;
4702  }
4703 
4704  case OCLASS_REWRITE:
4705  {
4706  Relation ruleDesc;
4707  HeapTuple tup;
4709 
4710  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
4711 
4712  tup = get_catalog_object_by_oid(ruleDesc, Anum_pg_rewrite_oid,
4713  object->objectId);
4714 
4715  if (!HeapTupleIsValid(tup))
4716  elog(ERROR, "could not find tuple for rule %u",
4717  object->objectId);
4718 
4719  rule = (Form_pg_rewrite) GETSTRUCT(tup);
4720 
4721  appendStringInfo(&buffer, "%s on ",
4722  quote_identifier(NameStr(rule->rulename)));
4723  getRelationIdentity(&buffer, rule->ev_class, objname);
4724  if (objname)
4725  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
4726 
4727  table_close(ruleDesc, AccessShareLock);
4728  break;
4729  }
4730 
4731  case OCLASS_TRIGGER:
4732  {
4733  Relation trigDesc;
4734  HeapTuple tup;
4735  Form_pg_trigger trig;
4736 
4737  trigDesc = table_open(TriggerRelationId, AccessShareLock);
4738 
4739  tup = get_catalog_object_by_oid(trigDesc, Anum_pg_trigger_oid,
4740  object->objectId);
4741 
4742  if (!HeapTupleIsValid(tup))
4743  elog(ERROR, "could not find tuple for trigger %u",
4744  object->objectId);
4745 
4746  trig = (Form_pg_trigger) GETSTRUCT(tup);
4747 
4748  appendStringInfo(&buffer, "%s on ",
4749  quote_identifier(NameStr(trig->tgname)));
4750  getRelationIdentity(&buffer, trig->tgrelid, objname);
4751  if (objname)
4752  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
4753 
4754  table_close(trigDesc, AccessShareLock);
4755  break;
4756  }
4757 
4758  case OCLASS_SCHEMA:
4759  {
4760  char *nspname;
4761 
4762  nspname = get_namespace_name_or_temp(object->objectId);
4763  if (!nspname)
4764  elog(ERROR, "cache lookup failed for namespace %u",
4765  object->objectId);
4766  appendStringInfoString(&buffer,
4767  quote_identifier(nspname));
4768  if (objname)
4769  *objname = list_make1(nspname);
4770  break;
4771  }
4772 
4773  case OCLASS_STATISTIC_EXT:
4774  {
4775  HeapTuple tup;
4776  Form_pg_statistic_ext formStatistic;
4777  char *schema;
4778 
4780  ObjectIdGetDatum(object->objectId));
4781  if (!HeapTupleIsValid(tup))
4782  elog(ERROR, "cache lookup failed for statistics object %u",
4783  object->objectId);
4784  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
4785  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
4786  appendStringInfoString(&buffer,
4788  NameStr(formStatistic->stxname)));
4789  if (objname)
4790  *objname = list_make2(schema,
4791  pstrdup(NameStr(formStatistic->stxname)));
4792  ReleaseSysCache(tup);
4793  }
4794  break;
4795 
4796  case OCLASS_TSPARSER:
4797  {
4798  HeapTuple tup;
4799  Form_pg_ts_parser formParser;
4800  char *schema;
4801 
4803  ObjectIdGetDatum(object->objectId));
4804  if (!HeapTupleIsValid(tup))
4805  elog(ERROR, "cache lookup failed for text search parser %u",
4806  object->objectId);
4807  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
4808  schema = get_namespace_name_or_temp(formParser->prsnamespace);
4809  appendStringInfoString(&buffer,
4811  NameStr(formParser->prsname)));
4812  if (objname)
4813  *objname = list_make2(schema,
4814  pstrdup(NameStr(formParser->prsname)));
4815  ReleaseSysCache(tup);
4816  break;
4817  }
4818 
4819  case OCLASS_TSDICT:
4820  {
4821  HeapTuple tup;
4822  Form_pg_ts_dict formDict;
4823  char *schema;
4824 
4825  tup = SearchSysCache1(TSDICTOID,
4826  ObjectIdGetDatum(object->objectId));
4827  if (!HeapTupleIsValid(tup))
4828  elog(ERROR, "cache lookup failed for text search dictionary %u",
4829  object->objectId);
4830  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
4831  schema = get_namespace_name_or_temp(formDict->dictnamespace);
4832  appendStringInfoString(&buffer,
4834  NameStr(formDict->dictname)));
4835  if (objname)
4836  *objname = list_make2(schema,
4837  pstrdup(NameStr(formDict->dictname)));
4838  ReleaseSysCache(tup);
4839  break;
4840  }
4841 
4842  case OCLASS_TSTEMPLATE:
4843  {
4844  HeapTuple tup;
4845  Form_pg_ts_template formTmpl;
4846  char *schema;
4847 
4849  ObjectIdGetDatum(object->objectId));
4850  if (!HeapTupleIsValid(tup))
4851  elog(ERROR, "cache lookup failed for text search template %u",
4852  object->objectId);
4853  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
4854  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
4855  appendStringInfoString(&buffer,
4857  NameStr(formTmpl->tmplname)));
4858  if (objname)
4859  *objname = list_make2(schema,
4860  pstrdup(NameStr(formTmpl->tmplname)));
4861  ReleaseSysCache(tup);
4862  break;
4863  }
4864 
4865  case OCLASS_TSCONFIG:
4866  {
4867  HeapTuple tup;
4868  Form_pg_ts_config formCfg;
4869  char *schema;
4870 
4872  ObjectIdGetDatum(object->objectId));
4873  if (!HeapTupleIsValid(tup))
4874  elog(ERROR, "cache lookup failed for text search configuration %u",
4875  object->objectId);
4876  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
4877  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
4878  appendStringInfoString(&buffer,
4880  NameStr(formCfg->cfgname)));
4881  if (objname)
4882  *objname = list_make2(schema,
4883  pstrdup(NameStr(formCfg->cfgname)));
4884  ReleaseSysCache(tup);
4885  break;
4886  }
4887 
4888  case OCLASS_ROLE:
4889  {
4890  char *username;
4891 
4892  username = GetUserNameFromId(object->objectId, false);
4893  if (objname)
4894  *objname = list_make1(username);
4895  appendStringInfoString(&buffer,
4896  quote_identifier(username));
4897  break;
4898  }
4899 
4900  case OCLASS_DATABASE:
4901  {
4902  char *datname;
4903 
4904  datname = get_database_name(object->objectId);
4905  if (!datname)
4906  elog(ERROR, "cache lookup failed for database %u",
4907  object->objectId);
4908  if (objname)
4909  *objname = list_make1(datname);
4910  appendStringInfoString(&buffer,
4911  quote_identifier(datname));
4912  break;
4913  }
4914 
4915  case OCLASS_TBLSPACE:
4916  {
4917  char *tblspace;
4918 
4919  tblspace = get_tablespace_name(object->objectId);
4920  if (!tblspace)
4921  elog(ERROR, "cache lookup failed for tablespace %u",
4922  object->objectId);
4923  if (objname)
4924  *objname = list_make1(tblspace);
4925  appendStringInfoString(&buffer,
4926  quote_identifier(tblspace));
4927  break;
4928  }
4929 
4930  case OCLASS_FDW:
4931  {
4932  ForeignDataWrapper *fdw;
4933 
4934  fdw = GetForeignDataWrapper(object->objectId);
4936  if (objname)
4937  *objname = list_make1(