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/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 2270 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(), ExecSecLabelStmt(), and RemoveObjects().

2272 {
2273  switch (objtype)
2274  {
2275  case OBJECT_INDEX:
2276  case OBJECT_SEQUENCE:
2277  case OBJECT_TABLE:
2278  case OBJECT_VIEW:
2279  case OBJECT_MATVIEW:
2280  case OBJECT_FOREIGN_TABLE:
2281  case OBJECT_COLUMN:
2282  case OBJECT_RULE:
2283  case OBJECT_TRIGGER:
2284  case OBJECT_POLICY:
2285  case OBJECT_TABCONSTRAINT:
2286  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2288  RelationGetRelationName(relation));
2289  break;
2290  case OBJECT_DATABASE:
2291  if (!pg_database_ownercheck(address.objectId, roleid))
2293  strVal((Value *) object));
2294  break;
2295  case OBJECT_TYPE:
2296  case OBJECT_DOMAIN:
2297  case OBJECT_ATTRIBUTE:
2298  if (!pg_type_ownercheck(address.objectId, roleid))
2300  break;
2301  case OBJECT_DOMCONSTRAINT:
2302  {
2303  HeapTuple tuple;
2304  Oid contypid;
2305 
2306  tuple = SearchSysCache1(CONSTROID,
2307  ObjectIdGetDatum(address.objectId));
2308  if (!HeapTupleIsValid(tuple))
2309  elog(ERROR, "constraint with OID %u does not exist",
2310  address.objectId);
2311 
2312  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2313 
2314  ReleaseSysCache(tuple);
2315 
2316  /*
2317  * Fallback to type ownership check in this case as this is
2318  * what domain constraints rely on.
2319  */
2320  if (!pg_type_ownercheck(contypid, roleid))
2322  }
2323  break;
2324  case OBJECT_AGGREGATE:
2325  case OBJECT_FUNCTION:
2326  case OBJECT_PROCEDURE:
2327  case OBJECT_ROUTINE:
2328  if (!pg_proc_ownercheck(address.objectId, roleid))
2330  NameListToString((castNode(ObjectWithArgs, object))->objname));
2331  break;
2332  case OBJECT_OPERATOR:
2333  if (!pg_oper_ownercheck(address.objectId, roleid))
2335  NameListToString((castNode(ObjectWithArgs, object))->objname));
2336  break;
2337  case OBJECT_SCHEMA:
2338  if (!pg_namespace_ownercheck(address.objectId, roleid))
2340  strVal((Value *) object));
2341  break;
2342  case OBJECT_COLLATION:
2343  if (!pg_collation_ownercheck(address.objectId, roleid))
2345  NameListToString(castNode(List, object)));
2346  break;
2347  case OBJECT_CONVERSION:
2348  if (!pg_conversion_ownercheck(address.objectId, roleid))
2350  NameListToString(castNode(List, object)));
2351  break;
2352  case OBJECT_EXTENSION:
2353  if (!pg_extension_ownercheck(address.objectId, roleid))
2355  strVal((Value *) object));
2356  break;
2357  case OBJECT_FDW:
2358  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2360  strVal((Value *) object));
2361  break;
2362  case OBJECT_FOREIGN_SERVER:
2363  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2365  strVal((Value *) object));
2366  break;
2367  case OBJECT_EVENT_TRIGGER:
2368  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2370  strVal((Value *) object));
2371  break;
2372  case OBJECT_LANGUAGE:
2373  if (!pg_language_ownercheck(address.objectId, roleid))
2375  strVal((Value *) object));
2376  break;
2377  case OBJECT_OPCLASS:
2378  if (!pg_opclass_ownercheck(address.objectId, roleid))
2380  NameListToString(castNode(List, object)));
2381  break;
2382  case OBJECT_OPFAMILY:
2383  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2385  NameListToString(castNode(List, object)));
2386  break;
2387  case OBJECT_LARGEOBJECT:
2388  if (!lo_compat_privileges &&
2389  !pg_largeobject_ownercheck(address.objectId, roleid))
2390  ereport(ERROR,
2391  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2392  errmsg("must be owner of large object %u",
2393  address.objectId)));
2394  break;
2395  case OBJECT_CAST:
2396  {
2397  /* We can only check permissions on the source/target types */
2398  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2399  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2400  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2401  Oid targettypeid = typenameTypeId(NULL, targettype);
2402 
2403  if (!pg_type_ownercheck(sourcetypeid, roleid)
2404  && !pg_type_ownercheck(targettypeid, roleid))
2405  ereport(ERROR,
2406  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2407  errmsg("must be owner of type %s or type %s",
2408  format_type_be(sourcetypeid),
2409  format_type_be(targettypeid))));
2410  }
2411  break;
2412  case OBJECT_PUBLICATION:
2413  if (!pg_publication_ownercheck(address.objectId, roleid))
2415  strVal((Value *) object));
2416  break;
2417  case OBJECT_SUBSCRIPTION:
2418  if (!pg_subscription_ownercheck(address.objectId, roleid))
2420  strVal((Value *) object));
2421  break;
2422  case OBJECT_TRANSFORM:
2423  {
2424  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2425  Oid typeid = typenameTypeId(NULL, typename);
2426 
2427  if (!pg_type_ownercheck(typeid, roleid))
2429  }
2430  break;
2431  case OBJECT_TABLESPACE:
2432  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2434  strVal((Value *) object));
2435  break;
2436  case OBJECT_TSDICTIONARY:
2437  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2439  NameListToString(castNode(List, object)));
2440  break;
2442  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2444  NameListToString(castNode(List, object)));
2445  break;
2446  case OBJECT_ROLE:
2447 
2448  /*
2449  * We treat roles as being "owned" by those with CREATEROLE priv,
2450  * except that superusers are only owned by superusers.
2451  */
2452  if (superuser_arg(address.objectId))
2453  {
2454  if (!superuser_arg(roleid))
2455  ereport(ERROR,
2456  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2457  errmsg("must be superuser")));
2458  }
2459  else
2460  {
2461  if (!has_createrole_privilege(roleid))
2462  ereport(ERROR,
2463  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2464  errmsg("must have CREATEROLE privilege")));
2465  }
2466  break;
2467  case OBJECT_TSPARSER:
2468  case OBJECT_TSTEMPLATE:
2469  case OBJECT_ACCESS_METHOD:
2470  /* We treat these object types as being owned by superusers */
2471  if (!superuser_arg(roleid))
2472  ereport(ERROR,
2473  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2474  errmsg("must be superuser")));
2475  break;
2476  case OBJECT_STATISTIC_EXT:
2477  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2479  break;
2480  default:
2481  elog(ERROR, "unrecognized object type: %d",
2482  (int) objtype);
2483  }
2484 }
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:57
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:594
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:608
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
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:456
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
#define ereport(elevel, rest)
Definition: elog.h:141
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:3094
#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
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:822
#define elog(elevel,...)
Definition: elog.h:228
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:422
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 2705 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().

