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/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, bool missing_ok)
 
static void getOpFamilyDescription (StringInfo buffer, Oid opfid, bool missing_ok)
 
static void getRelationTypeDescription (StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok)
 
static void getProcedureTypeDescription (StringInfo buffer, Oid procid, bool missing_ok)
 
static void getConstraintTypeDescription (StringInfo buffer, Oid constroid, bool missing_ok)
 
static void getOpFamilyIdentity (StringInfo buffer, Oid opfid, List **object, bool missing_ok)
 
static void getRelationIdentity (StringInfo buffer, Oid relid, List **object, bool missing_ok)
 
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, bool missing_ok)
 
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, bool missing_ok)
 
char * getObjectIdentity (const ObjectAddress *object, bool missing_ok)
 
char * getObjectIdentityParts (const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
 
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 2365 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().

2367 {
2368  switch (objtype)
2369  {
2370  case OBJECT_INDEX:
2371  case OBJECT_SEQUENCE:
2372  case OBJECT_TABLE:
2373  case OBJECT_VIEW:
2374  case OBJECT_MATVIEW:
2375  case OBJECT_FOREIGN_TABLE:
2376  case OBJECT_COLUMN:
2377  case OBJECT_RULE:
2378  case OBJECT_TRIGGER:
2379  case OBJECT_POLICY:
2380  case OBJECT_TABCONSTRAINT:
2381  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2383  RelationGetRelationName(relation));
2384  break;
2385  case OBJECT_DATABASE:
2386  if (!pg_database_ownercheck(address.objectId, roleid))
2388  strVal((Value *) object));
2389  break;
2390  case OBJECT_TYPE:
2391  case OBJECT_DOMAIN:
2392  case OBJECT_ATTRIBUTE:
2393  if (!pg_type_ownercheck(address.objectId, roleid))
2395  break;
2396  case OBJECT_DOMCONSTRAINT:
2397  {
2398  HeapTuple tuple;
2399  Oid contypid;
2400 
2401  tuple = SearchSysCache1(CONSTROID,
2402  ObjectIdGetDatum(address.objectId));
2403  if (!HeapTupleIsValid(tuple))
2404  elog(ERROR, "constraint with OID %u does not exist",
2405  address.objectId);
2406 
2407  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2408 
2409  ReleaseSysCache(tuple);
2410 
2411  /*
2412  * Fallback to type ownership check in this case as this is
2413  * what domain constraints rely on.
2414  */
2415  if (!pg_type_ownercheck(contypid, roleid))
2417  }
2418  break;
2419  case OBJECT_AGGREGATE:
2420  case OBJECT_FUNCTION:
2421  case OBJECT_PROCEDURE:
2422  case OBJECT_ROUTINE:
2423  if (!pg_proc_ownercheck(address.objectId, roleid))
2425  NameListToString((castNode(ObjectWithArgs, object))->objname));
2426  break;
2427  case OBJECT_OPERATOR:
2428  if (!pg_oper_ownercheck(address.objectId, roleid))
2430  NameListToString((castNode(ObjectWithArgs, object))->objname));
2431  break;
2432  case OBJECT_SCHEMA:
2433  if (!pg_namespace_ownercheck(address.objectId, roleid))
2435  strVal((Value *) object));
2436  break;
2437  case OBJECT_COLLATION:
2438  if (!pg_collation_ownercheck(address.objectId, roleid))
2440  NameListToString(castNode(List, object)));
2441  break;
2442  case OBJECT_CONVERSION:
2443  if (!pg_conversion_ownercheck(address.objectId, roleid))
2445  NameListToString(castNode(List, object)));
2446  break;
2447  case OBJECT_EXTENSION:
2448  if (!pg_extension_ownercheck(address.objectId, roleid))
2450  strVal((Value *) object));
2451  break;
2452  case OBJECT_FDW:
2453  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2455  strVal((Value *) object));
2456  break;
2457  case OBJECT_FOREIGN_SERVER:
2458  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2460  strVal((Value *) object));
2461  break;
2462  case OBJECT_EVENT_TRIGGER:
2463  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2465  strVal((Value *) object));
2466  break;
2467  case OBJECT_LANGUAGE:
2468  if (!pg_language_ownercheck(address.objectId, roleid))
2470  strVal((Value *) object));
2471  break;
2472  case OBJECT_OPCLASS:
2473  if (!pg_opclass_ownercheck(address.objectId, roleid))
2475  NameListToString(castNode(List, object)));
2476  break;
2477  case OBJECT_OPFAMILY:
2478  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2480  NameListToString(castNode(List, object)));
2481  break;
2482  case OBJECT_LARGEOBJECT:
2483  if (!lo_compat_privileges &&
2484  !pg_largeobject_ownercheck(address.objectId, roleid))
2485  ereport(ERROR,
2486  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2487  errmsg("must be owner of large object %u",
2488  address.objectId)));
2489  break;
2490  case OBJECT_CAST:
2491  {
2492  /* We can only check permissions on the source/target types */
2493  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2494  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2495  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2496  Oid targettypeid = typenameTypeId(NULL, targettype);
2497 
2498  if (!pg_type_ownercheck(sourcetypeid, roleid)
2499  && !pg_type_ownercheck(targettypeid, roleid))
2500  ereport(ERROR,
2501  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2502  errmsg("must be owner of type %s or type %s",
2503  format_type_be(sourcetypeid),
2504  format_type_be(targettypeid))));
2505  }
2506  break;
2507  case OBJECT_PUBLICATION:
2508  if (!pg_publication_ownercheck(address.objectId, roleid))
2510  strVal((Value *) object));
2511  break;
2512  case OBJECT_SUBSCRIPTION:
2513  if (!pg_subscription_ownercheck(address.objectId, roleid))
2515  strVal((Value *) object));
2516  break;
2517  case OBJECT_TRANSFORM:
2518  {
2519  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2520  Oid typeid = typenameTypeId(NULL, typename);
2521 
2522  if (!pg_type_ownercheck(typeid, roleid))
2524  }
2525  break;
2526  case OBJECT_TABLESPACE:
2527  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2529  strVal((Value *) object));
2530  break;
2531  case OBJECT_TSDICTIONARY:
2532  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2534  NameListToString(castNode(List, object)));
2535  break;
2537  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2539  NameListToString(castNode(List, object)));
2540  break;
2541  case OBJECT_ROLE:
2542 
2543  /*
2544  * We treat roles as being "owned" by those with CREATEROLE priv,
2545  * except that superusers are only owned by superusers.
2546  */
2547  if (superuser_arg(address.objectId))
2548  {
2549  if (!superuser_arg(roleid))
2550  ereport(ERROR,
2551  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2552  errmsg("must be superuser")));
2553  }
2554  else
2555  {
2556  if (!has_createrole_privilege(roleid))
2557  ereport(ERROR,
2558  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2559  errmsg("must have CREATEROLE privilege")));
2560  }
2561  break;
2562  case OBJECT_TSPARSER:
2563  case OBJECT_TSTEMPLATE:
2564  case OBJECT_ACCESS_METHOD:
2565  /* We treat these object types as being owned by superusers */
2566  if (!superuser_arg(roleid))
2567  ereport(ERROR,
2568  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2569  errmsg("must be superuser")));
2570  break;
2571  case OBJECT_STATISTIC_EXT:
2572  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2574  break;
2575  default:
2576  elog(ERROR, "unrecognized object type: %d",
2577  (int) objtype);
2578  }
2579 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5315
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5134
#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:4823
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:4973
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4794
#define castNode(_type_, nodeptr)
Definition: nodes.h:597
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5000
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5054
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5228
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4742
int errcode(int sqlerrcode)
Definition: elog.c:704
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4866
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4716
#define linitial_node(type, l)
Definition: pg_list.h:177
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3610
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3297
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:45
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5081
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5186
#define RelationGetRelationName(relation)
Definition: rel.h:491
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4892
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:4946
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5108
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
char * NameListToString(List *names)
Definition: namespace.c:3101
#define lsecond_node(type, l)
Definition: pg_list.h:182
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4919
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5160
#define ereport(elevel,...)
Definition: elog.h:155
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:4690
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5027
int errmsg(const char *fmt,...)
Definition: elog.c:915
#define elog(elevel,...)
Definition: elog.h:228
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:457
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4768
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5254
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5280

◆ get_catalog_object_by_oid()

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

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

