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

Go to the source code of this file.

Data Structures

struct  ObjectPropertyType
 
struct  object_type_map
 

Functions

static ObjectAddress get_object_address_unqualified (ObjectType objtype, Value *strval, bool missing_ok)
 
static ObjectAddress get_relation_by_qualified_name (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_relobject (ObjectType objtype, List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_attribute (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_attrdef (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_type (ObjectType objtype, TypeName *typename, bool missing_ok)
 
static ObjectAddress get_object_address_opcf (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_opf_member (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_usermapping (List *object, bool missing_ok)
 
static ObjectAddress get_object_address_publication_rel (List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_defacl (List *object, bool missing_ok)
 
static const ObjectPropertyTypeget_object_property_data (Oid class_id)
 
static void getRelationDescription (StringInfo buffer, Oid relid)
 
static void getOpFamilyDescription (StringInfo buffer, Oid opfid)
 
static void getRelationTypeDescription (StringInfo buffer, Oid relid, int32 objectSubId)
 
static void getProcedureTypeDescription (StringInfo buffer, Oid procid)
 
static void getConstraintTypeDescription (StringInfo buffer, Oid constroid)
 
static void getOpFamilyIdentity (StringInfo buffer, Oid opfid, List **object)
 
static void getRelationIdentity (StringInfo buffer, Oid relid, List **object)
 
ObjectAddress get_object_address (ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static Listtextarray_to_strvaluelist (ArrayType *arr)
 
Datum pg_get_object_address (PG_FUNCTION_ARGS)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
int read_objtype_from_string (const char *objtype)
 
const char * get_object_class_descr (Oid class_id)
 
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 2360 of file objectaddress.c.

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

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

2362 {
2363  switch (objtype)
2364  {
2365  case OBJECT_INDEX:
2366  case OBJECT_SEQUENCE:
2367  case OBJECT_TABLE:
2368  case OBJECT_VIEW:
2369  case OBJECT_MATVIEW:
2370  case OBJECT_FOREIGN_TABLE:
2371  case OBJECT_COLUMN:
2372  case OBJECT_RULE:
2373  case OBJECT_TRIGGER:
2374  case OBJECT_POLICY:
2375  case OBJECT_TABCONSTRAINT:
2376  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2378  RelationGetRelationName(relation));
2379  break;
2380  case OBJECT_DATABASE:
2381  if (!pg_database_ownercheck(address.objectId, roleid))
2383  strVal((Value *) object));
2384  break;
2385  case OBJECT_TYPE:
2386  case OBJECT_DOMAIN:
2387  case OBJECT_ATTRIBUTE:
2388  if (!pg_type_ownercheck(address.objectId, roleid))
2390  break;
2391  case OBJECT_DOMCONSTRAINT:
2392  {
2393  HeapTuple tuple;
2394  Oid contypid;
2395 
2396  tuple = SearchSysCache1(CONSTROID,
2397  ObjectIdGetDatum(address.objectId));
2398  if (!HeapTupleIsValid(tuple))
2399  elog(ERROR, "constraint with OID %u does not exist",
2400  address.objectId);
2401 
2402  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2403 
2404  ReleaseSysCache(tuple);
2405 
2406  /*
2407  * Fallback to type ownership check in this case as this is
2408  * what domain constraints rely on.
2409  */
2410  if (!pg_type_ownercheck(contypid, roleid))
2412  }
2413  break;
2414  case OBJECT_AGGREGATE:
2415  case OBJECT_FUNCTION:
2416  case OBJECT_PROCEDURE:
2417  case OBJECT_ROUTINE:
2418  if (!pg_proc_ownercheck(address.objectId, roleid))
2420  NameListToString((castNode(ObjectWithArgs, object))->objname));
2421  break;
2422  case OBJECT_OPERATOR:
2423  if (!pg_oper_ownercheck(address.objectId, roleid))
2425  NameListToString((castNode(ObjectWithArgs, object))->objname));
2426  break;
2427  case OBJECT_SCHEMA:
2428  if (!pg_namespace_ownercheck(address.objectId, roleid))
2430  strVal((Value *) object));
2431  break;
2432  case OBJECT_COLLATION:
2433  if (!pg_collation_ownercheck(address.objectId, roleid))
2435  NameListToString(castNode(List, object)));
2436  break;
2437  case OBJECT_CONVERSION:
2438  if (!pg_conversion_ownercheck(address.objectId, roleid))
2440  NameListToString(castNode(List, object)));
2441  break;
2442  case OBJECT_EXTENSION:
2443  if (!pg_extension_ownercheck(address.objectId, roleid))
2445  strVal((Value *) object));
2446  break;
2447  case OBJECT_FDW:
2448  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2450  strVal((Value *) object));
2451  break;
2452  case OBJECT_FOREIGN_SERVER:
2453  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2455  strVal((Value *) object));
2456  break;
2457  case OBJECT_EVENT_TRIGGER:
2458  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2460  strVal((Value *) object));
2461  break;
2462  case OBJECT_LANGUAGE:
2463  if (!pg_language_ownercheck(address.objectId, roleid))
2465  strVal((Value *) object));
2466  break;
2467  case OBJECT_OPCLASS:
2468  if (!pg_opclass_ownercheck(address.objectId, roleid))
2470  NameListToString(castNode(List, object)));
2471  break;
2472  case OBJECT_OPFAMILY:
2473  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2475  NameListToString(castNode(List, object)));
2476  break;
2477  case OBJECT_LARGEOBJECT:
2478  if (!lo_compat_privileges &&
2479  !pg_largeobject_ownercheck(address.objectId, roleid))
2480  ereport(ERROR,
2481  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2482  errmsg("must be owner of large object %u",
2483  address.objectId)));
2484  break;
2485  case OBJECT_CAST:
2486  {
2487  /* We can only check permissions on the source/target types */
2488  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2489  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2490  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2491  Oid targettypeid = typenameTypeId(NULL, targettype);
2492 
2493  if (!pg_type_ownercheck(sourcetypeid, roleid)
2494  && !pg_type_ownercheck(targettypeid, roleid))
2495  ereport(ERROR,
2496  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2497  errmsg("must be owner of type %s or type %s",
2498  format_type_be(sourcetypeid),
2499  format_type_be(targettypeid))));
2500  }
2501  break;
2502  case OBJECT_PUBLICATION:
2503  if (!pg_publication_ownercheck(address.objectId, roleid))
2505  strVal((Value *) object));
2506  break;
2507  case OBJECT_SUBSCRIPTION:
2508  if (!pg_subscription_ownercheck(address.objectId, roleid))
2510  strVal((Value *) object));
2511  break;
2512  case OBJECT_TRANSFORM:
2513  {
2514  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2515  Oid typeid = typenameTypeId(NULL, typename);
2516 
2517  if (!pg_type_ownercheck(typeid, roleid))
2519  }
2520  break;
2521  case OBJECT_TABLESPACE:
2522  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2524  strVal((Value *) object));
2525  break;
2526  case OBJECT_TSDICTIONARY:
2527  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2529  NameListToString(castNode(List, object)));
2530  break;
2532  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2534  NameListToString(castNode(List, object)));
2535  break;
2536  case OBJECT_ROLE:
2537 
2538  /*
2539  * We treat roles as being "owned" by those with CREATEROLE priv,
2540  * except that superusers are only owned by superusers.
2541  */
2542  if (superuser_arg(address.objectId))
2543  {
2544  if (!superuser_arg(roleid))
2545  ereport(ERROR,
2546  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2547  errmsg("must be superuser")));
2548  }
2549  else
2550  {
2551  if (!has_createrole_privilege(roleid))
2552  ereport(ERROR,
2553  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2554  errmsg("must have CREATEROLE privilege")));
2555  }
2556  break;
2557  case OBJECT_TSPARSER:
2558  case OBJECT_TSTEMPLATE:
2559  case OBJECT_ACCESS_METHOD:
2560  /* We treat these object types as being owned by superusers */
2561  if (!superuser_arg(roleid))
2562  ereport(ERROR,
2563  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2564  errmsg("must be superuser")));
2565  break;
2566  case OBJECT_STATISTIC_EXT:
2567  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2569  break;
2570  default:
2571  elog(ERROR, "unrecognized object type: %d",
2572  (int) objtype);
2573  }
2574 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5312
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5131
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
bool lo_compat_privileges
Definition: inv_api.c:58
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4820
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:4970
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4791
#define castNode(_type_, nodeptr)
Definition: nodes.h:598
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:4997
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5051
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5225
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4739
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4863
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4713
#define linitial_node(type, l)
Definition: pg_list.h:198
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3607
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3294
#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:5078
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5183
#define RelationGetRelationName(relation)
Definition: rel.h:490
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4889
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:4943
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5105
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
char * NameListToString(List *names)
Definition: namespace.c:3102
#define lsecond_node(type, l)
Definition: pg_list.h:203
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4916
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5157
#define ereport(elevel,...)
Definition: elog.h:144
FormData_pg_constraint * Form_pg_constraint
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
Definition: value.h:42
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4687
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5024
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:456
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4765
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5251
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5277