2706 {
2707  HeapTuple tuple;
2708  Oid classId = RelationGetRelid(catalog);
2709  int oidCacheId = get_object_catcache_oid(classId);
2710 
2711  if (oidCacheId > 0)
2712  {
2713  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2714  if (!HeapTupleIsValid(tuple)) /* should not happen */
2715  return NULL;
2716  }
2717  else
2718  {
2719  Oid oidIndexId = get_object_oid_index(classId);
2720  SysScanDesc scan;
2721  ScanKeyData skey;
2722 
2723  Assert(OidIsValid(oidIndexId));
2724 
2725  ScanKeyInit(&skey,
2726  oidcol,
2727  BTEqualStrategyNumber, F_OIDEQ,
2728  ObjectIdGetDatum(objectId));
2729 
2730  scan = systable_beginscan(catalog, oidIndexId, true,
2731  NULL, 1, &skey);
2732  tuple = systable_getnext(scan);
2733  if (!HeapTupleIsValid(tuple))
2734  {
2735  systable_endscan(scan);
2736  return NULL;
2737  }
2738  tuple = heap_copytuple(tuple);
2739 
2740  systable_endscan(scan);
2741  }
2742 
2743  return tuple;
2744 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:645
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#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:739
#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:422
#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 833 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().

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

1451 {
1452  ObjectAddress address;
1453  List *relname;
1454  Oid reloid;
1455  Relation relation;
1456  const char *attname;
1458  TupleDesc tupdesc;
1459  Oid defoid;
1460 
1461  /* Extract relation name and open relation. */
1462  if (list_length(object) < 2)
1463  ereport(ERROR,
1464  (errcode(ERRCODE_SYNTAX_ERROR),
1465  errmsg("column name must be qualified")));
1466  attname = strVal(llast(object));
1467  relname = list_truncate(list_copy(object), list_length(object) - 1);
1468  /* XXX no missing_ok support here */
1469  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1470  reloid = RelationGetRelid(relation);
1471 
1472  tupdesc = RelationGetDescr(relation);
1473 
1474  /* Look up attribute number and scan pg_attrdef to find its tuple */
1475  attnum = get_attnum(reloid, attname);
1476  defoid = InvalidOid;
1477  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1478  {
1479  Relation attrdef;
1480  ScanKeyData keys[2];
1481  SysScanDesc scan;
1482  HeapTuple tup;
1483 
1484  attrdef = relation_open(AttrDefaultRelationId, AccessShareLock);
1485  ScanKeyInit(&keys[0],
1486  Anum_pg_attrdef_adrelid,
1488  F_OIDEQ,
1489  ObjectIdGetDatum(reloid));
1490  ScanKeyInit(&keys[1],
1491  Anum_pg_attrdef_adnum,
1493  F_INT2EQ,
1494  Int16GetDatum(attnum));
1495  scan = systable_beginscan(attrdef, AttrDefaultIndexId, true,
1496  NULL, 2, keys);
1497  if (HeapTupleIsValid(tup = systable_getnext(scan)))
1498  {
1499  Form_pg_attrdef atdform = (Form_pg_attrdef) GETSTRUCT(tup);
1500 
1501  defoid = atdform->oid;
1502  }
1503 
1504  systable_endscan(scan);
1505  relation_close(attrdef, AccessShareLock);
1506  }
1507  if (!OidIsValid(defoid))
1508  {
1509  if (!missing_ok)
1510  ereport(ERROR,
1511  (errcode(ERRCODE_UNDEFINED_COLUMN),
1512  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1513  attname, NameListToString(relname))));
1514 
1515  address.classId = AttrDefaultRelationId;
1516  address.objectId = InvalidOid;
1517  address.objectSubId = InvalidAttrNumber;
1518  relation_close(relation, lockmode);
1519  return address;
1520  }
1521 
1522  address.classId = AttrDefaultRelationId;
1523  address.objectId = defoid;
1524  address.objectSubId = 0;
1525 
1526  *relp = relation;
1527  return address;
1528 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define RelationGetDescr(relation)
Definition: rel.h:448
#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:608
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3054
NameData relname
Definition: pg_class.h:35
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:645
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#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:806
TupleConstr * constr
Definition: tupdesc.h:85
#define ereport(elevel, rest)
Definition: elog.h:141
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * NameListToString(List *names)
Definition: namespace.c:3094
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 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:822
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:422
#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 1397 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().

1400 {
1401  ObjectAddress address;
1402  List *relname;
1403  Oid reloid;
1404  Relation relation;
1405  const char *attname;
1407 
1408  /* Extract relation name and open relation. */
1409  if (list_length(object) < 2)
1410  ereport(ERROR,
1411  (errcode(ERRCODE_SYNTAX_ERROR),
1412  errmsg("column name must be qualified")));
1413  attname = strVal(lfirst(list_tail(object)));
1414  relname = list_truncate(list_copy(object), list_length(object) - 1);
1415  /* XXX no missing_ok support here */
1416  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1417  reloid = RelationGetRelid(relation);
1418 
1419  /* Look up attribute and construct return value. */
1420  attnum = get_attnum(reloid, attname);
1421  if (attnum == InvalidAttrNumber)
1422  {
1423  if (!missing_ok)
1424  ereport(ERROR,
1425  (errcode(ERRCODE_UNDEFINED_COLUMN),
1426  errmsg("column \"%s\" of relation \"%s\" does not exist",
1427  attname, NameListToString(relname))));
1428 
1429  address.classId = RelationRelationId;
1430  address.objectId = InvalidOid;
1431  address.objectSubId = InvalidAttrNumber;
1432  relation_close(relation, lockmode);
1433  return address;
1434  }
1435 
1436  address.classId = RelationRelationId;
1437  address.objectId = reloid;
1438  address.objectSubId = attnum;
1439 
1440  *relp = relation;
1441  return address;
1442 }
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:608
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3054
NameData relname
Definition: pg_class.h:35
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:806
#define ereport(elevel, rest)
Definition: elog.h:141
char * NameListToString(List *names)
Definition: namespace.c:3094
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
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:822
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:422

◆ get_object_address_defacl()

static ObjectAddress get_object_address_defacl ( List object,
bool  missing_ok 
)
static

Definition at line 1846 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().

1847 {
1848  HeapTuple tp;
1849  Oid userid;
1850  Oid schemaid;
1851  char *username;
1852  char *schema;
1853  char objtype;
1854  char *objtype_str;
1855  ObjectAddress address;
1856 
1857  ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
1858 
1859  /*
1860  * First figure out the textual attributes so that they can be used for
1861  * error reporting.
1862  */
1863  username = strVal(lsecond(object));
1864  if (list_length(object) >= 3)
1865  schema = (char *) strVal(lthird(object));
1866  else
1867  schema = NULL;
1868 
1869  /*
1870  * Decode defaclobjtype. Only first char is considered; the rest of the
1871  * string, if any, is blissfully ignored.
1872  */
1873  objtype = ((char *) strVal(linitial(object)))[0];
1874  switch (objtype)
1875  {
1876  case DEFACLOBJ_RELATION:
1877  objtype_str = "tables";
1878  break;
1879  case DEFACLOBJ_SEQUENCE:
1880  objtype_str = "sequences";
1881  break;
1882  case DEFACLOBJ_FUNCTION:
1883  objtype_str = "functions";
1884  break;
1885  case DEFACLOBJ_TYPE:
1886  objtype_str = "types";
1887  break;
1888  case DEFACLOBJ_NAMESPACE:
1889  objtype_str = "schemas";
1890  break;
1891  default:
1892  ereport(ERROR,
1893  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1894  errmsg("unrecognized default ACL object type \"%c\"", objtype),
1895  errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
1896  DEFACLOBJ_RELATION,
1897  DEFACLOBJ_SEQUENCE,
1898  DEFACLOBJ_FUNCTION,
1899  DEFACLOBJ_TYPE,
1900  DEFACLOBJ_NAMESPACE)));
1901  }
1902 
1903  /*
1904  * Look up user ID. Behave as "default ACL not found" if the user doesn't
1905  * exist.
1906  */
1908  CStringGetDatum(username));
1909  if (!HeapTupleIsValid(tp))
1910  goto not_found;
1911  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1912  ReleaseSysCache(tp);
1913 
1914  /*
1915  * If a schema name was given, look up its OID. If it doesn't exist,
1916  * behave as "default ACL not found".
1917  */
1918  if (schema)
1919  {
1920  schemaid = get_namespace_oid(schema, true);
1921  if (schemaid == InvalidOid)
1922  goto not_found;
1923  }
1924  else
1925  schemaid = InvalidOid;
1926 
1927  /* Finally, look up the pg_default_acl object */
1929  ObjectIdGetDatum(userid),
1930  ObjectIdGetDatum(schemaid),
1931  CharGetDatum(objtype));
1932  if (!HeapTupleIsValid(tp))
1933  goto not_found;
1934 
1935  address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
1936  ReleaseSysCache(tp);
1937 
1938  return address;
1939 
1940 not_found:
1941  if (!missing_ok)
1942  {
1943  if (schema)
1944  ereport(ERROR,
1945  (errcode(ERRCODE_UNDEFINED_OBJECT),
1946  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
1947  username, schema, objtype_str)));
1948  else
1949  ereport(ERROR,
1950  (errcode(ERRCODE_UNDEFINED_OBJECT),
1951  errmsg("default ACL for user \"%s\" on %s does not exist",
1952  username, objtype_str)));
1953  }
1954  return address;
1955 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3035
int errhint(const char *fmt,...)
Definition: elog.c:1069
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
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
#define ereport(elevel, rest)
Definition: elog.h:141
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 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:822
#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 1573 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().