2809 {
2810  HeapTuple tuple;
2811  Oid classId = RelationGetRelid(catalog);
2812  int oidCacheId = get_object_catcache_oid(classId);
2813 
2814  if (oidCacheId > 0)
2815  {
2816  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2817  if (!HeapTupleIsValid(tuple)) /* should not happen */
2818  return NULL;
2819  }
2820  else
2821  {
2822  Oid oidIndexId = get_object_oid_index(classId);
2823  SysScanDesc scan;
2824  ScanKeyData skey;
2825 
2826  Assert(OidIsValid(oidIndexId));
2827 
2828  ScanKeyInit(&skey,
2829  oidcol,
2830  BTEqualStrategyNumber, F_OIDEQ,
2831  ObjectIdGetDatum(objectId));
2832 
2833  scan = systable_beginscan(catalog, oidIndexId, true,
2834  NULL, 1, &skey);
2835  tuple = systable_getnext(scan);
2836  if (!HeapTupleIsValid(tuple))
2837  {
2838  systable_endscan(scan);
2839  return NULL;
2840  }
2841  tuple = heap_copytuple(tuple);
2842 
2843  systable_endscan(scan);
2844  }
2845 
2846  return tuple;
2847 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:593
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:698
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:381
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:500
#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:792
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:175
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:457
#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 928 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().

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

1546 {
1547  ObjectAddress address;
1548  List *relname;
1549  Oid reloid;
1550  Relation relation;
1551  const char *attname;
1553  TupleDesc tupdesc;
1554  Oid defoid;
1555 
1556  /* Extract relation name and open relation. */
1557  if (list_length(object) < 2)
1558  ereport(ERROR,
1559  (errcode(ERRCODE_SYNTAX_ERROR),
1560  errmsg("column name must be qualified")));
1561  attname = strVal(llast(object));
1562  relname = list_truncate(list_copy(object), list_length(object) - 1);
1563  /* XXX no missing_ok support here */
1564  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1565  reloid = RelationGetRelid(relation);
1566 
1567  tupdesc = RelationGetDescr(relation);
1568 
1569  /* Look up attribute number and scan pg_attrdef to find its tuple */
1570  attnum = get_attnum(reloid, attname);
1571  defoid = InvalidOid;
1572  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1573  {
1574  Relation attrdef;
1575  ScanKeyData keys[2];
1576  SysScanDesc scan;
1577  HeapTuple tup;
1578 
1579  attrdef = relation_open(AttrDefaultRelationId, AccessShareLock);
1580  ScanKeyInit(&keys[0],
1581  Anum_pg_attrdef_adrelid,
1583  F_OIDEQ,
1584  ObjectIdGetDatum(reloid));
1585  ScanKeyInit(&keys[1],
1586  Anum_pg_attrdef_adnum,
1588  F_INT2EQ,
1589  Int16GetDatum(attnum));
1590  scan = systable_beginscan(attrdef, AttrDefaultIndexId, true,
1591  NULL, 2, keys);
1592  if (HeapTupleIsValid(tup = systable_getnext(scan)))
1593  {
1594  Form_pg_attrdef atdform = (Form_pg_attrdef) GETSTRUCT(tup);
1595 
1596  defoid = atdform->oid;
1597  }
1598 
1599  systable_endscan(scan);
1600  relation_close(attrdef, AccessShareLock);
1601  }
1602  if (!OidIsValid(defoid))
1603  {
1604  if (!missing_ok)
1605  ereport(ERROR,
1606  (errcode(ERRCODE_UNDEFINED_COLUMN),
1607  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1608  attname, NameListToString(relname))));
1609 
1610  address.classId = AttrDefaultRelationId;
1611  address.objectId = InvalidOid;
1612  address.objectSubId = InvalidAttrNumber;
1613  relation_close(relation, lockmode);
1614  return address;
1615  }
1616 
1617  address.classId = AttrDefaultRelationId;
1618  address.objectId = defoid;
1619  address.objectSubId = 0;
1620 
1621  *relp = relation;
1622  return address;
1623 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:593
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define RelationGetDescr(relation)
Definition: rel.h:483
#define AttrDefaultIndexId
Definition: pg_attrdef.h:52
#define llast(l)
Definition: pg_list.h:194
#define Int16GetDatum(X)
Definition: postgres.h:451
List * list_truncate(List *list, int new_size)
Definition: list.c:600
#define AccessShareLock
Definition: lockdefs.h:36
List * list_copy(const List *oldlist)
Definition: list.c:1418
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:704
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:698
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:381
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:500
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:45
NameData attname
Definition: pg_attribute.h:40
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
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:3101
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:155
#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:149
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:915
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:457
#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 1492 of file objectaddress.c.

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

Referenced by get_object_address().

1495 {
1496  ObjectAddress address;
1497  List *relname;
1498  Oid reloid;
1499  Relation relation;
1500  const char *attname;
1502 
1503  /* Extract relation name and open relation. */
1504  if (list_length(object) < 2)
1505  ereport(ERROR,
1506  (errcode(ERRCODE_SYNTAX_ERROR),
1507  errmsg("column name must be qualified")));
1508  attname = strVal(llast(object));
1509  relname = list_truncate(list_copy(object), list_length(object) - 1);
1510  /* XXX no missing_ok support here */
1511  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1512  reloid = RelationGetRelid(relation);
1513 
1514  /* Look up attribute and construct return value. */
1515  attnum = get_attnum(reloid, attname);
1516  if (attnum == InvalidAttrNumber)
1517  {
1518  if (!missing_ok)
1519  ereport(ERROR,
1520  (errcode(ERRCODE_UNDEFINED_COLUMN),
1521  errmsg("column \"%s\" of relation \"%s\" does not exist",
1522  attname, NameListToString(relname))));
1523 
1524  address.classId = RelationRelationId;
1525  address.objectId = InvalidOid;
1526  address.objectSubId = InvalidAttrNumber;
1527  relation_close(relation, lockmode);
1528  return address;
1529  }
1530 
1531  address.classId = RelationRelationId;
1532  address.objectId = reloid;
1533  address.objectSubId = attnum;
1534 
1535  *relp = relation;
1536  return address;
1537 }
#define llast(l)
Definition: pg_list.h:194
List * list_truncate(List *list, int new_size)
Definition: list.c:600
List * list_copy(const List *oldlist)
Definition: list.c:1418
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:704
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:45
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:3101
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:155
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
static int list_length(const List *l)
Definition: pg_list.h:149
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:915
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:457

◆ get_object_address_defacl()

static ObjectAddress get_object_address_defacl ( List object,
bool  missing_ok 
)
static

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

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

◆ get_object_address_opcf()

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

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

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

◆ get_object_address_opf_member()

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

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

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

◆ get_object_address_publication_rel()

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

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

1891 {
1892  ObjectAddress address;
1893  Relation relation;
1894  List *relname;
1895  char *pubname;
1896  Publication *pub;
1897 
1898  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1899 
1900  relname = linitial(object);
1902  AccessShareLock, missing_ok);
1903  if (!relation)
1904  return address;
1905 
1906  /* fetch publication name from input list */
1907  pubname = strVal(lsecond(object));
1908 
1909  /* Now look up the pg_publication tuple */
1910  pub = GetPublicationByName(pubname, missing_ok);
1911  if (!pub)
1912  {
1913  relation_close(relation, AccessShareLock);
1914  return address;
1915  }
1916 
1917  /* Find the publication relation mapping in syscache. */
1918  address.objectId =
1919  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1921  ObjectIdGetDatum(pub->oid));
1922  if (!OidIsValid(address.objectId))
1923  {
1924  if (!missing_ok)
1925  ereport(ERROR,
1926  (errcode(ERRCODE_UNDEFINED_OBJECT),
1927  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1928  RelationGetRelationName(relation), pubname)));
1929  relation_close(relation, AccessShareLock);
1930  return address;
1931  }
1932 
1933  *relp = relation;
1934  return address;
1935 }
#define AccessShareLock
Definition: lockdefs.h:36
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:704
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
NameData relname
Definition: pg_class.h:38
#define OidIsValid(objectId)
Definition: c.h:698
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
#define lsecond(l)
Definition: pg_list.h:179
#define linitial(l)
Definition: pg_list.h:174
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:45
#define RelationGetRelationName(relation)
Definition: rel.h:491
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:155
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:195
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:915
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:457
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 1413 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().