◆ get_catalog_object_by_oid()

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

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

2804 {
2805  HeapTuple tuple;
2806  Oid classId = RelationGetRelid(catalog);
2807  int oidCacheId = get_object_catcache_oid(classId);
2808 
2809  if (oidCacheId > 0)
2810  {
2811  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2812  if (!HeapTupleIsValid(tuple)) /* should not happen */
2813  return NULL;
2814  }
2815  else
2816  {
2817  Oid oidIndexId = get_object_oid_index(classId);
2818  SysScanDesc scan;
2819  ScanKeyData skey;
2820 
2821  Assert(OidIsValid(oidIndexId));
2822 
2823  ScanKeyInit(&skey,
2824  oidcol,
2825  BTEqualStrategyNumber, F_OIDEQ,
2826  ObjectIdGetDatum(objectId));
2827 
2828  scan = systable_beginscan(catalog, oidIndexId, true,
2829  NULL, 1, &skey);
2830  tuple = systable_getnext(scan);
2831  if (!HeapTupleIsValid(tuple))
2832  {
2833  systable_endscan(scan);
2834  return NULL;
2835  }
2836  tuple = heap_copytuple(tuple);
2837 
2838  systable_endscan(scan);
2839  }
2840 
2841  return tuple;
2842 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:529
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:356
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:448
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:738
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:456
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ get_object_address()

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

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

925 {
926  ObjectAddress address;
927  ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
928  Relation relation = NULL;
929  uint64 inval_count;
930 
931  /* Some kind of lock must be taken. */
932  Assert(lockmode != NoLock);
933 
934  for (;;)
935  {
936  /*
937  * Remember this value, so that, after looking up the object name and
938  * locking it, we can check whether any invalidation messages have
939  * been processed that might require a do-over.
940  */
941  inval_count = SharedInvalidMessageCounter;
942 
943  /* Look up object address. */
944  switch (objtype)
945  {
946  case OBJECT_INDEX:
947  case OBJECT_SEQUENCE:
948  case OBJECT_TABLE:
949  case OBJECT_VIEW:
950  case OBJECT_MATVIEW:
952  address =
953  get_relation_by_qualified_name(objtype, castNode(List, object),
954  &relation, lockmode,
955  missing_ok);
956  break;
957  case OBJECT_COLUMN:
958  address =
959  get_object_address_attribute(objtype, castNode(List, object),
960  &relation, lockmode,
961  missing_ok);
962  break;
963  case OBJECT_DEFAULT:
964  address =
965  get_object_address_attrdef(objtype, castNode(List, object),
966  &relation, lockmode,
967  missing_ok);
968  break;
969  case OBJECT_RULE:
970  case OBJECT_TRIGGER:
972  case OBJECT_POLICY:
973  address = get_object_address_relobject(objtype, castNode(List, object),
974  &relation, missing_ok);
975  break;
977  {
978  List *objlist;
979  ObjectAddress domaddr;
980  char *constrname;
981 
982  objlist = castNode(List, object);
984  linitial_node(TypeName, objlist),
985  missing_ok);
986  constrname = strVal(lsecond(objlist));
987 
988  address.classId = ConstraintRelationId;
989  address.objectId = get_domain_constraint_oid(domaddr.objectId,
990  constrname, missing_ok);
991  address.objectSubId = 0;
992 
993  }
994  break;
995  case OBJECT_DATABASE:
996  case OBJECT_EXTENSION:
997  case OBJECT_TABLESPACE:
998  case OBJECT_ROLE:
999  case OBJECT_SCHEMA:
1000  case OBJECT_LANGUAGE:
1001  case OBJECT_FDW:
1002  case OBJECT_FOREIGN_SERVER:
1003  case OBJECT_EVENT_TRIGGER:
1004  case OBJECT_ACCESS_METHOD:
1005  case OBJECT_PUBLICATION:
1006  case OBJECT_SUBSCRIPTION:
1007  address = get_object_address_unqualified(objtype,
1008  (Value *) object, missing_ok);
1009  break;
1010  case OBJECT_TYPE:
1011  case OBJECT_DOMAIN:
1012  address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
1013  break;
1014  case OBJECT_AGGREGATE:
1015  case OBJECT_FUNCTION:
1016  case OBJECT_PROCEDURE:
1017  case OBJECT_ROUTINE:
1018  address.classId = ProcedureRelationId;
1019  address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
1020  address.objectSubId = 0;
1021  break;
1022  case OBJECT_OPERATOR:
1023  address.classId = OperatorRelationId;
1024  address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
1025  address.objectSubId = 0;
1026  break;
1027  case OBJECT_COLLATION:
1028  address.classId = CollationRelationId;
1029  address.objectId = get_collation_oid(castNode(List, object), missing_ok);
1030  address.objectSubId = 0;
1031  break;
1032  case OBJECT_CONVERSION:
1033  address.classId = ConversionRelationId;
1034  address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
1035  address.objectSubId = 0;
1036  break;
1037  case OBJECT_OPCLASS:
1038  case OBJECT_OPFAMILY:
1039  address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
1040  break;
1041  case OBJECT_AMOP:
1042  case OBJECT_AMPROC:
1043  address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
1044  break;
1045  case OBJECT_LARGEOBJECT:
1046  address.classId = LargeObjectRelationId;
1047  address.objectId = oidparse(object);
1048  address.objectSubId = 0;
1049  if (!LargeObjectExists(address.objectId))
1050  {
1051  if (!missing_ok)
1052  ereport(ERROR,
1053  (errcode(ERRCODE_UNDEFINED_OBJECT),
1054  errmsg("large object %u does not exist",
1055  address.objectId)));
1056  }
1057  break;
1058  case OBJECT_CAST:
1059  {
1060  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
1061  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
1062  Oid sourcetypeid;
1063  Oid targettypeid;
1064 
1065  sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
1066  targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
1067  address.classId = CastRelationId;
1068  address.objectId =
1069  get_cast_oid(sourcetypeid, targettypeid, missing_ok);
1070  address.objectSubId = 0;
1071  }
1072  break;
1073  case OBJECT_TRANSFORM:
1074  {
1075  TypeName *typename = linitial_node(TypeName, castNode(List, object));
1076  char *langname = strVal(lsecond(castNode(List, object)));
1077  Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
1078  Oid lang_id = get_language_oid(langname, missing_ok);
1079 
1080  address.classId = TransformRelationId;
1081  address.objectId =
1082  get_transform_oid(type_id, lang_id, missing_ok);
1083  address.objectSubId = 0;
1084  }
1085  break;
1086  case OBJECT_TSPARSER:
1087  address.classId = TSParserRelationId;
1088  address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
1089  address.objectSubId = 0;
1090  break;
1091  case OBJECT_TSDICTIONARY:
1092  address.classId = TSDictionaryRelationId;
1093  address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
1094  address.objectSubId = 0;
1095  break;
1096  case OBJECT_TSTEMPLATE:
1097  address.classId = TSTemplateRelationId;
1098  address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
1099  address.objectSubId = 0;
1100  break;
1102  address.classId = TSConfigRelationId;
1103  address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
1104  address.objectSubId = 0;
1105  break;
1106  case OBJECT_USER_MAPPING:
1107  address = get_object_address_usermapping(castNode(List, object),
1108  missing_ok);
1109  break;
1112  &relation,
1113  missing_ok);
1114  break;
1115  case OBJECT_DEFACL:
1116  address = get_object_address_defacl(castNode(List, object),
1117  missing_ok);
1118  break;
1119  case OBJECT_STATISTIC_EXT:
1120  address.classId = StatisticExtRelationId;
1121  address.objectId = get_statistics_object_oid(castNode(List, object),
1122  missing_ok);
1123  address.objectSubId = 0;
1124  break;
1125  default:
1126  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1127  /* placate compiler, in case it thinks elog might return */
1128  address.classId = InvalidOid;
1129  address.objectId = InvalidOid;
1130  address.objectSubId = 0;
1131  }
1132 
1133  /*
1134  * If we could not find the supplied object, return without locking.
1135  */
1136  if (!OidIsValid(address.objectId))
1137  {
1138  Assert(missing_ok);
1139  return address;
1140  }
1141 
1142  /*
1143  * If we're retrying, see if we got the same answer as last time. If
1144  * so, we're done; if not, we locked the wrong thing, so give up our
1145  * lock.
1146  */
1147  if (OidIsValid(old_address.classId))
1148  {
1149  if (old_address.classId == address.classId
1150  && old_address.objectId == address.objectId
1151  && old_address.objectSubId == address.objectSubId)
1152  break;
1153  if (old_address.classId != RelationRelationId)
1154  {
1155  if (IsSharedRelation(old_address.classId))
1156  UnlockSharedObject(old_address.classId,
1157  old_address.objectId,
1158  0, lockmode);
1159  else
1160  UnlockDatabaseObject(old_address.classId,
1161  old_address.objectId,
1162  0, lockmode);
1163  }
1164  }
1165 
1166  /*
1167  * If we're dealing with a relation or attribute, then the relation is
1168  * already locked. Otherwise, we lock it now.
1169  */
1170  if (address.classId != RelationRelationId)
1171  {
1172  if (IsSharedRelation(address.classId))
1173  LockSharedObject(address.classId, address.objectId, 0,
1174  lockmode);
1175  else
1176  LockDatabaseObject(address.classId, address.objectId, 0,
1177  lockmode);
1178  }
1179 
1180  /*
1181  * At this point, we've resolved the name to an OID and locked the
1182  * corresponding database object. However, it's possible that by the
1183  * time we acquire the lock on the object, concurrent DDL has modified
1184  * the database in such a way that the name we originally looked up no
1185  * longer resolves to that OID.
1186  *
1187  * We can be certain that this isn't an issue if (a) no shared
1188  * invalidation messages have been processed or (b) we've locked a
1189  * relation somewhere along the line. All the relation name lookups
1190  * in this module ultimately use RangeVarGetRelid() to acquire a
1191  * relation lock, and that function protects against the same kinds of
1192  * races we're worried about here. Even when operating on a
1193  * constraint, rule, or trigger, we still acquire AccessShareLock on
1194  * the relation, which is enough to freeze out any concurrent DDL.
1195  *
1196  * In all other cases, however, it's possible that the name we looked
1197  * up no longer refers to the object we locked, so we retry the lookup
1198  * and see whether we get the same answer.
1199  */
1200  if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1201  break;
1202  old_address = address;
1203  }
1204 
1205  /* Return the object address and the relation. */
1206  *relp = relation;
1207  return address;
1208 }
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:598
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:228
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2679
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial_node(type, l)
Definition: pg_list.h:198
static ObjectAddress get_object_address_unqualified(ObjectType objtype, Value *strval, bool missing_ok)
#define OidIsValid(objectId)
Definition: c.h:644
#define lsecond(l)
Definition: pg_list.h:200
static ObjectAddress get_relation_by_qualified_name(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static ObjectAddress get_object_address_attrdef(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2426
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
#define ERROR
Definition: elog.h:43
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1023
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2178
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2553
#define NoLock
Definition: lockdefs.h:34
static ObjectAddress get_object_address_relobject(ObjectType objtype, List *object, Relation *relp, bool missing_ok)
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:961
static ObjectAddress get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
static ObjectAddress get_object_address_defacl(List *object, bool missing_ok)
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:982
#define lsecond_node(type, l)
Definition: pg_list.h:203
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:238
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1002
uint64 SharedInvalidMessageCounter
Definition: sinval.c:26
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2300
#define Assert(condition)
Definition: c.h:738
Definition: value.h:42
static ObjectAddress get_object_address_opf_member(ObjectType objtype, List *object, bool missing_ok)
Oid get_conversion_oid(List *name, bool missing_ok)
Definition: namespace.c:3655
bool LargeObjectExists(Oid loid)
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
Definition: parse_func.c:2163
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
Definition: lsyscache.c:1005
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3601
Definition: pg_list.h:50
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition: parse_type.c:232

◆ get_object_address_attrdef()

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

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

1541 {
1542  ObjectAddress address;
1543  List *relname;
1544  Oid reloid;
1545  Relation relation;
1546  const char *attname;
1548  TupleDesc tupdesc;
1549  Oid defoid;
1550 
1551  /* Extract relation name and open relation. */
1552  if (list_length(object) < 2)
1553  ereport(ERROR,
1554  (errcode(ERRCODE_SYNTAX_ERROR),
1555  errmsg("column name must be qualified")));
1556  attname = strVal(llast(object));
1557  relname = list_truncate(list_copy(object), list_length(object) - 1);
1558  /* XXX no missing_ok support here */
1559  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1560  reloid = RelationGetRelid(relation);
1561 
1562  tupdesc = RelationGetDescr(relation);
1563 
1564  /* Look up attribute number and scan pg_attrdef to find its tuple */
1565  attnum = get_attnum(reloid, attname);
1566  defoid = InvalidOid;
1567  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1568  {
1569  Relation attrdef;
1570  ScanKeyData keys[2];
1571  SysScanDesc scan;
1572  HeapTuple tup;
1573 
1574  attrdef = relation_open(AttrDefaultRelationId, AccessShareLock);
1575  ScanKeyInit(&keys[0],
1576  Anum_pg_attrdef_adrelid,
1578  F_OIDEQ,
1579  ObjectIdGetDatum(reloid));
1580  ScanKeyInit(&keys[1],
1581  Anum_pg_attrdef_adnum,
1583  F_INT2EQ,
1584  Int16GetDatum(attnum));
1585  scan = systable_beginscan(attrdef, AttrDefaultIndexId, true,
1586  NULL, 2, keys);
1587  if (HeapTupleIsValid(tup = systable_getnext(scan)))
1588  {
1589  Form_pg_attrdef atdform = (Form_pg_attrdef) GETSTRUCT(tup);
1590 
1591  defoid = atdform->oid;
1592  }
1593 
1594  systable_endscan(scan);
1595  relation_close(attrdef, AccessShareLock);
1596  }
1597  if (!OidIsValid(defoid))
1598  {
1599  if (!missing_ok)
1600  ereport(ERROR,
1601  (errcode(ERRCODE_UNDEFINED_COLUMN),
1602  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1603  attname, NameListToString(relname))));
1604 
1605  address.classId = AttrDefaultRelationId;
1606  address.objectId = InvalidOid;
1607  address.objectSubId = InvalidAttrNumber;
1608  relation_close(relation, lockmode);
1609  return address;
1610  }
1611 
1612  address.classId = AttrDefaultRelationId;
1613  address.objectId = defoid;
1614  address.objectSubId = 0;
1615 
1616  *relp = relation;
1617  return address;
1618 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:529
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define RelationGetDescr(relation)
Definition: rel.h:482
#define llast(l)
Definition: pg_list.h:215
#define Int16GetDatum(X)
Definition: postgres.h:451
List * list_truncate(List *list, int new_size)
Definition: list.c:585
#define AccessShareLock
Definition: lockdefs.h:36
List * list_copy(const List *oldlist)
Definition: list.c:1403
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:356
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:448
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
NameData attname
Definition: pg_attribute.h:40
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
#define AttrDefaultIndexId
Definition: indexing.h:89
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:856
TupleConstr * constr
Definition: tupdesc.h:85
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * NameListToString(List *names)
Definition: namespace.c:3102
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
static int list_length(const List *l)
Definition: pg_list.h:169
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:824
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:456
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ get_object_address_attribute()

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

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

1490 {
1491  ObjectAddress address;
1492  List *relname;
1493  Oid reloid;
1494  Relation relation;
1495  const char *attname;
1497 
1498  /* Extract relation name and open relation. */
1499  if (list_length(object) < 2)
1500  ereport(ERROR,
1501  (errcode(ERRCODE_SYNTAX_ERROR),
1502  errmsg("column name must be qualified")));
1503  attname = strVal(lfirst(list_tail(object)));
1504  relname = list_truncate(list_copy(object), list_length(object) - 1);
1505  /* XXX no missing_ok support here */
1506  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1507  reloid = RelationGetRelid(relation);
1508 
1509  /* Look up attribute and construct return value. */
1510  attnum = get_attnum(reloid, attname);
1511  if (attnum == InvalidAttrNumber)
1512  {
1513  if (!missing_ok)
1514  ereport(ERROR,
1515  (errcode(ERRCODE_UNDEFINED_COLUMN),
1516  errmsg("column \"%s\" of relation \"%s\" does not exist",
1517  attname, NameListToString(relname))));
1518 
1519  address.classId = RelationRelationId;
1520  address.objectId = InvalidOid;
1521  address.objectSubId = InvalidAttrNumber;
1522  relation_close(relation, lockmode);
1523  return address;
1524  }
1525 
1526  address.classId = RelationRelationId;
1527  address.objectId = reloid;
1528  address.objectSubId = attnum;
1529 
1530  *relp = relation;
1531  return address;
1532 }
List * list_truncate(List *list, int new_size)
Definition: list.c:585
List * list_copy(const List *oldlist)
Definition: list.c:1403
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
NameData attname
Definition: pg_attribute.h:40
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:856
char * NameListToString(List *names)
Definition: namespace.c:3102
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define ereport(elevel,...)
Definition: elog.h:144
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define lfirst(lc)
Definition: pg_list.h:190
static int list_length(const List *l)
Definition: pg_list.h:169
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:824
static ListCell * list_tail(const List *l)
Definition: pg_list.h:132
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:456

◆ get_object_address_defacl()

static ObjectAddress get_object_address_defacl ( List object,
bool  missing_ok 
)
static

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

1937 {
1938  HeapTuple tp;
1939  Oid userid;
1940  Oid schemaid;
1941  char *username;
1942  char *schema;
1943  char objtype;
1944  char *objtype_str;
1945  ObjectAddress address;
1946 
1947  ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
1948 
1949  /*
1950  * First figure out the textual attributes so that they can be used for
1951  * error reporting.
1952  */
1953  username = strVal(lsecond(object));
1954  if (list_length(object) >= 3)
1955  schema = (char *) strVal(lthird(object));
1956  else
1957  schema = NULL;
1958 
1959  /*
1960  * Decode defaclobjtype. Only first char is considered; the rest of the
1961  * string, if any, is blissfully ignored.
1962  */
1963  objtype = ((char *) strVal(linitial(object)))[0];
1964  switch (objtype)
1965  {
1966  case DEFACLOBJ_RELATION:
1967  objtype_str = "tables";
1968  break;
1969  case DEFACLOBJ_SEQUENCE:
1970  objtype_str = "sequences";
1971  break;
1972  case DEFACLOBJ_FUNCTION:
1973  objtype_str = "functions";
1974  break;
1975  case DEFACLOBJ_TYPE:
1976  objtype_str = "types";
1977  break;
1978  case DEFACLOBJ_NAMESPACE:
1979  objtype_str = "schemas";
1980  break;
1981  default:
1982  ereport(ERROR,
1983  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1984  errmsg("unrecognized default ACL object type \"%c\"", objtype),
1985  errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
1986  DEFACLOBJ_RELATION,
1987  DEFACLOBJ_SEQUENCE,
1988  DEFACLOBJ_FUNCTION,
1989  DEFACLOBJ_TYPE,
1990  DEFACLOBJ_NAMESPACE)));
1991  }
1992 
1993  /*
1994  * Look up user ID. Behave as "default ACL not found" if the user doesn't
1995  * exist.
1996  */
1998  CStringGetDatum(username));
1999  if (!HeapTupleIsValid(tp))
2000  goto not_found;
2001  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
2002  ReleaseSysCache(tp);
2003 
2004  /*
2005  * If a schema name was given, look up its OID. If it doesn't exist,
2006  * behave as "default ACL not found".
2007  */
2008  if (schema)
2009  {
2010  schemaid = get_namespace_oid(schema, true);
2011  if (schemaid == InvalidOid)
2012  goto not_found;
2013  }
2014  else
2015  schemaid = InvalidOid;
2016 
2017  /* Finally, look up the pg_default_acl object */
2019  ObjectIdGetDatum(userid),
2020  ObjectIdGetDatum(schemaid),
2021  CharGetDatum(objtype));
2022  if (!HeapTupleIsValid(tp))
2023  goto not_found;
2024 
2025  address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
2026  ReleaseSysCache(tp);
2027 
2028  return address;
2029 
2030 not_found:
2031  if (!missing_ok)
2032  {
2033  if (schema)
2034  ereport(ERROR,
2035  (errcode(ERRCODE_UNDEFINED_OBJECT),
2036  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
2037  username, schema, objtype_str)));
2038  else
2039  ereport(ERROR,
2040  (errcode(ERRCODE_UNDEFINED_OBJECT),
2041  errmsg("default ACL for user \"%s\" on %s does not exist",
2042  username, objtype_str)));
2043  }
2044  return address;
2045 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3043
int errhint(const char *fmt,...)
Definition: elog.c:1071
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:200
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
#define linitial(l)
Definition: pg_list.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Definition: syscache.c:1138
FormData_pg_default_acl * Form_pg_default_acl
#define CStringGetDatum(X)
Definition: postgres.h:578
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
static char * username
Definition: initdb.c:133
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static int list_length(const List *l)
Definition: pg_list.h:169
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define CharGetDatum(X)
Definition: postgres.h:416
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define lthird(l)
Definition: pg_list.h:205