1574 {
1575  Oid amoid;
1576  ObjectAddress address;
1577 
1578  /* XXX no missing_ok support here */
1579  amoid = get_index_am_oid(strVal(linitial(object)), false);
1580  object = list_copy_tail(object, 1);
1581 
1582  switch (objtype)
1583  {
1584  case OBJECT_OPCLASS:
1585  address.classId = OperatorClassRelationId;
1586  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1587  address.objectSubId = 0;
1588  break;
1589  case OBJECT_OPFAMILY:
1590  address.classId = OperatorFamilyRelationId;
1591  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1592  address.objectSubId = 0;
1593  break;
1594  default:
1595  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1596  /* placate compiler, which doesn't know elog won't return */
1597  address.classId = InvalidOid;
1598  address.objectId = InvalidOid;
1599  address.objectSubId = 0;
1600  }
1601 
1602  return address;
1603 }
#define strVal(v)
Definition: value.h:54
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c:222
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:141
#define elog(elevel,...)
Definition: elog.h:228

◆ get_object_address_opf_member()

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

Definition at line 1611 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().

1613 {
1614  ObjectAddress famaddr;
1615  ObjectAddress address;
1616  ListCell *cell;
1617  List *copy;
1618  TypeName *typenames[2];
1619  Oid typeoids[2];
1620  int membernum;
1621  int i;
1622 
1623  /*
1624  * The last element of the object list contains the strategy or procedure
1625  * number. We need to strip that out before getting the opclass/family
1626  * address. The rest can be used directly by get_object_address_opcf().
1627  */
1628  membernum = atoi(strVal(llast(linitial(object))));
1629  copy = list_truncate(list_copy(linitial(object)), list_length(linitial(object)) - 1);
1630 
1631  /* no missing_ok support here */
1632  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1633 
1634  /* find out left/right type names and OIDs */
1635  typenames[0] = typenames[1] = NULL;
1636  typeoids[0] = typeoids[1] = InvalidOid;
1637  i = 0;
1638  foreach(cell, lsecond(object))
1639  {
1640  ObjectAddress typaddr;
1641 
1642  typenames[i] = lfirst_node(TypeName, cell);
1643  typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
1644  typeoids[i] = typaddr.objectId;
1645  if (++i >= 2)
1646  break;
1647  }
1648 
1649  switch (objtype)
1650  {
1651  case OBJECT_AMOP:
1652  {
1653  HeapTuple tp;
1654 
1655  ObjectAddressSet(address, AccessMethodOperatorRelationId,
1656  InvalidOid);
1657 
1659  ObjectIdGetDatum(famaddr.objectId),
1660  ObjectIdGetDatum(typeoids[0]),
1661  ObjectIdGetDatum(typeoids[1]),
1662  Int16GetDatum(membernum));
1663  if (!HeapTupleIsValid(tp))
1664  {
1665  if (!missing_ok)
1666  ereport(ERROR,
1667  (errcode(ERRCODE_UNDEFINED_OBJECT),
1668  errmsg("operator %d (%s, %s) of %s does not exist",
1669  membernum,
1670  TypeNameToString(typenames[0]),
1671  TypeNameToString(typenames[1]),
1672  getObjectDescription(&famaddr))));
1673  }
1674  else
1675  {
1676  address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
1677  ReleaseSysCache(tp);
1678  }
1679  }
1680  break;
1681 
1682  case OBJECT_AMPROC:
1683  {
1684  HeapTuple tp;
1685 
1686  ObjectAddressSet(address, AccessMethodProcedureRelationId,
1687  InvalidOid);
1688 
1690  ObjectIdGetDatum(famaddr.objectId),
1691  ObjectIdGetDatum(typeoids[0]),
1692  ObjectIdGetDatum(typeoids[1]),
1693  Int16GetDatum(membernum));
1694  if (!HeapTupleIsValid(tp))
1695  {
1696  if (!missing_ok)
1697  ereport(ERROR,
1698  (errcode(ERRCODE_UNDEFINED_OBJECT),
1699  errmsg("function %d (%s, %s) of %s does not exist",
1700  membernum,
1701  TypeNameToString(typenames[0]),
1702  TypeNameToString(typenames[1]),
1703  getObjectDescription(&famaddr))));
1704  }
1705  else
1706  {
1707  address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
1708  ReleaseSysCache(tp);
1709  }
1710  }
1711  break;
1712  default:
1713  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1714  }
1715 
1716  return address;
1717 }
#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:608
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
#define ereport(elevel, rest)
Definition: elog.h:141
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#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:822
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
#define elog(elevel,...)
Definition: elog.h:228
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 1794 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().