1415 {
1416  ObjectAddress address;
1417  Relation relation = NULL;
1418  int nnames;
1419  const char *depname;
1420  List *relname;
1421  Oid reloid;
1422 
1423  /* Extract name of dependent object. */
1424  depname = strVal(llast(object));
1425 
1426  /* Separate relation name from dependent object name. */
1427  nnames = list_length(object);
1428  if (nnames < 2)
1429  ereport(ERROR,
1430  (errcode(ERRCODE_SYNTAX_ERROR),
1431  errmsg("must specify relation and object name")));
1432 
1433  /* Extract relation name and open relation. */
1434  relname = list_truncate(list_copy(object), nnames - 1);
1435  relation = table_openrv_extended(makeRangeVarFromNameList(relname),
1437  missing_ok);
1438 
1439  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1440 
1441  switch (objtype)
1442  {
1443  case OBJECT_RULE:
1444  address.classId = RewriteRelationId;
1445  address.objectId = relation ?
1446  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1447  address.objectSubId = 0;
1448  break;
1449  case OBJECT_TRIGGER:
1450  address.classId = TriggerRelationId;
1451  address.objectId = relation ?
1452  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1453  address.objectSubId = 0;
1454  break;
1455  case OBJECT_TABCONSTRAINT:
1456  address.classId = ConstraintRelationId;
1457  address.objectId = relation ?
1458  get_relation_constraint_oid(reloid, depname, missing_ok) :
1459  InvalidOid;
1460  address.objectSubId = 0;
1461  break;
1462  case OBJECT_POLICY:
1463  address.classId = PolicyRelationId;
1464  address.objectId = relation ?
1465  get_relation_policy_oid(reloid, depname, missing_ok) :
1466  InvalidOid;
1467  address.objectSubId = 0;
1468  break;
1469  default:
1470  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1471  }
1472 
1473  /* Avoid relcache leak when object not found. */
1474  if (!OidIsValid(address.objectId))
1475  {
1476  if (relation != NULL)
1477  table_close(relation, AccessShareLock);
1478 
1479  relation = NULL; /* department of accident prevention */
1480  return address;
1481  }
1482 
1483  /* Done. */
1484  *relp = relation;
1485  return address;
1486 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: table.c:132
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
#define llast(l)
Definition: pg_list.h:194
List * list_truncate(List *list, int new_size)
Definition: list.c:600
#define AccessShareLock
Definition: lockdefs.h:36
List * list_copy(const List *oldlist)
Definition: list.c:1418
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:704
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:698
#define ERROR
Definition: elog.h:45
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:155
Oid get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
Definition: policy.c:1307
static int list_length(const List *l)
Definition: pg_list.h:149
Oid get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
Definition: trigger.c:1312
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
int errmsg(const char *fmt,...)
Definition: elog.c:915
#define elog(elevel,...)
Definition: elog.h:228
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:457

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

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

Referenced by ExecAlterObjectDependsStmt().

1226 {
1227  if (rel)
1228  {
1229  object = lcons(makeString(rel->relname), object);
1230  if (rel->schemaname)
1231  object = lcons(makeString(rel->schemaname), object);
1232  if (rel->catalogname)
1233  object = lcons(makeString(rel->catalogname), object);
1234  }
1235 
1236  return get_object_address(objtype, (Node *) object,
1237  relp, lockmode, missing_ok);
1238 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:528
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
List * lcons(void *datum, List *list)
Definition: list.c:468
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 1629 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().

1630 {
1631  ObjectAddress address;
1632  Type tup;
1633 
1634  address.classId = TypeRelationId;
1635  address.objectId = InvalidOid;
1636  address.objectSubId = 0;
1637 
1638  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1639  if (!HeapTupleIsValid(tup))
1640  {
1641  if (!missing_ok)
1642  ereport(ERROR,
1643  (errcode(ERRCODE_UNDEFINED_OBJECT),
1644  errmsg("type \"%s\" does not exist",
1645  TypeNameToString(typename))));
1646  return address;
1647  }
1648  address.objectId = typeTypeId(tup);
1649 
1650  if (objtype == OBJECT_DOMAIN)
1651  {
1652  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1653  ereport(ERROR,
1654  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1655  errmsg("\"%s\" is not a domain",
1656  TypeNameToString(typename))));
1657  }
1658 
1659  ReleaseSysCache(tup);
1660 
1661  return address;
1662 }
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:704
#define ERROR
Definition: elog.h:45
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:155
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261
int errmsg(const char *fmt,...)
Definition: elog.c:915
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 1245 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().

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

◆ get_object_address_usermapping()

static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

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

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

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2711 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2712 {
2713  const ObjectPropertyType *prop = get_object_property_data(class_id);
2714 
2715  return prop->attnum_acl;
2716 }
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 2687 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().

2688 {
2689  const ObjectPropertyType *prop = get_object_property_data(class_id);
2690 
2691  return prop->attnum_name;
2692 }
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 2695 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().

2696 {
2697  const ObjectPropertyType *prop = get_object_property_data(class_id);
2698 
2699  return prop->attnum_namespace;
2700 }
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 2679 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().

2680 {
2681  const ObjectPropertyType *prop = get_object_property_data(class_id);
2682 
2683  return prop->attnum_oid;
2684 }
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 2703 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2704 {
2705  const ObjectPropertyType *prop = get_object_property_data(class_id);
2706 
2707  return prop->attnum_owner;
2708 }
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 2671 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2672 {
2673  const ObjectPropertyType *prop = get_object_property_data(class_id);
2674 
2675  return prop->name_catcache_id;
2676 }
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 2663 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().

2664 {
2665  const ObjectPropertyType *prop = get_object_property_data(class_id);
2666 
2667  return prop->oid_catcache_id;
2668 }
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 2647 of file objectaddress.c.

References ObjectPropertyType::class_descr, and get_object_property_data().

Referenced by DropObjectById().

2648 {
2649  const ObjectPropertyType *prop = get_object_property_data(class_id);
2650 
2651  return prop->class_descr;
2652 }
const char * class_descr
Definition: objectaddress.c:99
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 2744 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2745 {
2746  const ObjectPropertyType *prop = get_object_property_data(class_id);
2747 
2748  return prop->is_nsp_name_unique;
2749 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

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

2589 {
2590  int cache;
2591  HeapTuple tuple;
2592  bool isnull;
2593  Oid oid;
2594  const ObjectPropertyType *property;
2595 
2596  /* If not owned by a namespace, just return InvalidOid. */
2597  property = get_object_property_data(address->classId);
2598  if (property->attnum_namespace == InvalidAttrNumber)
2599  return InvalidOid;
2600 
2601  /* Currently, we can only handle object types with system caches. */
2602  cache = property->oid_catcache_id;
2603  Assert(cache != -1);
2604 
2605  /* Fetch tuple from syscache and extract namespace attribute. */
2606  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2607  if (!HeapTupleIsValid(tuple))
2608  elog(ERROR, "cache lookup failed for cache %d oid %u",
2609  cache, address->objectId);
2610  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2611  tuple,
2612  property->attnum_namespace,
2613  &isnull));
2614  Assert(!isnull);
2615  ReleaseSysCache(tuple);
2616 
2617  return oid;
2618 }
#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:45
static const ObjectPropertyType * get_object_property_data(Oid class_id)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:792
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog(elevel,...)
Definition: elog.h:228

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2655 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by DropObjectById(), and get_catalog_object_by_oid().

2656 {
2657  const ObjectPropertyType *prop = get_object_property_data(class_id);
2658 
2659  return prop->oid_index_oid;
2660 }
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 2773 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().

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

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

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

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

1334 {
1335  Relation relation;
1336  ObjectAddress address;
1337 
1338  address.classId = RelationRelationId;
1339  address.objectId = InvalidOid;
1340  address.objectSubId = 0;
1341 
1343  lockmode, missing_ok);
1344  if (!relation)
1345  return address;
1346 
1347  switch (objtype)
1348  {
1349  case OBJECT_INDEX:
1350  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1351  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1352  ereport(ERROR,
1353  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1354  errmsg("\"%s\" is not an index",
1355  RelationGetRelationName(relation))));
1356  break;
1357  case OBJECT_SEQUENCE:
1358  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1359  ereport(ERROR,
1360  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1361  errmsg("\"%s\" is not a sequence",
1362  RelationGetRelationName(relation))));
1363  break;
1364  case OBJECT_TABLE:
1365  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1366  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1367  ereport(ERROR,
1368  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1369  errmsg("\"%s\" is not a table",
1370  RelationGetRelationName(relation))));
1371  break;
1372  case OBJECT_VIEW:
1373  if (relation->rd_rel->relkind != RELKIND_VIEW)
1374  ereport(ERROR,
1375  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1376  errmsg("\"%s\" is not a view",
1377  RelationGetRelationName(relation))));
1378  break;
1379  case OBJECT_MATVIEW:
1380  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1381  ereport(ERROR,
1382  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1383  errmsg("\"%s\" is not a materialized view",
1384  RelationGetRelationName(relation))));
1385  break;
1386  case OBJECT_FOREIGN_TABLE:
1387  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1388  ereport(ERROR,
1389  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1390  errmsg("\"%s\" is not a foreign table",
1391  RelationGetRelationName(relation))));
1392  break;
1393  default:
1394  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1395  break;
1396  }
1397 
1398  /* Done. */
1399  address.objectId = RelationGetRelid(relation);
1400  *relp = relation;
1401 
1402  return address;
1403 }
int errcode(int sqlerrcode)
Definition: elog.c:704
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
Form_pg_class rd_rel
Definition: rel.h:110
#define ERROR
Definition: elog.h:45
#define RelationGetRelationName(relation)
Definition: rel.h:491
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:915
#define elog(elevel,...)
Definition: elog.h:228
#define RelationGetRelid(relation)
Definition: rel.h:457
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 5930 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_internal(), 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(), sanity_check_relation(), transformTableLikeClause(), and truncate_check_perms().

5931 {
5932  switch (relkind)
5933  {
5934  case RELKIND_RELATION:
5935  case RELKIND_PARTITIONED_TABLE:
5936  return OBJECT_TABLE;
5937  case RELKIND_INDEX:
5938  case RELKIND_PARTITIONED_INDEX:
5939  return OBJECT_INDEX;
5940  case RELKIND_SEQUENCE:
5941  return OBJECT_SEQUENCE;
5942  case RELKIND_VIEW:
5943  return OBJECT_VIEW;
5944  case RELKIND_MATVIEW:
5945  return OBJECT_MATVIEW;
5946  case RELKIND_FOREIGN_TABLE:
5947  return OBJECT_FOREIGN_TABLE;
5948  case RELKIND_TOASTVALUE:
5949  return OBJECT_TABLE;
5950  default:
5951  /* Per above, don't raise an error */
5952  return OBJECT_TABLE;
5953  }
5954 }

◆ getConstraintTypeDescription()

static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid,
bool  missing_ok 
)
static

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

4562 {
4563  Relation constrRel;
4564  HeapTuple constrTup;
4565  Form_pg_constraint constrForm;
4566 
4567  constrRel = table_open(ConstraintRelationId, AccessShareLock);
4568  constrTup = get_catalog_object_by_oid(constrRel, Anum_pg_constraint_oid,
4569  constroid);
4570  if (!HeapTupleIsValid(constrTup))
4571  {
4572  if (!missing_ok)
4573  elog(ERROR, "cache lookup failed for constraint %u", constroid);
4574 
4575  table_close(constrRel, AccessShareLock);
4576 
4577  /* fallback to "constraint" for an undefined object */
4578  appendStringInfoString(buffer, "constraint");
4579  return;
4580  }
4581 
4582  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4583 
4584  if (OidIsValid(constrForm->conrelid))
4585  appendStringInfoString(buffer, "table constraint");
4586  else if (OidIsValid(constrForm->contypid))
4587  appendStringInfoString(buffer, "domain constraint");
4588  else
4589  elog(ERROR, "invalid constraint %u", constrForm->oid);
4590 
4591  table_close(constrRel, AccessShareLock);
4592 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define AccessShareLock
Definition: lockdefs.h:36
#define OidIsValid(objectId)
Definition: c.h:698
#define ERROR
Definition: elog.h:45
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
FormData_pg_constraint * Form_pg_constraint
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:228
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 2856 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), Assert, attname, AttrDefaultOidIndexId, BTEqualStrategyNumber, CastOidIndexId, CLAOID, ObjectAddress::classId, CollationIsVisible(), COLLOID, CONSTROID, ConversionIsVisible(), CONVOID, StringInfoData::data, datname, DefaultAclOidIndexId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), format_type_be(), format_type_extended(), FORMAT_TYPE_INVALID_AS_NULL, get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectClass(), getObjectDescription(), getOpFamilyDescription(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LargeObjectExists(), StringInfoData::len, 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, proname, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), RewriteOidIndexId, ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, StatisticsObjIsVisible(), subname, systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TRFOID, TriggerOidIndexId, TSConfigIsVisible(), TSCONFIGOID, TSDictionaryIsVisible(), TSDICTOID, TSParserIsVisible(), TSPARSEROID, TSTemplateIsVisible(), TSTEMPLATEOID, typname, USERMAPPINGOID, and username.

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().