◆ get_object_address_opcf()

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

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

1664 {
1665  Oid amoid;
1666  ObjectAddress address;
1667 
1668  /* XXX no missing_ok support here */
1669  amoid = get_index_am_oid(strVal(linitial(object)), false);
1670  object = list_copy_tail(object, 1);
1671 
1672  switch (objtype)
1673  {
1674  case OBJECT_OPCLASS:
1675  address.classId = OperatorClassRelationId;
1676  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1677  address.objectSubId = 0;
1678  break;
1679  case OBJECT_OPFAMILY:
1680  address.classId = OperatorFamilyRelationId;
1681  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1682  address.objectSubId = 0;
1683  break;
1684  default:
1685  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1686  /* placate compiler, which doesn't know elog won't return */
1687  address.classId = InvalidOid;
1688  address.objectId = InvalidOid;
1689  address.objectSubId = 0;
1690  }
1691 
1692  return address;
1693 }
#define strVal(v)
Definition: value.h:54
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c:223
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1422
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:163
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)
Definition: opclasscmds.c:142
#define elog(elevel,...)
Definition: elog.h:214

◆ get_object_address_opf_member()

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

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

1703 {
1704  ObjectAddress famaddr;
1705  ObjectAddress address;
1706  ListCell *cell;
1707  List *copy;
1708  TypeName *typenames[2];
1709  Oid typeoids[2];
1710  int membernum;
1711  int i;
1712 
1713  /*
1714  * The last element of the object list contains the strategy or procedure
1715  * number. We need to strip that out before getting the opclass/family
1716  * address. The rest can be used directly by get_object_address_opcf().
1717  */
1718  membernum = atoi(strVal(llast(linitial(object))));
1719  copy = list_truncate(list_copy(linitial(object)), list_length(linitial(object)) - 1);
1720 
1721  /* no missing_ok support here */
1722  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1723 
1724  /* find out left/right type names and OIDs */
1725  typenames[0] = typenames[1] = NULL;
1726  typeoids[0] = typeoids[1] = InvalidOid;
1727  i = 0;
1728  foreach(cell, lsecond(object))
1729  {
1730  ObjectAddress typaddr;
1731 
1732  typenames[i] = lfirst_node(TypeName, cell);
1733  typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
1734  typeoids[i] = typaddr.objectId;
1735  if (++i >= 2)
1736  break;
1737  }
1738 
1739  switch (objtype)
1740  {
1741  case OBJECT_AMOP:
1742  {
1743  HeapTuple tp;
1744 
1745  ObjectAddressSet(address, AccessMethodOperatorRelationId,
1746  InvalidOid);
1747 
1749  ObjectIdGetDatum(famaddr.objectId),
1750  ObjectIdGetDatum(typeoids[0]),
1751  ObjectIdGetDatum(typeoids[1]),
1752  Int16GetDatum(membernum));
1753  if (!HeapTupleIsValid(tp))
1754  {
1755  if (!missing_ok)
1756  ereport(ERROR,
1757  (errcode(ERRCODE_UNDEFINED_OBJECT),
1758  errmsg("operator %d (%s, %s) of %s does not exist",
1759  membernum,
1760  TypeNameToString(typenames[0]),
1761  TypeNameToString(typenames[1]),
1762  getObjectDescription(&famaddr))));
1763  }
1764  else
1765  {
1766  address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
1767  ReleaseSysCache(tp);
1768  }
1769  }
1770  break;
1771 
1772  case OBJECT_AMPROC:
1773  {
1774  HeapTuple tp;
1775 
1776  ObjectAddressSet(address, AccessMethodProcedureRelationId,
1777  InvalidOid);
1778 
1780  ObjectIdGetDatum(famaddr.objectId),
1781  ObjectIdGetDatum(typeoids[0]),
1782  ObjectIdGetDatum(typeoids[1]),
1783  Int16GetDatum(membernum));
1784  if (!HeapTupleIsValid(tp))
1785  {
1786  if (!missing_ok)
1787  ereport(ERROR,
1788  (errcode(ERRCODE_UNDEFINED_OBJECT),
1789  errmsg("function %d (%s, %s) of %s does not exist",
1790  membernum,
1791  TypeNameToString(typenames[0]),
1792  TypeNameToString(typenames[1]),
1793  getObjectDescription(&famaddr))));
1794  }
1795  else
1796  {
1797  address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
1798  ReleaseSysCache(tp);
1799  }
1800  }
1801  break;
1802  default:
1803  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1804  }
1805 
1806  return address;
1807 }
#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:585
List * list_copy(const List *oldlist)
Definition: list.c:1403
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:200
char * getObjectDescription(const ObjectAddress *object)
#define linitial(l)
Definition: pg_list.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define lfirst_node(type, lc)
Definition: pg_list.h:193
static ObjectAddress get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:1149
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static int list_length(const List *l)
Definition: pg_list.h:169
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:824
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
#define elog(elevel,...)
Definition: elog.h:214
int i
Definition: pg_list.h:50