1796 {
1797  ObjectAddress address;
1798  Relation relation;
1799  List *relname;
1800  char *pubname;
1801  Publication *pub;
1802 
1803  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1804 
1805  relname = linitial(object);
1807  AccessShareLock, missing_ok);
1808  if (!relation)
1809  return address;
1810 
1811  /* fetch publication name from input list */
1812  pubname = strVal(lsecond(object));
1813 
1814  /* Now look up the pg_publication tuple */
1815  pub = GetPublicationByName(pubname, missing_ok);
1816  if (!pub)
1817  {
1818  relation_close(relation, AccessShareLock);
1819  return address;
1820  }
1821 
1822  /* Find the publication relation mapping in syscache. */
1823  address.objectId =
1824  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1826  ObjectIdGetDatum(pub->oid));
1827  if (!OidIsValid(address.objectId))
1828  {
1829  if (!missing_ok)
1830  ereport(ERROR,
1831  (errcode(ERRCODE_UNDEFINED_OBJECT),
1832  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1833  RelationGetRelationName(relation), pubname)));
1834  relation_close(relation, AccessShareLock);
1835  return address;
1836  }
1837 
1838  *relp = relation;
1839  return address;
1840 }
#define AccessShareLock
Definition: lockdefs.h:36
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3054
NameData relname
Definition: pg_class.h:35
#define OidIsValid(objectId)
Definition: c.h:645
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:456
#define ereport(elevel, rest)
Definition: elog.h:141
#define InvalidOid
Definition: postgres_ext.h:36
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:822
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:422
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 1318 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().