2857 {
2858  StringInfoData buffer;
2859 
2860  initStringInfo(&buffer);
2861 
2862  switch (getObjectClass(object))
2863  {
2864  case OCLASS_CLASS:
2865  if (object->objectSubId == 0)
2866  getRelationDescription(&buffer, object->objectId, missing_ok);
2867  else
2868  {
2869  /* column, not whole relation */
2870  StringInfoData rel;
2871  char *attname = get_attname(object->objectId,
2872  object->objectSubId,
2873  missing_ok);
2874  if (!attname)
2875  break;
2876 
2877  initStringInfo(&rel);
2878  getRelationDescription(&rel, object->objectId, missing_ok);
2879  /* translator: second %s is, e.g., "table %s" */
2880  appendStringInfo(&buffer, _("column %s of %s"),
2881  attname, rel.data);
2882  pfree(rel.data);
2883  }
2884  break;
2885 
2886  case OCLASS_PROC:
2887  {
2889  char *proname = format_procedure_extended(object->objectId,
2890  flags);
2891  if (proname == NULL)
2892  break;
2893 
2894  appendStringInfo(&buffer, _("function %s"), proname);
2895  break;
2896  }
2897 
2898  case OCLASS_TYPE:
2899  {
2901  char *typname = format_type_extended(object->objectId, -1,
2902  flags);
2903  if (typname == NULL)
2904  break;
2905 
2906  appendStringInfo(&buffer, _("type %s"), typname);
2907  break;
2908  }
2909 
2910  case OCLASS_CAST:
2911  {
2912  Relation castDesc;
2913  ScanKeyData skey[1];
2914  SysScanDesc rcscan;
2915  HeapTuple tup;
2916  Form_pg_cast castForm;
2917 
2918  castDesc = table_open(CastRelationId, AccessShareLock);
2919 
2920  ScanKeyInit(&skey[0],
2921  Anum_pg_cast_oid,
2922  BTEqualStrategyNumber, F_OIDEQ,
2923  ObjectIdGetDatum(object->objectId));
2924 
2925  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2926  NULL, 1, skey);
2927 
2928  tup = systable_getnext(rcscan);
2929 
2930  if (!HeapTupleIsValid(tup))
2931  {
2932  if (!missing_ok)
2933  elog(ERROR, "could not find tuple for cast %u",
2934  object->objectId);
2935 
2936  systable_endscan(rcscan);
2937  table_close(castDesc, AccessShareLock);
2938  break;
2939  }
2940 
2941  castForm = (Form_pg_cast) GETSTRUCT(tup);
2942 
2943  appendStringInfo(&buffer, _("cast from %s to %s"),
2944  format_type_be(castForm->castsource),
2945  format_type_be(castForm->casttarget));
2946 
2947  systable_endscan(rcscan);
2948  table_close(castDesc, AccessShareLock);
2949  break;
2950  }
2951 
2952  case OCLASS_COLLATION:
2953  {
2954  HeapTuple collTup;
2955  Form_pg_collation coll;
2956  char *nspname;
2957 
2958  collTup = SearchSysCache1(COLLOID,
2959  ObjectIdGetDatum(object->objectId));
2960  if (!HeapTupleIsValid(collTup))
2961  {
2962  if (!missing_ok)
2963  elog(ERROR, "cache lookup failed for collation %u",
2964  object->objectId);
2965  break;
2966  }
2967 
2968  coll = (Form_pg_collation) GETSTRUCT(collTup);
2969 
2970  /* Qualify the name if not visible in search path */
2971  if (CollationIsVisible(object->objectId))
2972  nspname = NULL;
2973  else
2974  nspname = get_namespace_name(coll->collnamespace);
2975 
2976  appendStringInfo(&buffer, _("collation %s"),
2978  NameStr(coll->collname)));
2979  ReleaseSysCache(collTup);
2980  break;
2981  }
2982 
2983  case OCLASS_CONSTRAINT:
2984  {
2985  HeapTuple conTup;
2986  Form_pg_constraint con;
2987 
2988  conTup = SearchSysCache1(CONSTROID,
2989  ObjectIdGetDatum(object->objectId));
2990  if (!HeapTupleIsValid(conTup))
2991  {
2992  if (!missing_ok)
2993  elog(ERROR, "cache lookup failed for constraint %u",
2994  object->objectId);
2995  break;
2996  }
2997 
2998  con = (Form_pg_constraint) GETSTRUCT(conTup);
2999 
3000  if (OidIsValid(con->conrelid))
3001  {
3002  StringInfoData rel;
3003 
3004  initStringInfo(&rel);
3005  getRelationDescription(&rel, con->conrelid, false);
3006  /* translator: second %s is, e.g., "table %s" */
3007  appendStringInfo(&buffer, _("constraint %s on %s"),
3008  NameStr(con->conname), rel.data);
3009  pfree(rel.data);
3010  }
3011  else
3012  {
3013  appendStringInfo(&buffer, _("constraint %s"),
3014  NameStr(con->conname));
3015  }
3016 
3017  ReleaseSysCache(conTup);
3018  break;
3019  }
3020 
3021  case OCLASS_CONVERSION:
3022  {
3023  HeapTuple conTup;
3024  Form_pg_conversion conv;
3025  char *nspname;
3026 
3027  conTup = SearchSysCache1(CONVOID,
3028  ObjectIdGetDatum(object->objectId));
3029  if (!HeapTupleIsValid(conTup))
3030  {
3031  if (!missing_ok)
3032  elog(ERROR, "cache lookup failed for conversion %u",
3033  object->objectId);
3034  break;
3035  }
3036 
3037  conv = (Form_pg_conversion) GETSTRUCT(conTup);
3038 
3039  /* Qualify the name if not visible in search path */
3040  if (ConversionIsVisible(object->objectId))
3041  nspname = NULL;
3042  else
3043  nspname = get_namespace_name(conv->connamespace);
3044 
3045  appendStringInfo(&buffer, _("conversion %s"),
3047  NameStr(conv->conname)));
3048  ReleaseSysCache(conTup);
3049  break;
3050  }
3051 
3052  case OCLASS_DEFAULT:
3053  {
3054  Relation attrdefDesc;
3055  ScanKeyData skey[1];
3056  SysScanDesc adscan;
3057  HeapTuple tup;
3058  Form_pg_attrdef attrdef;
3059  ObjectAddress colobject;
3060 
3061  attrdefDesc = table_open(AttrDefaultRelationId, AccessShareLock);
3062 
3063  ScanKeyInit(&skey[0],
3064  Anum_pg_attrdef_oid,
3065  BTEqualStrategyNumber, F_OIDEQ,
3066  ObjectIdGetDatum(object->objectId));
3067 
3068  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
3069  true, NULL, 1, skey);
3070 
3071  tup = systable_getnext(adscan);
3072 
3073  if (!HeapTupleIsValid(tup))
3074  {
3075  if (!missing_ok)
3076  elog(ERROR, "could not find tuple for attrdef %u",
3077  object->objectId);
3078 
3079  systable_endscan(adscan);
3080  table_close(attrdefDesc, AccessShareLock);
3081  break;
3082  }
3083 
3084  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
3085 
3086  colobject.classId = RelationRelationId;
3087  colobject.objectId = attrdef->adrelid;
3088  colobject.objectSubId = attrdef->adnum;
3089 
3090  /* translator: %s is typically "column %s of table %s" */
3091  appendStringInfo(&buffer, _("default value for %s"),
3092  getObjectDescription(&colobject, false));
3093 
3094  systable_endscan(adscan);
3095  table_close(attrdefDesc, AccessShareLock);
3096  break;
3097  }
3098 
3099  case OCLASS_LANGUAGE:
3100  {
3101  char *langname = get_language_name(object->objectId,
3102  missing_ok);
3103 
3104  if (langname)
3105  appendStringInfo(&buffer, _("language %s"),
3106  get_language_name(object->objectId, false));
3107  break;
3108  }
3109 
3110  case OCLASS_LARGEOBJECT:
3111  if (!LargeObjectExists(object->objectId))
3112  break;
3113  appendStringInfo(&buffer, _("large object %u"),
3114  object->objectId);
3115  break;
3116 
3117  case OCLASS_OPERATOR:
3118  {
3120  char *oprname = format_operator_extended(object->objectId,
3121  flags);
3122 
3123  if (oprname == NULL)
3124  break;
3125 
3126  appendStringInfo(&buffer, _("operator %s"), oprname);
3127  break;
3128  }
3129 
3130  case OCLASS_OPCLASS:
3131  {
3132  HeapTuple opcTup;
3133  Form_pg_opclass opcForm;
3134  HeapTuple amTup;
3135  Form_pg_am amForm;
3136  char *nspname;
3137 
3138  opcTup = SearchSysCache1(CLAOID,
3139  ObjectIdGetDatum(object->objectId));
3140  if (!HeapTupleIsValid(opcTup))
3141  {
3142  if (!missing_ok)
3143  elog(ERROR, "cache lookup failed for opclass %u",
3144  object->objectId);
3145  break;
3146  }
3147 
3148  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
3149 
3150  amTup = SearchSysCache1(AMOID,
3151  ObjectIdGetDatum(opcForm->opcmethod));
3152  if (!HeapTupleIsValid(amTup))
3153  elog(ERROR, "cache lookup failed for access method %u",
3154  opcForm->opcmethod);
3155  amForm = (Form_pg_am) GETSTRUCT(amTup);
3156 
3157  /* Qualify the name if not visible in search path */
3158  if (OpclassIsVisible(object->objectId))
3159  nspname = NULL;
3160  else
3161  nspname = get_namespace_name(opcForm->opcnamespace);
3162 
3163  appendStringInfo(&buffer, _("operator class %s for access method %s"),
3165  NameStr(opcForm->opcname)),
3166  NameStr(amForm->amname));
3167 
3168  ReleaseSysCache(amTup);
3169  ReleaseSysCache(opcTup);
3170  break;
3171  }
3172 
3173  case OCLASS_OPFAMILY:
3174  getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3175  break;
3176 
3177  case OCLASS_AM:
3178  {
3179  HeapTuple tup;
3180 
3181  tup = SearchSysCache1(AMOID,
3182  ObjectIdGetDatum(object->objectId));
3183  if (!HeapTupleIsValid(tup))
3184  {
3185  if (!missing_ok)
3186  elog(ERROR, "cache lookup failed for access method %u",
3187  object->objectId);
3188  break;
3189  }
3190 
3191  appendStringInfo(&buffer, _("access method %s"),
3192  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3193  ReleaseSysCache(tup);
3194  break;
3195  }
3196 
3197  case OCLASS_AMOP:
3198  {
3199  Relation amopDesc;
3200  HeapTuple tup;
3201  ScanKeyData skey[1];
3202  SysScanDesc amscan;
3203  Form_pg_amop amopForm;
3204  StringInfoData opfam;
3205 
3206  amopDesc = table_open(AccessMethodOperatorRelationId,
3207  AccessShareLock);
3208 
3209  ScanKeyInit(&skey[0],
3210  Anum_pg_amop_oid,
3211  BTEqualStrategyNumber, F_OIDEQ,
3212  ObjectIdGetDatum(object->objectId));
3213 
3214  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
3215  NULL, 1, skey);
3216 
3217  tup = systable_getnext(amscan);
3218 
3219  if (!HeapTupleIsValid(tup))
3220  {
3221  if (!missing_ok)
3222  elog(ERROR, "could not find tuple for amop entry %u",
3223  object->objectId);
3224 
3225  systable_endscan(amscan);
3226  table_close(amopDesc, AccessShareLock);
3227  break;
3228  }
3229 
3230  amopForm = (Form_pg_amop) GETSTRUCT(tup);
3231 
3232  initStringInfo(&opfam);
3233  getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3234 
3235  /*------
3236  translator: %d is the operator strategy (a number), the
3237  first two %s's are data type names, the third %s is the
3238  description of the operator family, and the last %s is the
3239  textual form of the operator with arguments. */
3240  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3241  amopForm->amopstrategy,
3242  format_type_be(amopForm->amoplefttype),
3243  format_type_be(amopForm->amoprighttype),
3244  opfam.data,
3245  format_operator(amopForm->amopopr));
3246 
3247  pfree(opfam.data);
3248 
3249  systable_endscan(amscan);
3250  table_close(amopDesc, AccessShareLock);
3251  break;
3252  }
3253 
3254  case OCLASS_AMPROC:
3255  {
3256  Relation amprocDesc;
3257  ScanKeyData skey[1];
3258  SysScanDesc amscan;
3259  HeapTuple tup;
3260  Form_pg_amproc amprocForm;
3261  StringInfoData opfam;
3262 
3263  amprocDesc = table_open(AccessMethodProcedureRelationId,
3264  AccessShareLock);
3265 
3266  ScanKeyInit(&skey[0],
3267  Anum_pg_amproc_oid,
3268  BTEqualStrategyNumber, F_OIDEQ,
3269  ObjectIdGetDatum(object->objectId));
3270 
3271  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
3272  NULL, 1, skey);
3273 
3274  tup = systable_getnext(amscan);
3275 
3276  if (!HeapTupleIsValid(tup))
3277  {
3278  if (!missing_ok)
3279  elog(ERROR, "could not find tuple for amproc entry %u",
3280  object->objectId);
3281 
3282  systable_endscan(amscan);
3283  table_close(amprocDesc, AccessShareLock);
3284  break;
3285  }
3286 
3287  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
3288 
3289  initStringInfo(&opfam);
3290  getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3291 
3292  /*------
3293  translator: %d is the function number, the first two %s's
3294  are data type names, the third %s is the description of the
3295  operator family, and the last %s is the textual form of the
3296  function with arguments. */
3297  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3298  amprocForm->amprocnum,
3299  format_type_be(amprocForm->amproclefttype),
3300  format_type_be(amprocForm->amprocrighttype),
3301  opfam.data,
3302  format_procedure(amprocForm->amproc));
3303 
3304  pfree(opfam.data);
3305 
3306  systable_endscan(amscan);
3307  table_close(amprocDesc, AccessShareLock);
3308  break;
3309  }
3310 
3311  case OCLASS_REWRITE:
3312  {
3313  Relation ruleDesc;
3314  ScanKeyData skey[1];
3315  SysScanDesc rcscan;
3316  HeapTuple tup;
3318  StringInfoData rel;
3319 
3320  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
3321 
3322  ScanKeyInit(&skey[0],
3323  Anum_pg_rewrite_oid,
3324  BTEqualStrategyNumber, F_OIDEQ,
3325  ObjectIdGetDatum(object->objectId));
3326 
3327  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3328  NULL, 1, skey);
3329 
3330  tup = systable_getnext(rcscan);
3331 
3332  if (!HeapTupleIsValid(tup))
3333  {
3334  if (!missing_ok)
3335  elog(ERROR, "could not find tuple for rule %u",
3336  object->objectId);
3337 
3338  systable_endscan(rcscan);
3339  table_close(ruleDesc, AccessShareLock);
3340  break;
3341  }
3342 
3343  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3344 
3345  initStringInfo(&rel);
3346  getRelationDescription(&rel, rule->ev_class, false);
3347 
3348  /* translator: second %s is, e.g., "table %s" */
3349  appendStringInfo(&buffer, _("rule %s on %s"),
3350  NameStr(rule->rulename), rel.data);
3351  pfree(rel.data);
3352  systable_endscan(rcscan);
3353  table_close(ruleDesc, AccessShareLock);
3354  break;
3355  }
3356 
3357  case OCLASS_TRIGGER:
3358  {
3359  Relation trigDesc;
3360  ScanKeyData skey[1];
3361  SysScanDesc tgscan;
3362  HeapTuple tup;
3363  Form_pg_trigger trig;
3364  StringInfoData rel;
3365 
3366  trigDesc = table_open(TriggerRelationId, AccessShareLock);
3367 
3368  ScanKeyInit(&skey[0],
3369  Anum_pg_trigger_oid,
3370  BTEqualStrategyNumber, F_OIDEQ,
3371  ObjectIdGetDatum(object->objectId));
3372 
3373  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3374  NULL, 1, skey);
3375 
3376  tup = systable_getnext(tgscan);
3377 
3378  if (!HeapTupleIsValid(tup))
3379  {
3380  if (!missing_ok)
3381  elog(ERROR, "could not find tuple for trigger %u",
3382  object->objectId);
3383 
3384  systable_endscan(tgscan);
3385  table_close(trigDesc, AccessShareLock);
3386  break;
3387  }
3388 
3389  trig = (Form_pg_trigger) GETSTRUCT(tup);
3390 
3391  initStringInfo(&rel);
3392  getRelationDescription(&rel, trig->tgrelid, false);
3393 
3394  /* translator: second %s is, e.g., "table %s" */
3395  appendStringInfo(&buffer, _("trigger %s on %s"),
3396  NameStr(trig->tgname), rel.data);
3397  pfree(rel.data);
3398  systable_endscan(tgscan);
3399  table_close(trigDesc, AccessShareLock);
3400  break;
3401  }
3402 
3403  case OCLASS_SCHEMA:
3404  {
3405  char *nspname;
3406 
3407  nspname = get_namespace_name(object->objectId);
3408  if (!nspname)
3409  {
3410  if (!missing_ok)
3411  elog(ERROR, "cache lookup failed for namespace %u",
3412  object->objectId);
3413  break;
3414  }
3415  appendStringInfo(&buffer, _("schema %s"), nspname);
3416  break;
3417  }
3418 
3419  case OCLASS_STATISTIC_EXT:
3420  {
3421  HeapTuple stxTup;
3422  Form_pg_statistic_ext stxForm;
3423  char *nspname;
3424 
3425  stxTup = SearchSysCache1(STATEXTOID,
3426  ObjectIdGetDatum(object->objectId));
3427  if (!HeapTupleIsValid(stxTup))
3428  {
3429  if (!missing_ok)
3430  elog(ERROR, "could not find tuple for statistics object %u",
3431  object->objectId);
3432  break;
3433  }
3434 
3435  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3436 
3437  /* Qualify the name if not visible in search path */
3438  if (StatisticsObjIsVisible(object->objectId))
3439  nspname = NULL;
3440  else
3441  nspname = get_namespace_name(stxForm->stxnamespace);
3442 
3443  appendStringInfo(&buffer, _("statistics object %s"),
3445  NameStr(stxForm->stxname)));
3446 
3447  ReleaseSysCache(stxTup);
3448  break;
3449  }
3450 
3451  case OCLASS_TSPARSER:
3452  {
3453  HeapTuple tup;
3454  Form_pg_ts_parser prsForm;
3455  char *nspname;
3456 
3458  ObjectIdGetDatum(object->objectId));
3459  if (!HeapTupleIsValid(tup))
3460  {
3461  if (!missing_ok)
3462  elog(ERROR, "cache lookup failed for text search parser %u",
3463  object->objectId);
3464  break;
3465  }
3466  prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3467 
3468  /* Qualify the name if not visible in search path */
3469  if (TSParserIsVisible(object->objectId))
3470  nspname = NULL;
3471  else
3472  nspname = get_namespace_name(prsForm->prsnamespace);
3473 
3474  appendStringInfo(&buffer, _("text search parser %s"),
3476  NameStr(prsForm->prsname)));
3477  ReleaseSysCache(tup);
3478  break;
3479  }
3480 
3481  case OCLASS_TSDICT:
3482  {
3483  HeapTuple tup;
3484  Form_pg_ts_dict dictForm;
3485  char *nspname;
3486 
3487  tup = SearchSysCache1(TSDICTOID,
3488  ObjectIdGetDatum(object->objectId));
3489  if (!HeapTupleIsValid(tup))
3490  {
3491  if (!missing_ok)
3492  elog(ERROR, "cache lookup failed for text search dictionary %u",
3493  object->objectId);
3494  break;
3495  }
3496 
3497  dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3498 
3499  /* Qualify the name if not visible in search path */
3500  if (TSDictionaryIsVisible(object->objectId))
3501  nspname = NULL;
3502  else
3503  nspname = get_namespace_name(dictForm->dictnamespace);
3504 
3505  appendStringInfo(&buffer, _("text search dictionary %s"),
3507  NameStr(dictForm->dictname)));
3508  ReleaseSysCache(tup);
3509  break;
3510  }
3511 
3512  case OCLASS_TSTEMPLATE:
3513  {
3514  HeapTuple tup;
3515  Form_pg_ts_template tmplForm;
3516  char *nspname;
3517 
3519  ObjectIdGetDatum(object->objectId));
3520  if (!HeapTupleIsValid(tup))
3521  {
3522  if (!missing_ok)
3523  elog(ERROR, "cache lookup failed for text search template %u",
3524  object->objectId);
3525  break;
3526  }
3527 
3528  tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3529 
3530  /* Qualify the name if not visible in search path */
3531  if (TSTemplateIsVisible(object->objectId))
3532  nspname = NULL;
3533  else
3534  nspname = get_namespace_name(tmplForm->tmplnamespace);
3535 
3536  appendStringInfo(&buffer, _("text search template %s"),
3538  NameStr(tmplForm->tmplname)));
3539  ReleaseSysCache(tup);
3540  break;
3541  }
3542 
3543  case OCLASS_TSCONFIG:
3544  {
3545  HeapTuple tup;
3546  Form_pg_ts_config cfgForm;
3547  char *nspname;
3548 
3550  ObjectIdGetDatum(object->objectId));
3551  if (!HeapTupleIsValid(tup))
3552  {
3553  if (!missing_ok)
3554  elog(ERROR, "cache lookup failed for text search configuration %u",
3555  object->objectId);
3556  break;
3557  }
3558 
3559  cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3560 
3561  /* Qualify the name if not visible in search path */
3562  if (TSConfigIsVisible(object->objectId))
3563  nspname = NULL;
3564  else
3565  nspname = get_namespace_name(cfgForm->cfgnamespace);
3566 
3567  appendStringInfo(&buffer, _("text search configuration %s"),
3569  NameStr(cfgForm->cfgname)));
3570  ReleaseSysCache(tup);
3571  break;
3572  }
3573 
3574  case OCLASS_ROLE:
3575  {
3576  char *username = GetUserNameFromId(object->objectId,
3577  missing_ok);
3578 
3579  if (username)
3580  appendStringInfo(&buffer, _("role %s"), username);
3581  break;
3582  }
3583 
3584  case OCLASS_DATABASE:
3585  {
3586  char *datname;
3587 
3588  datname = get_database_name(object->objectId);
3589  if (!datname)
3590  {
3591  if (!missing_ok)
3592  elog(ERROR, "cache lookup failed for database %u",
3593  object->objectId);
3594  break;
3595  }
3596  appendStringInfo(&buffer, _("database %s"), datname);
3597  break;
3598  }
3599 
3600  case OCLASS_TBLSPACE:
3601  {
3602  char *tblspace;
3603 
3604  tblspace = get_tablespace_name(object->objectId);
3605  if (!tblspace)
3606  {
3607  if (!missing_ok)
3608  elog(ERROR, "cache lookup failed for tablespace %u",
3609  object->objectId);
3610  break;
3611  }
3612  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3613  break;
3614  }
3615 
3616  case OCLASS_FDW:
3617  {
3618  ForeignDataWrapper *fdw;
3619 
3621  missing_ok);
3622  if (fdw)
3623  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3624  break;
3625  }
3626 
3627  case OCLASS_FOREIGN_SERVER:
3628  {
3629  ForeignServer *srv;
3630 
3631  srv = GetForeignServerExtended(object->objectId, missing_ok);
3632  if (srv)
3633  appendStringInfo(&buffer, _("server %s"), srv->servername);
3634  break;
3635  }
3636 
3637  case OCLASS_USER_MAPPING:
3638  {
3639  HeapTuple tup;
3640  Oid useid;
3641  char *usename;
3642  Form_pg_user_mapping umform;
3643  ForeignServer *srv;
3644 
3646  ObjectIdGetDatum(object->objectId));
3647  if (!HeapTupleIsValid(tup))
3648  {
3649  if (!missing_ok)
3650  elog(ERROR, "cache lookup failed for user mapping %u",
3651  object->objectId);
3652  break;
3653  }
3654 
3655  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3656  useid = umform->umuser;
3657  srv = GetForeignServer(umform->umserver);
3658 
3659  ReleaseSysCache(tup);
3660 
3661  if (OidIsValid(useid))
3662  usename = GetUserNameFromId(useid, false);
3663  else
3664  usename = "public";
3665 
3666  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3667  srv->servername);
3668  break;
3669  }
3670 
3671  case OCLASS_DEFACL:
3672  {
3673  Relation defaclrel;
3674  ScanKeyData skey[1];
3675  SysScanDesc rcscan;
3676  HeapTuple tup;
3677  Form_pg_default_acl defacl;
3678  char *rolename;
3679  char *nspname;
3680 
3681  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
3682 
3683  ScanKeyInit(&skey[0],
3684  Anum_pg_default_acl_oid,
3685  BTEqualStrategyNumber, F_OIDEQ,
3686  ObjectIdGetDatum(object->objectId));
3687 
3688  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3689  true, NULL, 1, skey);
3690 
3691  tup = systable_getnext(rcscan);
3692 
3693  if (!HeapTupleIsValid(tup))
3694  {
3695  if (!missing_ok)
3696  elog(ERROR, "could not find tuple for default ACL %u",
3697  object->objectId);
3698 
3699  systable_endscan(rcscan);
3700  table_close(defaclrel, AccessShareLock);
3701  break;
3702  }
3703 
3704  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3705 
3706  rolename = GetUserNameFromId(defacl->defaclrole, false);
3707 
3708  if (OidIsValid(defacl->defaclnamespace))
3709  nspname = get_namespace_name(defacl->defaclnamespace);
3710  else
3711  nspname = NULL;
3712 
3713  switch (defacl->defaclobjtype)
3714  {
3715  case DEFACLOBJ_RELATION:
3716  if (nspname)
3717  appendStringInfo(&buffer,
3718  _("default privileges on new relations belonging to role %s in schema %s"),
3719  rolename, nspname);
3720  else
3721  appendStringInfo(&buffer,
3722  _("default privileges on new relations belonging to role %s"),
3723  rolename);
3724  break;
3725  case DEFACLOBJ_SEQUENCE:
3726  if (nspname)
3727  appendStringInfo(&buffer,
3728  _("default privileges on new sequences belonging to role %s in schema %s"),
3729  rolename, nspname);
3730  else
3731  appendStringInfo(&buffer,
3732  _("default privileges on new sequences belonging to role %s"),
3733  rolename);
3734  break;
3735  case DEFACLOBJ_FUNCTION:
3736  if (nspname)
3737  appendStringInfo(&buffer,
3738  _("default privileges on new functions belonging to role %s in schema %s"),
3739  rolename, nspname);
3740  else
3741  appendStringInfo(&buffer,
3742  _("default privileges on new functions belonging to role %s"),
3743  rolename);
3744  break;
3745  case DEFACLOBJ_TYPE:
3746  if (nspname)
3747  appendStringInfo(&buffer,
3748  _("default privileges on new types belonging to role %s in schema %s"),
3749  rolename, nspname);
3750  else
3751  appendStringInfo(&buffer,
3752  _("default privileges on new types belonging to role %s"),
3753  rolename);
3754  break;
3755  case DEFACLOBJ_NAMESPACE:
3756  Assert(!nspname);
3757  appendStringInfo(&buffer,
3758  _("default privileges on new schemas belonging to role %s"),
3759  rolename);
3760  break;
3761  default:
3762  /* shouldn't get here */
3763  if (nspname)
3764  appendStringInfo(&buffer,
3765  _("default privileges belonging to role %s in schema %s"),
3766  rolename, nspname);
3767  else
3768  appendStringInfo(&buffer,
3769  _("default privileges belonging to role %s"),
3770  rolename);
3771  break;
3772  }
3773 
3774  systable_endscan(rcscan);
3775  table_close(defaclrel, AccessShareLock);
3776  break;
3777  }
3778 
3779  case OCLASS_EXTENSION:
3780  {
3781  char *extname;
3782 
3783  extname = get_extension_name(object->objectId);
3784  if (!extname)
3785  {
3786  if (!missing_ok)
3787  elog(ERROR, "cache lookup failed for extension %u",
3788  object->objectId);
3789  break;
3790  }
3791  appendStringInfo(&buffer, _("extension %s"), extname);
3792  break;
3793  }
3794 
3795  case OCLASS_EVENT_TRIGGER:
3796  {
3797  HeapTuple tup;
3798 
3800  ObjectIdGetDatum(object->objectId));
3801  if (!HeapTupleIsValid(tup))
3802  {
3803  if (!missing_ok)
3804  elog(ERROR, "cache lookup failed for event trigger %u",
3805  object->objectId);
3806  break;
3807  }
3808  appendStringInfo(&buffer, _("event trigger %s"),
3809  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3810  ReleaseSysCache(tup);
3811  break;
3812  }
3813 
3814  case OCLASS_POLICY:
3815  {
3816  Relation policy_rel;
3817  ScanKeyData skey[1];
3818  SysScanDesc sscan;
3819  HeapTuple tuple;
3820  Form_pg_policy form_policy;
3821  StringInfoData rel;
3822 
3823  policy_rel = table_open(PolicyRelationId, AccessShareLock);
3824 
3825  ScanKeyInit(&skey[0],
3826  Anum_pg_policy_oid,
3827  BTEqualStrategyNumber, F_OIDEQ,
3828  ObjectIdGetDatum(object->objectId));
3829 
3830  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3831  true, NULL, 1, skey);
3832 
3833  tuple = systable_getnext(sscan);
3834 
3835  if (!HeapTupleIsValid(tuple))
3836  {
3837  if (!missing_ok)
3838  elog(ERROR, "could not find tuple for policy %u",
3839  object->objectId);
3840 
3841  systable_endscan(sscan);
3842  table_close(policy_rel, AccessShareLock);
3843  break;
3844  }
3845 
3846  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3847 
3848  initStringInfo(&rel);
3849  getRelationDescription(&rel, form_policy->polrelid, false);
3850 
3851  /* translator: second %s is, e.g., "table %s" */
3852  appendStringInfo(&buffer, _("policy %s on %s"),
3853  NameStr(form_policy->polname), rel.data);
3854  pfree(rel.data);
3855  systable_endscan(sscan);
3856  table_close(policy_rel, AccessShareLock);
3857  break;
3858  }
3859 
3860  case OCLASS_PUBLICATION:
3861  {
3862  char *pubname = get_publication_name(object->objectId,
3863  missing_ok);
3864  if (pubname)
3865  appendStringInfo(&buffer, _("publication %s"), pubname);
3866  break;
3867  }
3868 
3870  {
3871  HeapTuple tup;
3872  char *pubname;
3873  Form_pg_publication_rel prform;
3874  StringInfoData rel;
3875 
3877  ObjectIdGetDatum(object->objectId));
3878  if (!HeapTupleIsValid(tup))
3879  {
3880  if (!missing_ok)
3881  elog(ERROR, "cache lookup failed for publication table %u",
3882  object->objectId);
3883  break;
3884  }
3885 
3886  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3887  pubname = get_publication_name(prform->prpubid, false);
3888 
3889  initStringInfo(&rel);
3890  getRelationDescription(&rel, prform->prrelid, false);
3891 
3892  /* translator: first %s is, e.g., "table %s" */
3893  appendStringInfo(&buffer, _("publication of %s in publication %s"),
3894  rel.data, pubname);
3895  pfree(rel.data);
3896  ReleaseSysCache(tup);
3897  break;
3898  }
3899 
3900  case OCLASS_SUBSCRIPTION:
3901  {
3902  char *subname = get_subscription_name(object->objectId,
3903  missing_ok);
3904  if (subname)
3905  appendStringInfo(&buffer, _("subscription %s"), subname);
3906  break;
3907  }
3908 
3909  case OCLASS_TRANSFORM:
3910  {
3911  HeapTuple trfTup;
3912  Form_pg_transform trfForm;
3913 
3914  trfTup = SearchSysCache1(TRFOID,
3915  ObjectIdGetDatum(object->objectId));
3916  if (!HeapTupleIsValid(trfTup))
3917  {
3918  if (!missing_ok)
3919  elog(ERROR, "could not find tuple for transform %u",
3920  object->objectId);
3921  break;
3922  }
3923 
3924  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
3925 
3926  appendStringInfo(&buffer, _("transform for %s language %s"),
3927  format_type_be(trfForm->trftype),
3928  get_language_name(trfForm->trflang, false));
3929 
3930  ReleaseSysCache(trfTup);
3931  break;
3932  }
3933 
3934  /*
3935  * There's intentionally no default: case here; we want the
3936  * compiler to warn if a new OCLASS hasn't been handled above.
3937  */
3938  }
3939 
3940  /* an empty buffer is equivalent to no object found */
3941  if (buffer.len == 0)
3942  return NULL;
3943 
3944  return buffer.data;
3945 }
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
#define AccessMethodProcedureOidIndexId
Definition: pg_amproc.h:73
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
NameData proname
Definition: pg_proc.h:35
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:593
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define PolicyOidIndexId
Definition: pg_policy.h:55
Definition: syscache.h:36
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1127
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
uint16 bits16
Definition: c.h:437
char * fdwname
Definition: foreign.h:28
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
char * get_extension_name(Oid ext_oid)
Definition: extension.c:185
static void getOpFamilyDescription(StringInfo buffer, Oid opfid, bool missing_ok)
static void getRelationDescription(StringInfo buffer, Oid relid, bool missing_ok)
#define AccessShareLock
Definition: lockdefs.h:36
bool StatisticsObjIsVisible(Oid relid)
Definition: namespace.c:2234
#define CastOidIndexId
Definition: pg_cast.h:60
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:851
unsigned int Oid
Definition: postgres_ext.h:31
NameData subname
#define RewriteOidIndexId
Definition: pg_rewrite.h:57
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2866
#define OidIsValid(objectId)
Definition: c.h:698
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:381
char * get_publication_name(Oid pubid, bool missing_ok)
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:780
Definition: localtime.c:72
char * get_subscription_name(Oid subid, bool missing_ok)
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:500
void pfree(void *pointer)
Definition: mcxt.c:1057
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:45
NameData attname
Definition: pg_attribute.h:40
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2736
#define DefaultAclOidIndexId
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:3289
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2047
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
NameData typname
Definition: pg_type.h:41
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:2483
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:11019
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
#define FORMAT_TYPE_INVALID_AS_NULL
Definition: builtins.h:111
#define TriggerOidIndexId
Definition: pg_trigger.h:82
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:109
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
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
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:349
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1832
static char * username
Definition: initdb.c:134
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:50
#define AccessMethodOperatorOidIndexId
Definition: pg_amop.h:95
ForeignServer * GetForeignServerExtended(Oid serverid, bits16 flags)
Definition: foreign.c:121
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:322
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2130
#define AttrDefaultOidIndexId
Definition: pg_attrdef.h:54
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:891
#define Assert(condition)
Definition: c.h:792
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:73
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
Definition: format_type.c:112
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:47
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:2610
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
bool LargeObjectExists(Oid loid)
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2357
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition: foreign.c:47
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1479
char * servername
Definition: foreign.h:39
FormData_pg_ts_template * Form_pg_ts_template
#define elog(elevel,...)
Definition: elog.h:228
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:669
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:89
#define BTEqualStrategyNumber
Definition: stratnum.h:31
FormData_pg_statistic_ext * Form_pg_statistic_ext

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3951 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3952 {
3953  ObjectAddress address;
3954 
3955  address.classId = classid;
3956  address.objectId = objid;
3957  address.objectSubId = 0;
3958 
3959  return getObjectDescription(&address, false);
3960 }
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