◆ get_object_address_publication_rel()

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

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

1886 {
1887  ObjectAddress address;
1888  Relation relation;
1889  List *relname;
1890  char *pubname;
1891  Publication *pub;
1892 
1893  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1894 
1895  relname = linitial(object);
1897  AccessShareLock, missing_ok);
1898  if (!relation)
1899  return address;
1900 
1901  /* fetch publication name from input list */
1902  pubname = strVal(lsecond(object));
1903 
1904  /* Now look up the pg_publication tuple */
1905  pub = GetPublicationByName(pubname, missing_ok);
1906  if (!pub)
1907  {
1908  relation_close(relation, AccessShareLock);
1909  return address;
1910  }
1911 
1912  /* Find the publication relation mapping in syscache. */
1913  address.objectId =
1914  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1916  ObjectIdGetDatum(pub->oid));
1917  if (!OidIsValid(address.objectId))
1918  {
1919  if (!missing_ok)
1920  ereport(ERROR,
1921  (errcode(ERRCODE_UNDEFINED_OBJECT),
1922  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1923  RelationGetRelationName(relation), pubname)));
1924  relation_close(relation, AccessShareLock);
1925  return address;
1926  }
1927 
1928  *relp = relation;
1929  return address;
1930 }
#define AccessShareLock
Definition: lockdefs.h:36
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
NameData relname
Definition: pg_class.h:38
#define OidIsValid(objectId)
Definition: c.h:644
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
#define lsecond(l)
Definition: pg_list.h:200
#define linitial(l)
Definition: pg_list.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:490
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:194
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:456
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: relation.c:173