1320 {
1321  ObjectAddress address;
1322  Relation relation = NULL;
1323  int nnames;
1324  const char *depname;
1325  List *relname;
1326  Oid reloid;
1327 
1328  /* Extract name of dependent object. */
1329  depname = strVal(llast(object));
1330 
1331  /* Separate relation name from dependent object name. */
1332  nnames = list_length(object);
1333  if (nnames < 2)
1334  ereport(ERROR,
1335  (errcode(ERRCODE_SYNTAX_ERROR),
1336  errmsg("must specify relation and object name")));
1337 
1338  /* Extract relation name and open relation. */
1339  relname = list_truncate(list_copy(object), nnames - 1);
1340  relation = table_openrv_extended(makeRangeVarFromNameList(relname),
1342  missing_ok);
1343 
1344  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1345 
1346  switch (objtype)
1347  {
1348  case OBJECT_RULE:
1349  address.classId = RewriteRelationId;
1350  address.objectId = relation ?
1351  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1352  address.objectSubId = 0;
1353  break;
1354  case OBJECT_TRIGGER:
1355  address.classId = TriggerRelationId;
1356  address.objectId = relation ?
1357  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1358  address.objectSubId = 0;
1359  break;
1360  case OBJECT_TABCONSTRAINT:
1361  address.classId = ConstraintRelationId;
1362  address.objectId = relation ?
1363  get_relation_constraint_oid(reloid, depname, missing_ok) :
1364  InvalidOid;
1365  address.objectSubId = 0;
1366  break;
1367  case OBJECT_POLICY:
1368  address.classId = PolicyRelationId;
1369  address.objectId = relation ?
1370  get_relation_policy_oid(reloid, depname, missing_ok) :
1371  InvalidOid;
1372  address.objectSubId = 0;
1373  break;
1374  default:
1375  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1376  }
1377 
1378  /* Avoid relcache leak when object not found. */
1379  if (!OidIsValid(address.objectId))
1380  {
1381  if (relation != NULL)
1382  table_close(relation, AccessShareLock);
1383 
1384  relation = NULL; /* department of accident prevention */
1385  return address;
1386  }
1387 
1388  /* Done. */
1389  *relp = relation;
1390  return address;
1391 }
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:608
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3054
NameData relname
Definition: pg_class.h:35
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:645
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
Definition: policy.c:1326
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:1576
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:422