Definition at line 4650 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_extended(), FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_operator_parts(), FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_procedure_extended(), format_procedure_parts(), format_type_be_qualified(), format_type_extended(), FORMAT_TYPE_FORCE_QUALIFY, FORMAT_TYPE_INVALID_AS_NULL, 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(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectClass(), getObjectIdentityParts(), getOpFamilyIdentity(), getRelationIdentity(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LANGOID, lappend(), LargeObjectExists(), StringInfoData::len, 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, proname, 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().

4653 {
4654  StringInfoData buffer;
4655 
4656  initStringInfo(&buffer);
4657 
4658  /*
4659  * Make sure that both objname and objargs were passed, or none was; and
4660  * initialize them to empty lists. For objname this is useless because it
4661  * will be initialized in all cases inside the switch; but we do it anyway
4662  * so that we can test below that no branch leaves it unset.
4663  */
4664  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4665  if (objname)
4666  {
4667  *objname = NIL;
4668  *objargs = NIL;
4669  }
4670 
4671  switch (getObjectClass(object))
4672  {
4673  case OCLASS_CLASS:
4674  {
4675  char *attr = NULL;
4676 
4677  /*
4678  * Check for the attribute first, so as if it is missing we
4679  * can skip the entire relation description.
4680  */
4681  if (object->objectSubId != 0)
4682  {
4683  attr = get_attname(object->objectId,
4684  object->objectSubId,
4685  missing_ok);
4686 
4687  if (missing_ok && attr == NULL)
4688  break;
4689  }
4690 
4691  getRelationIdentity(&buffer, object->objectId, objname,
4692  missing_ok);
4693  if (objname && *objname == NIL)
4694  break;
4695 
4696  if (attr)
4697  {
4698  appendStringInfo(&buffer, ".%s",
4699  quote_identifier(attr));
4700  if (objname)
4701  *objname = lappend(*objname, attr);
4702  }
4703  }
4704  break;
4705 
4706  case OCLASS_PROC:
4707  {
4709  char *proname = format_procedure_extended(object->objectId,
4710  flags);
4711  if (proname == NULL)
4712  break;
4713 
4714  appendStringInfoString(&buffer, proname);
4715  if (objname)
4716  format_procedure_parts(object->objectId, objname, objargs,
4717  missing_ok);
4718  break;
4719  }
4720 
4721  case OCLASS_TYPE:
4722  {
4724  char *typeout;
4725 
4726  typeout = format_type_extended(object->objectId, -1, flags);
4727 
4728  if (typeout == NULL)
4729  break;
4730 
4731  appendStringInfoString(&buffer, typeout);
4732  if (objname)
4733  *objname = list_make1(typeout);
4734  }
4735  break;
4736 
4737  case OCLASS_CAST:
4738  {
4739  Relation castRel;
4740  HeapTuple tup;
4741  Form_pg_cast castForm;
4742 
4743  castRel = table_open(CastRelationId, AccessShareLock);
4744 
4745  tup = get_catalog_object_by_oid(castRel, Anum_pg_cast_oid,
4746  object->objectId);
4747 
4748  if (!HeapTupleIsValid(tup))
4749  {
4750  if (!missing_ok)
4751  elog(ERROR, "could not find tuple for cast %u",
4752  object->objectId);
4753 
4754  table_close(castRel, AccessShareLock);
4755  break;
4756  }
4757 
4758  castForm = (Form_pg_cast) GETSTRUCT(tup);
4759 
4760  appendStringInfo(&buffer, "(%s AS %s)",
4761  format_type_be_qualified(castForm->castsource),
4762  format_type_be_qualified(castForm->casttarget));
4763 
4764  if (objname)
4765  {
4766  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4767  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4768  }
4769 
4770  table_close(castRel, AccessShareLock);
4771  break;
4772  }
4773 
4774  case OCLASS_COLLATION:
4775  {
4776  HeapTuple collTup;
4777  Form_pg_collation coll;
4778  char *schema;
4779 
4780  collTup = SearchSysCache1(COLLOID,
4781  ObjectIdGetDatum(object->objectId));
4782  if (!HeapTupleIsValid(collTup))
4783  {
4784  if (!missing_ok)
4785  elog(ERROR, "cache lookup failed for collation %u",
4786  object->objectId);
4787  break;
4788  }
4789  coll = (Form_pg_collation) GETSTRUCT(collTup);
4790  schema = get_namespace_name_or_temp(coll->collnamespace);
4791  appendStringInfoString(&buffer,
4793  NameStr(coll->collname)));
4794  if (objname)
4795  *objname = list_make2(schema,
4796  pstrdup(NameStr(coll->collname)));
4797  ReleaseSysCache(collTup);
4798  break;
4799  }
4800 
4801  case OCLASS_CONSTRAINT:
4802  {
4803  HeapTuple conTup;
4804  Form_pg_constraint con;
4805 
4806  conTup = SearchSysCache1(CONSTROID,
4807  ObjectIdGetDatum(object->objectId));
4808  if (!HeapTupleIsValid(conTup))
4809  {
4810  if (!missing_ok)
4811  elog(ERROR, "cache lookup failed for constraint %u",
4812  object->objectId);
4813  break;
4814  }
4815  con = (Form_pg_constraint) GETSTRUCT(conTup);
4816 
4817  if (OidIsValid(con->conrelid))
4818  {
4819  appendStringInfo(&buffer, "%s on ",
4820  quote_identifier(NameStr(con->conname)));
4821  getRelationIdentity(&buffer, con->conrelid, objname,
4822  false);
4823  if (objname)
4824  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4825  }
4826  else
4827  {
4828  ObjectAddress domain;
4829 
4830  Assert(OidIsValid(con->contypid));
4831  domain.classId = TypeRelationId;
4832  domain.objectId = con->contypid;
4833  domain.objectSubId = 0;
4834 
4835  appendStringInfo(&buffer, "%s on %s",
4836  quote_identifier(NameStr(con->conname)),
4837  getObjectIdentityParts(&domain, objname,
4838  objargs, false));
4839 
4840  if (objname)
4841  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4842  }
4843 
4844  ReleaseSysCache(conTup);
4845  break;
4846  }
4847 
4848  case OCLASS_CONVERSION:
4849  {
4850  HeapTuple conTup;
4851  Form_pg_conversion conForm;
4852  char *schema;
4853 
4854  conTup = SearchSysCache1(CONVOID,
4855  ObjectIdGetDatum(object->objectId));
4856  if (!HeapTupleIsValid(conTup))
4857  {
4858  if (!missing_ok)
4859  elog(ERROR, "cache lookup failed for conversion %u",
4860  object->objectId);
4861  break;
4862  }
4863  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4864  schema = get_namespace_name_or_temp(conForm->connamespace);
4865  appendStringInfoString(&buffer,
4867  NameStr(conForm->conname)));
4868  if (objname)
4869  *objname = list_make2(schema,
4870  pstrdup(NameStr(conForm->conname)));
4871  ReleaseSysCache(conTup);
4872  break;
4873  }
4874 
4875  case OCLASS_DEFAULT:
4876  {
4877  Relation attrdefDesc;
4878  ScanKeyData skey[1];
4879  SysScanDesc adscan;
4880 
4881  HeapTuple tup;
4882  Form_pg_attrdef attrdef;
4883  ObjectAddress colobject;
4884 
4885  attrdefDesc = table_open(AttrDefaultRelationId, AccessShareLock);
4886 
4887  ScanKeyInit(&skey[0],
4888  Anum_pg_attrdef_oid,
4889  BTEqualStrategyNumber, F_OIDEQ,
4890  ObjectIdGetDatum(object->objectId));
4891 
4892  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
4893  true, NULL, 1, skey);
4894 
4895  tup = systable_getnext(adscan);
4896 
4897  if (!HeapTupleIsValid(tup))
4898  {
4899  if (!missing_ok)
4900  elog(ERROR, "could not find tuple for attrdef %u",
4901  object->objectId);
4902 
4903  systable_endscan(adscan);
4904  table_close(attrdefDesc, AccessShareLock);
4905  break;
4906  }
4907 
4908  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
4909 
4910  colobject.classId = RelationRelationId;
4911  colobject.objectId = attrdef->adrelid;
4912  colobject.objectSubId = attrdef->adnum;
4913 
4914  appendStringInfo(&buffer, "for %s",
4915  getObjectIdentityParts(&colobject,
4916  objname, objargs,
4917  false));
4918 
4919  systable_endscan(adscan);
4920  table_close(attrdefDesc, AccessShareLock);
4921  break;
4922  }
4923 
4924  case OCLASS_LANGUAGE:
4925  {
4926  HeapTuple langTup;
4927  Form_pg_language langForm;
4928 
4929  langTup = SearchSysCache1(LANGOID,
4930  ObjectIdGetDatum(object->objectId));
4931  if (!HeapTupleIsValid(langTup))
4932  {
4933  if (!missing_ok)
4934  elog(ERROR, "cache lookup failed for language %u",
4935  object->objectId);
4936  break;
4937  }
4938  langForm = (Form_pg_language) GETSTRUCT(langTup);
4939  appendStringInfoString(&buffer,
4940  quote_identifier(NameStr(langForm->lanname)));
4941  if (objname)
4942  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
4943  ReleaseSysCache(langTup);
4944  break;
4945  }
4946  case OCLASS_LARGEOBJECT:
4947  if (!LargeObjectExists(object->objectId))
4948  break;
4949  appendStringInfo(&buffer, "%u",
4950  object->objectId);
4951  if (objname)
4952  *objname = list_make1(psprintf("%u", object->objectId));
4953  break;
4954 
4955  case OCLASS_OPERATOR:
4956  {
4958  char *oprname = format_operator_extended(object->objectId,
4959  flags);
4960  if (oprname == NULL)
4961  break;
4962 
4963  appendStringInfoString(&buffer, oprname);
4964  if (objname)
4965  format_operator_parts(object->objectId, objname, objargs, missing_ok);
4966  break;
4967  }
4968 
4969  case OCLASS_OPCLASS:
4970  {
4971  HeapTuple opcTup;
4972  Form_pg_opclass opcForm;
4973  HeapTuple amTup;
4974  Form_pg_am amForm;
4975  char *schema;
4976 
4977  opcTup = SearchSysCache1(CLAOID,
4978  ObjectIdGetDatum(object->objectId));
4979  if (!HeapTupleIsValid(opcTup))
4980  {
4981  if (!missing_ok)
4982  elog(ERROR, "cache lookup failed for opclass %u",
4983  object->objectId);
4984  break;
4985  }
4986  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
4987  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
4988 
4989  amTup = SearchSysCache1(AMOID,
4990  ObjectIdGetDatum(opcForm->opcmethod));
4991  if (!HeapTupleIsValid(amTup))
4992  elog(ERROR, "cache lookup failed for access method %u",
4993  opcForm->opcmethod);
4994  amForm = (Form_pg_am) GETSTRUCT(amTup);
4995 
4996  appendStringInfo(&buffer, "%s USING %s",
4998  NameStr(opcForm->opcname)),
4999  quote_identifier(NameStr(amForm->amname)));
5000  if (objname)
5001  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5002  schema,
5003  pstrdup(NameStr(opcForm->opcname)));
5004 
5005  ReleaseSysCache(amTup);
5006  ReleaseSysCache(opcTup);
5007  break;
5008  }
5009 
5010  case OCLASS_OPFAMILY:
5011  getOpFamilyIdentity(&buffer, object->objectId, objname,
5012  missing_ok);
5013  break;
5014 
5015  case OCLASS_AM:
5016  {
5017  char *amname;
5018 
5019  amname = get_am_name(object->objectId);
5020  if (!amname)
5021  {
5022  if (!missing_ok)
5023  elog(ERROR, "cache lookup failed for access method %u",
5024  object->objectId);
5025  break;
5026  }
5027  appendStringInfoString(&buffer, quote_identifier(amname));
5028  if (objname)
5029  *objname = list_make1(amname);
5030  }
5031  break;
5032 
5033  case OCLASS_AMOP:
5034  {
5035  Relation amopDesc;
5036  HeapTuple tup;
5037  ScanKeyData skey[1];
5038  SysScanDesc amscan;
5039  Form_pg_amop amopForm;
5040  StringInfoData opfam;
5041  char *ltype;
5042  char *rtype;
5043 
5044  amopDesc = table_open(AccessMethodOperatorRelationId,
5045  AccessShareLock);
5046 
5047  ScanKeyInit(&skey[0],
5048  Anum_pg_amop_oid,
5049  BTEqualStrategyNumber, F_OIDEQ,
5050  ObjectIdGetDatum(object->objectId));
5051 
5052  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
5053  NULL, 1, skey);
5054 
5055  tup = systable_getnext(amscan);
5056 
5057  if (!HeapTupleIsValid(tup))
5058  {
5059  if (!missing_ok)
5060  elog(ERROR, "could not find tuple for amop entry %u",
5061  object->objectId);
5062 
5063  systable_endscan(amscan);
5064  table_close(amopDesc, AccessShareLock);
5065  break;
5066  }
5067 
5068  amopForm = (Form_pg_amop) GETSTRUCT(tup);
5069 
5070  initStringInfo(&opfam);
5071  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5072  false);
5073 
5074  ltype = format_type_be_qualified(amopForm->amoplefttype);
5075  rtype = format_type_be_qualified(amopForm->amoprighttype);
5076 
5077  if (objname)
5078  {
5079  *objname = lappend(*objname,
5080  psprintf("%d", amopForm->amopstrategy));
5081  *objargs = list_make2(ltype, rtype);
5082  }
5083 
5084  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5085  amopForm->amopstrategy,
5086  ltype, rtype, opfam.data);
5087 
5088  pfree(opfam.data);
5089 
5090  systable_endscan(amscan);
5091  table_close(amopDesc, AccessShareLock);
5092  break;
5093  }
5094 
5095  case OCLASS_AMPROC:
5096  {
5097  Relation amprocDesc;
5098  ScanKeyData skey[1];
5099  SysScanDesc amscan;
5100  HeapTuple tup;
5101  Form_pg_amproc amprocForm;
5102  StringInfoData opfam;
5103  char *ltype;
5104  char *rtype;
5105 
5106  amprocDesc = table_open(AccessMethodProcedureRelationId,
5107  AccessShareLock);
5108 
5109