◆ get_object_address_relobject()

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

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

1410 {
1411  ObjectAddress address;
1412  Relation relation = NULL;
1413  int nnames;
1414  const char *depname;
1415  List *relname;
1416  Oid reloid;
1417 
1418  /* Extract name of dependent object. */
1419  depname = strVal(llast(object));
1420 
1421  /* Separate relation name from dependent object name. */
1422  nnames = list_length(object);
1423  if (nnames < 2)
1424  ereport(ERROR,
1425  (errcode(ERRCODE_SYNTAX_ERROR),
1426  errmsg("must specify relation and object name")));
1427 
1428  /* Extract relation name and open relation. */
1429  relname = list_truncate(list_copy(object), nnames - 1);
1430  relation = table_openrv_extended(makeRangeVarFromNameList(relname),
1432  missing_ok);
1433 
1434  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1435 
1436  switch (objtype)
1437  {
1438  case OBJECT_RULE:
1439  address.classId = RewriteRelationId;
1440  address.objectId = relation ?
1441  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1442  address.objectSubId = 0;
1443  break;
1444  case OBJECT_TRIGGER:
1445  address.classId = TriggerRelationId;
1446  address.objectId = relation ?
1447  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1448  address.objectSubId = 0;
1449  break;
1450  case OBJECT_TABCONSTRAINT:
1451  address.classId = ConstraintRelationId;
1452  address.objectId = relation ?
1453  get_relation_constraint_oid(reloid, depname, missing_ok) :
1454  InvalidOid;
1455  address.objectSubId = 0;
1456  break;
1457  case OBJECT_POLICY:
1458  address.classId = PolicyRelationId;
1459  address.objectId = relation ?
1460  get_relation_policy_oid(reloid, depname, missing_ok) :
1461  InvalidOid;
1462  address.objectSubId = 0;
1463  break;
1464  default:
1465  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1466  }
1467 
1468  /* Avoid relcache leak when object not found. */
1469  if (!OidIsValid(address.objectId))
1470  {
1471  if (relation != NULL)
1472  table_close(relation, AccessShareLock);
1473 
1474  relation = NULL; /* department of accident prevention */
1475  return address;
1476  }
1477 
1478  /* Done. */
1479  *relp = relation;
1480  return address;
1481 }
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:585
#define AccessShareLock
Definition: lockdefs.h:36
List * list_copy(const List *oldlist)
Definition: list.c:1403
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:644
#define ERROR
Definition: elog.h:43
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
Oid get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
Definition: policy.c:1327
static int list_length(const List *l)
Definition: pg_list.h:169
Oid get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
Definition: trigger.c:1239
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:456