◆ 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 1128 of file objectaddress.c.

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

Referenced by ExecAlterObjectDependsStmt().

1131 {
1132  if (rel)
1133  {
1134  object = lcons(makeString(rel->relname), object);
1135  if (rel->schemaname)
1136  object = lcons(makeString(rel->schemaname), object);
1137  if (rel->catalogname)
1138  object = lcons(makeString(rel->catalogname), object);
1139  }
1140 
1141  return get_object_address(objtype, (Node *) object,
1142  relp, lockmode, missing_ok);
1143 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:525
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 1534 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().

1535 {
1536  ObjectAddress address;
1537  Type tup;
1538 
1539  address.classId = TypeRelationId;
1540  address.objectId = InvalidOid;
1541  address.objectSubId = 0;
1542 
1543  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1544  if (!HeapTupleIsValid(tup))
1545  {
1546  if (!missing_ok)
1547  ereport(ERROR,
1548  (errcode(ERRCODE_UNDEFINED_OBJECT),
1549  errmsg("type \"%s\" does not exist",
1550  TypeNameToString(typename))));
1551  return address;
1552  }
1553  address.objectId = typeTypeId(tup);
1554 
1555  if (objtype == OBJECT_DOMAIN)
1556  {
1557  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1558  ereport(ERROR,
1559  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1560  errmsg("\"%s\" is not a domain",
1561  TypeNameToString(typename))));
1562  }
1563 
1564  ReleaseSysCache(tup);
1565 
1566  return address;
1567 }
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:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:250
int errmsg(const char *fmt,...)
Definition: elog.c:822
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 1150 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().

1152 {
1153  const char *name;
1154  ObjectAddress address;
1155 
1156  name = strVal(strval);
1157 
1158  /* Translate name to OID. */
1159  switch (objtype)
1160  {
1161  case OBJECT_ACCESS_METHOD:
1162  address.classId = AccessMethodRelationId;
1163  address.objectId = get_am_oid(name, missing_ok);
1164  address.objectSubId = 0;
1165  break;
1166  case OBJECT_DATABASE:
1167  address.classId = DatabaseRelationId;
1168  address.objectId = get_database_oid(name, missing_ok);
1169  address.objectSubId = 0;
1170  break;
1171  case OBJECT_EXTENSION:
1172  address.classId = ExtensionRelationId;
1173  address.objectId = get_extension_oid(name, missing_ok);
1174  address.objectSubId = 0;
1175  break;
1176  case OBJECT_TABLESPACE:
1177  address.classId = TableSpaceRelationId;
1178  address.objectId = get_tablespace_oid(name, missing_ok);
1179  address.objectSubId = 0;
1180  break;
1181  case OBJECT_ROLE:
1182  address.classId = AuthIdRelationId;
1183  address.objectId = get_role_oid(name, missing_ok);
1184  address.objectSubId = 0;
1185  break;
1186  case OBJECT_SCHEMA:
1187  address.classId = NamespaceRelationId;
1188  address.objectId = get_namespace_oid(name, missing_ok);
1189  address.objectSubId = 0;
1190  break;
1191  case OBJECT_LANGUAGE:
1192  address.classId = LanguageRelationId;
1193  address.objectId = get_language_oid(name, missing_ok);
1194  address.objectSubId = 0;
1195  break;
1196  case OBJECT_FDW:
1197  address.classId = ForeignDataWrapperRelationId;
1198  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1199  address.objectSubId = 0;
1200  break;
1201  case OBJECT_FOREIGN_SERVER:
1202  address.classId = ForeignServerRelationId;
1203  address.objectId = get_foreign_server_oid(name, missing_ok);
1204  address.objectSubId = 0;
1205  break;
1206  case OBJECT_EVENT_TRIGGER:
1207  address.classId = EventTriggerRelationId;
1208  address.objectId = get_event_trigger_oid(name, missing_ok);
1209  address.objectSubId = 0;
1210  break;
1211  case OBJECT_PUBLICATION:
1212  address.classId = PublicationRelationId;
1213  address.objectId = get_publication_oid(name, missing_ok);
1214  address.objectSubId = 0;
1215  break;
1216  case OBJECT_SUBSCRIPTION:
1217  address.classId = SubscriptionRelationId;
1218  address.objectId = get_subscription_oid(name, missing_ok);
1219  address.objectSubId = 0;
1220  break;
1221  default:
1222  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1223  /* placate compiler, which doesn't know elog won't return */
1224  address.classId = InvalidOid;
1225  address.objectId = InvalidOid;
1226  address.objectSubId = 0;
1227  }
1228 
1229  return address;
1230 }
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:3035
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:559
#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:138
#define elog(elevel,...)
Definition: elog.h:228
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 1723 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().