◆ get_object_address_rv()

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

Definition at line 1218 of file objectaddress.c.

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

Referenced by ExecAlterObjectDependsStmt().

1221 {
1222  if (rel)
1223  {
1224  object = lcons(makeString(rel->relname), object);
1225  if (rel->schemaname)
1226  object = lcons(makeString(rel->schemaname), object);
1227  if (rel->catalogname)
1228  object = lcons(makeString(rel->catalogname), object);
1229  }
1230 
1231  return get_object_address(objtype, (Node *) object,
1232  relp, lockmode, missing_ok);
1233 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:529
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
List * lcons(void *datum, List *list)
Definition: list.c:453
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 1624 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().

1625 {
1626  ObjectAddress address;
1627  Type tup;
1628 
1629  address.classId = TypeRelationId;
1630  address.objectId = InvalidOid;
1631  address.objectSubId = 0;
1632 
1633  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1634  if (!HeapTupleIsValid(tup))
1635  {
1636  if (!missing_ok)
1637  ereport(ERROR,
1638  (errcode(ERRCODE_UNDEFINED_OBJECT),
1639  errmsg("type \"%s\" does not exist",
1640  TypeNameToString(typename))));
1641  return address;
1642  }
1643  address.objectId = typeTypeId(tup);
1644 
1645  if (objtype == OBJECT_DOMAIN)
1646  {
1647  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1648  ereport(ERROR,
1649  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1650  errmsg("\"%s\" is not a domain",
1651  TypeNameToString(typename))));
1652  }
1653 
1654  ReleaseSysCache(tup);
1655 
1656  return address;
1657 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:38
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:476
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
int errmsg(const char *fmt,...)
Definition: elog.c:824
Oid typeTypeId(Type tp)
Definition: parse_type.c:588

◆ get_object_address_unqualified()

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

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

1242 {
1243  const char *name;
1244  ObjectAddress address;
1245 
1246  name = strVal(strval);
1247 
1248  /* Translate name to OID. */
1249  switch (objtype)
1250  {
1251  case OBJECT_ACCESS_METHOD:
1252  address.classId = AccessMethodRelationId;
1253  address.objectId = get_am_oid(name, missing_ok);
1254  address.objectSubId = 0;
1255  break;
1256  case OBJECT_DATABASE:
1257  address.classId = DatabaseRelationId;
1258  address.objectId = get_database_oid(name, missing_ok);
1259  address.objectSubId = 0;
1260  break;
1261  case OBJECT_EXTENSION:
1262  address.classId = ExtensionRelationId;
1263  address.objectId = get_extension_oid(name, missing_ok);
1264  address.objectSubId = 0;
1265  break;
1266  case OBJECT_TABLESPACE:
1267  address.classId = TableSpaceRelationId;
1268  address.objectId = get_tablespace_oid(name, missing_ok);
1269  address.objectSubId = 0;
1270  break;
1271  case OBJECT_ROLE:
1272  address.classId = AuthIdRelationId;
1273  address.objectId = get_role_oid(name, missing_ok);
1274  address.objectSubId = 0;
1275  break;
1276  case OBJECT_SCHEMA:
1277  address.classId = NamespaceRelationId;
1278  address.objectId = get_namespace_oid(name, missing_ok);
1279  address.objectSubId = 0;
1280  break;
1281  case OBJECT_LANGUAGE:
1282  address.classId = LanguageRelationId;
1283  address.objectId = get_language_oid(name, missing_ok);
1284  address.objectSubId = 0;
1285  break;
1286  case OBJECT_FDW:
1287  address.classId = ForeignDataWrapperRelationId;
1288  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1289  address.objectSubId = 0;
1290  break;
1291  case OBJECT_FOREIGN_SERVER:
1292  address.classId = ForeignServerRelationId;
1293  address.objectId = get_foreign_server_oid(name, missing_ok);
1294  address.objectSubId = 0;
1295  break;
1296  case OBJECT_EVENT_TRIGGER:
1297  address.classId = EventTriggerRelationId;
1298  address.objectId = get_event_trigger_oid(name, missing_ok);
1299  address.objectSubId = 0;
1300  break;
1301  case OBJECT_PUBLICATION:
1302  address.classId = PublicationRelationId;
1303  address.objectId = get_publication_oid(name, missing_ok);
1304  address.objectSubId = 0;
1305  break;
1306  case OBJECT_SUBSCRIPTION:
1307  address.classId = SubscriptionRelationId;
1308  address.objectId = get_subscription_oid(name, missing_ok);
1309  address.objectSubId = 0;
1310  break;
1311  default:
1312  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1313  /* placate compiler, which doesn't know elog won't return */
1314  address.classId = InvalidOid;
1315  address.objectId = InvalidOid;
1316  address.objectSubId = 0;
1317  }
1318 
1319  return address;
1320 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1421
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3043
Oid get_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:183
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:228
#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:5175
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:561
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:140
#define elog(elevel,...)
Definition: elog.h:214
Oid get_publication_oid(const char *pubname, bool missing_ok)
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:714

◆ get_object_address_usermapping()

static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

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

1814 {
1815  ObjectAddress address;
1816  Oid userid;
1817  char *username;
1818  char *servername;
1819  ForeignServer *server;
1820  HeapTuple tp;
1821 
1822  ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1823 
1824  /* fetch string names from input lists, for error messages */
1825  username = strVal(linitial(object));
1826  servername = strVal(lsecond(object));
1827 
1828  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1829  if (strcmp(username, "public") == 0)
1830  userid = InvalidOid;
1831  else
1832  {
1834  CStringGetDatum(username));
1835  if (!HeapTupleIsValid(tp))
1836  {
1837  if (!missing_ok)
1838  ereport(ERROR,
1839  (errcode(ERRCODE_UNDEFINED_OBJECT),
1840  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1841  username, servername)));
1842  return address;
1843  }
1844  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1845  ReleaseSysCache(tp);
1846  }
1847 
1848  /* Now look up the pg_user_mapping tuple */
1849  server = GetForeignServerByName(servername, true);
1850  if (!server)
1851  {
1852  if (!missing_ok)
1853  ereport(ERROR,
1854  (errcode(ERRCODE_UNDEFINED_OBJECT),
1855  errmsg("server \"%s\" does not exist", servername)));
1856  return address;
1857  }
1858  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1859  ObjectIdGetDatum(userid),
1860  ObjectIdGetDatum(server->serverid));
1861  if (!HeapTupleIsValid(tp))
1862  {
1863  if (!missing_ok)
1864  ereport(ERROR,
1865  (errcode(ERRCODE_UNDEFINED_OBJECT),
1866  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1867  username, servername)));
1868  return address;
1869  }
1870 
1871  address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1872 
1873  ReleaseSysCache(tp);
1874 
1875  return address;
1876 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:610
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:200
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
#define linitial(l)
Definition: pg_list.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
FormData_pg_user_mapping * Form_pg_user_mapping
#define CStringGetDatum(X)
Definition: postgres.h:578
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
Definition: foreign.c:180
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
static char * username
Definition: initdb.c:133
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1127
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:824
Oid serverid
Definition: foreign.h:36

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2706 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2707 {
2708  const ObjectPropertyType *prop = get_object_property_data(class_id);
2709 
2710  return prop->attnum_acl;
2711 }
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 2682 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().