1724 {
1725  ObjectAddress address;
1726  Oid userid;
1727  char *username;
1728  char *servername;
1729  ForeignServer *server;
1730  HeapTuple tp;
1731 
1732  ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1733 
1734  /* fetch string names from input lists, for error messages */
1735  username = strVal(linitial(object));
1736  servername = strVal(lsecond(object));
1737 
1738  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1739  if (strcmp(username, "public") == 0)
1740  userid = InvalidOid;
1741  else
1742  {
1744  CStringGetDatum(username));
1745  if (!HeapTupleIsValid(tp))
1746  {
1747  if (!missing_ok)
1748  ereport(ERROR,
1749  (errcode(ERRCODE_UNDEFINED_OBJECT),
1750  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1751  username, servername)));
1752  return address;
1753  }
1754  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1755  ReleaseSysCache(tp);
1756  }
1757 
1758  /* Now look up the pg_user_mapping tuple */
1759  server = GetForeignServerByName(servername, true);
1760  if (!server)
1761  {
1762  if (!missing_ok)
1763  ereport(ERROR,
1764  (errcode(ERRCODE_UNDEFINED_OBJECT),
1765  errmsg("server \"%s\" does not exist", servername)));
1766  return address;
1767  }
1768  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1769  ObjectIdGetDatum(userid),
1770  ObjectIdGetDatum(server->serverid));
1771  if (!HeapTupleIsValid(tp))
1772  {
1773  if (!missing_ok)
1774  ereport(ERROR,
1775  (errcode(ERRCODE_UNDEFINED_OBJECT),
1776  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1777  username, servername)));
1778  return address;
1779  }
1780 
1781  address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1782 
1783  ReleaseSysCache(tp);
1784 
1785  return address;
1786 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
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
#define ereport(elevel, rest)
Definition: elog.h:141
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 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:822
Oid serverid
Definition: foreign.h:36

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2608 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2609 {
2610  const ObjectPropertyType *prop = get_object_property_data(class_id);
2611 
2612  return prop->attnum_acl;
2613 }
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 2584 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().

2585 {
2586  const ObjectPropertyType *prop = get_object_property_data(class_id);
2587 
2588  return prop->attnum_name;
2589 }
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 2592 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().

2593 {
2594  const ObjectPropertyType *prop = get_object_property_data(class_id);
2595 
2596  return prop->attnum_namespace;
2597 }
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 2576 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().

2577 {
2578  const ObjectPropertyType *prop = get_object_property_data(class_id);
2579 
2580  return prop->attnum_oid;
2581 }
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 2600 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2601 {
2602  const ObjectPropertyType *prop = get_object_property_data(class_id);
2603 
2604  return prop->attnum_owner;
2605 }
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 2568 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2569 {
2570  const ObjectPropertyType *prop = get_object_property_data(class_id);
2571 
2572  return prop->name_catcache_id;
2573 }
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 2560 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().

2561 {
2562  const ObjectPropertyType *prop = get_object_property_data(class_id);
2563 
2564  return prop->oid_catcache_id;
2565 }
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 2641 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

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

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

Definition at line 2493 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().