2683 {
2684  const ObjectPropertyType *prop = get_object_property_data(class_id);
2685 
2686  return prop->attnum_name;
2687 }
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 2690 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().

2691 {
2692  const ObjectPropertyType *prop = get_object_property_data(class_id);
2693 
2694  return prop->attnum_namespace;
2695 }
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 2674 of file objectaddress.c.

References ObjectPropertyType::attnum_oid, and get_object_property_data().

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

2675 {
2676  const ObjectPropertyType *prop = get_object_property_data(class_id);
2677 
2678  return prop->attnum_oid;
2679 }
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 2698 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2699 {
2700  const ObjectPropertyType *prop = get_object_property_data(class_id);
2701 
2702  return prop->attnum_owner;
2703 }
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 2666 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2667 {
2668  const ObjectPropertyType *prop = get_object_property_data(class_id);
2669 
2670  return prop->name_catcache_id;
2671 }
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 2658 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_catcache_id.

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

2659 {
2660  const ObjectPropertyType *prop = get_object_property_data(class_id);
2661 
2662  return prop->oid_catcache_id;
2663 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_class_descr()

const char* get_object_class_descr ( Oid  class_id)

Definition at line 2642 of file objectaddress.c.

References ObjectPropertyType::class_descr, and get_object_property_data().

Referenced by DropObjectById().

2643 {
2644  const ObjectPropertyType *prop = get_object_property_data(class_id);
2645 
2646  return prop->class_descr;
2647 }
const char * class_descr
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 2739 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2740 {
2741  const ObjectPropertyType *prop = get_object_property_data(class_id);
2742 
2743  return prop->is_nsp_name_unique;
2744 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

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

2584 {
2585  int cache;
2586  HeapTuple tuple;
2587  bool isnull;
2588  Oid oid;
2589  const ObjectPropertyType *property;
2590 
2591  /* If not owned by a namespace, just return InvalidOid. */
2592  property = get_object_property_data(address->classId);
2593  if (property->attnum_namespace == InvalidAttrNumber)
2594  return InvalidOid;
2595 
2596  /* Currently, we can only handle object types with system caches. */
2597  cache = property->oid_catcache_id;
2598  Assert(cache != -1);
2599 
2600  /* Fetch tuple from syscache and extract namespace attribute. */
2601  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2602  if (!HeapTupleIsValid(tuple))
2603  elog(ERROR, "cache lookup failed for cache %d oid %u",
2604  cache, address->objectId);
2605  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2606  tuple,
2607  property->attnum_namespace,
2608  &isnull));
2609  Assert(!isnull);
2610  ReleaseSysCache(tuple);
2611 
2612  return oid;
2613 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1377
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:738
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog(elevel,...)
Definition: elog.h:214

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2650 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by DropObjectById(), and get_catalog_object_by_oid().

2651 {
2652  const ObjectPropertyType *prop = get_object_property_data(class_id);
2653 
2654  return prop->oid_index_oid;
2655 }
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 2768 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_class_descr(), get_object_namensp_unique(), get_object_namespace(), get_object_oid_index(), and get_object_type().

2769 {
2770  static const ObjectPropertyType *prop_last = NULL;
2771  int index;
2772 
2773  /*
2774  * A shortcut to speed up multiple consecutive lookups of a particular
2775  * object class.
2776  */
2777  if (prop_last && prop_last->class_oid == class_id)
2778  return prop_last;
2779 
2780  for (index = 0; index < lengthof(ObjectProperty); index++)
2781  {
2782  if (ObjectProperty[index].class_oid == class_id)
2783  {
2784  prop_last = &ObjectProperty[index];
2785  return &ObjectProperty[index];
2786  }
2787  }
2788 
2789  ereport(ERROR,
2790  (errmsg_internal("unrecognized class ID: %u", class_id)));
2791 
2792  return NULL; /* keep MSC compiler happy */
2793 }
#define lengthof(array)
Definition: c.h:668
Definition: type.h:89
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType ObjectProperty[]
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:911

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

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

2722 {
2723  const ObjectPropertyType *prop = get_object_property_data(class_id);
2724 
2725  if (prop->objtype == OBJECT_TABLE)
2726  {
2727  /*
2728  * If the property data says it's a table, dig a little deeper to get
2729  * the real relation kind, so that callers can produce more precise
2730  * error messages.
2731  */
2732  return get_relkind_objtype(get_rel_relkind(object_id));
2733  }
2734  else
2735  return prop->objtype;
2736 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1915
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 1326 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().

1329 {
1330  Relation relation;
1331  ObjectAddress address;
1332 
1333  address.classId = RelationRelationId;
1334  address.objectId = InvalidOid;
1335  address.objectSubId = 0;
1336 
1338  lockmode, missing_ok);
1339  if (!relation)
1340  return address;
1341 
1342  switch (objtype)
1343  {
1344  case OBJECT_INDEX:
1345  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1346  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1347  ereport(ERROR,
1348  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1349  errmsg("\"%s\" is not an index",
1350  RelationGetRelationName(relation))));
1351  break;
1352  case OBJECT_SEQUENCE:
1353  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1354  ereport(ERROR,
1355  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1356  errmsg("\"%s\" is not a sequence",
1357  RelationGetRelationName(relation))));
1358  break;
1359  case OBJECT_TABLE:
1360  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1361  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1362  ereport(ERROR,
1363  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1364  errmsg("\"%s\" is not a table",
1365  RelationGetRelationName(relation))));
1366  break;
1367  case OBJECT_VIEW:
1368  if (relation->rd_rel->relkind != RELKIND_VIEW)
1369  ereport(ERROR,
1370  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1371  errmsg("\"%s\" is not a view",
1372  RelationGetRelationName(relation))));
1373  break;
1374  case OBJECT_MATVIEW:
1375  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1376  ereport(ERROR,
1377  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1378  errmsg("\"%s\" is not a materialized view",
1379  RelationGetRelationName(relation))));
1380  break;
1381  case OBJECT_FOREIGN_TABLE:
1382  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1383  ereport(ERROR,
1384  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1385  errmsg("\"%s\" is not a foreign table",
1386  RelationGetRelationName(relation))));
1387  break;
1388  default:
1389  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1390  break;
1391  }
1392 
1393  /* Done. */
1394  address.objectId = RelationGetRelid(relation);
1395  *relp = relation;
1396 
1397  return address;
1398 }
int errcode(int sqlerrcode)
Definition: elog.c:610
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3062
Form_pg_class rd_rel
Definition: rel.h:109
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:490
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
#define RelationGetRelid(relation)
Definition: rel.h:456
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: relation.c:173

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 5452 of file objectaddress.c.

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

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