2494 {
2495  int cache;
2496  HeapTuple tuple;
2497  bool isnull;
2498  Oid oid;
2499  const ObjectPropertyType *property;
2500 
2501  /* If not owned by a namespace, just return InvalidOid. */
2502  property = get_object_property_data(address->classId);
2503  if (property->attnum_namespace == InvalidAttrNumber)
2504  return InvalidOid;
2505 
2506  /* Currently, we can only handle object types with system caches. */
2507  cache = property->oid_catcache_id;
2508  Assert(cache != -1);
2509 
2510  /* Fetch tuple from syscache and extract namespace attribute. */
2511  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2512  if (!HeapTupleIsValid(tuple))
2513  elog(ERROR, "cache lookup failed for cache %d oid %u",
2514  cache, address->objectId);
2515  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2516  tuple,
2517  property->attnum_namespace,
2518  &isnull));
2519  Assert(!isnull);
2520  ReleaseSysCache(tuple);
2521 
2522  return oid;
2523 }
#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:739
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog(elevel,...)
Definition: elog.h:228

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2552 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2553 {
2554  const ObjectPropertyType *prop = get_object_property_data(class_id);
2555 
2556  return prop->oid_index_oid;
2557 }
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 2670 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().

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

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

Definition at line 2623 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().

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

1239 {
1240  Relation relation;
1241  ObjectAddress address;
1242 
1243  address.classId = RelationRelationId;
1244  address.objectId = InvalidOid;
1245  address.objectSubId = 0;
1246 
1248  lockmode, missing_ok);
1249  if (!relation)
1250  return address;
1251 
1252  switch (objtype)
1253  {
1254  case OBJECT_INDEX:
1255  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1256  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1257  ereport(ERROR,
1258  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1259  errmsg("\"%s\" is not an index",
1260  RelationGetRelationName(relation))));
1261  break;
1262  case OBJECT_SEQUENCE:
1263  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1264  ereport(ERROR,
1265  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1266  errmsg("\"%s\" is not a sequence",
1267  RelationGetRelationName(relation))));
1268  break;
1269  case OBJECT_TABLE:
1270  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1271  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1272  ereport(ERROR,
1273  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1274  errmsg("\"%s\" is not a table",
1275  RelationGetRelationName(relation))));
1276  break;
1277  case OBJECT_VIEW:
1278  if (relation->rd_rel->relkind != RELKIND_VIEW)
1279  ereport(ERROR,
1280  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1281  errmsg("\"%s\" is not a view",
1282  RelationGetRelationName(relation))));
1283  break;
1284  case OBJECT_MATVIEW:
1285  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1286  ereport(ERROR,
1287  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1288  errmsg("\"%s\" is not a materialized view",
1289  RelationGetRelationName(relation))));
1290  break;
1291  case OBJECT_FOREIGN_TABLE:
1292  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1293  ereport(ERROR,
1294  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1295  errmsg("\"%s\" is not a foreign table",
1296  RelationGetRelationName(relation))));
1297  break;
1298  default:
1299  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1300  break;
1301  }
1302 
1303  /* Done. */
1304  address.objectId = RelationGetRelid(relation);
1305  *relp = relation;
1306 
1307  return address;
1308 }
int errcode(int sqlerrcode)
Definition: elog.c:608
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3054
Form_pg_class rd_rel
Definition: rel.h:83
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:456
#define ereport(elevel, rest)
Definition: elog.h:141
#define InvalidOid
Definition: postgres_ext.h:36
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
#define RelationGetRelid(relation)
Definition: rel.h:422
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 5354 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(), LockTableRecurse(), LockViewRecurse_walker(), MergeAttributes(), pg_prewarm(), pgrowlocks(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), transformTableLikeClause(), and truncate_check_rel().

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

◆ getConstraintTypeDescription()

static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid 
)
static

Definition at line 4225 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().

4226 {
4227  Relation constrRel;
4228  HeapTuple constrTup;
4229  Form_pg_constraint constrForm;
4230 
4231  constrRel = table_open(ConstraintRelationId, AccessShareLock);
4232  constrTup = get_catalog_object_by_oid(constrRel, Anum_pg_constraint_oid,
4233  constroid);
4234  if (!HeapTupleIsValid(constrTup))
4235  elog(ERROR, "cache lookup failed for constraint %u", constroid);
4236 
4237  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4238 
4239  if (OidIsValid(constrForm->conrelid))
4240  appendStringInfoString(buffer, "table constraint");
4241  else if (OidIsValid(constrForm->contypid))
4242  appendStringInfoString(buffer, "domain constraint");
4243  else
4244  elog(ERROR, "invalid constraint %u", constrForm->oid);
4245 
4246  table_close(constrRel, AccessShareLock);
4247 }
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:645
#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:228
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object)

Definition at line 2752 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().

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3662 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

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

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

Definition at line 4295 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().

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