5453 {
5454  switch (relkind)
5455  {
5456  case RELKIND_RELATION:
5457  case RELKIND_PARTITIONED_TABLE:
5458  return OBJECT_TABLE;
5459  case RELKIND_INDEX:
5460  case RELKIND_PARTITIONED_INDEX:
5461  return OBJECT_INDEX;
5462  case RELKIND_SEQUENCE:
5463  return OBJECT_SEQUENCE;
5464  case RELKIND_VIEW:
5465  return OBJECT_VIEW;
5466  case RELKIND_MATVIEW:
5467  return OBJECT_MATVIEW;
5468  case RELKIND_FOREIGN_TABLE:
5469  return OBJECT_FOREIGN_TABLE;
5470  case RELKIND_TOASTVALUE:
5471  return OBJECT_TABLE;
5472  default:
5473  /* Per above, don't raise an error */
5474  return OBJECT_TABLE;
5475  }
5476 }

◆ getConstraintTypeDescription()

static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid 
)
static

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

4324 {
4325  Relation constrRel;
4326  HeapTuple constrTup;
4327  Form_pg_constraint constrForm;
4328 
4329  constrRel = table_open(ConstraintRelationId, AccessShareLock);
4330  constrTup = get_catalog_object_by_oid(constrRel, Anum_pg_constraint_oid,
4331  constroid);
4332  if (!HeapTupleIsValid(constrTup))
4333  elog(ERROR, "cache lookup failed for constraint %u", constroid);
4334 
4335  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4336 
4337  if (OidIsValid(constrForm->conrelid))
4338  appendStringInfoString(buffer, "table constraint");
4339  else if (OidIsValid(constrForm->contypid))
4340  appendStringInfoString(buffer, "domain constraint");
4341  else
4342  elog(ERROR, "invalid constraint %u", constrForm->oid);
4343 
4344  table_close(constrRel, AccessShareLock);
4345 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define AccessShareLock
Definition: lockdefs.h:36
#define OidIsValid(objectId)
Definition: c.h:644
#define ERROR
Definition: elog.h:43
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
FormData_pg_constraint * Form_pg_constraint
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:214
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object)

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

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3760 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3761 {
3762  ObjectAddress address;
3763 
3764  address.classId = classid;
3765  address.objectId = objid;
3766  address.objectSubId = 0;
3767 
3768  return getObjectDescription(&address);
3769 }
char * getObjectDescription(const ObjectAddress *object)

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

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

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