PostgreSQL Source Code  git master
objectaddress.h File Reference
#include "access/htup.h"
#include "nodes/parsenodes.h"
#include "storage/lockdefs.h"
#include "utils/relcache.h"
Include dependency graph for objectaddress.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ObjectAddress
 

Macros

#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
 
#define ObjectAddressSet(addr, class_id, object_id)   ObjectAddressSubSet(addr, class_id, object_id, 0)
 

Typedefs

typedef struct ObjectAddress ObjectAddress
 

Functions

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)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
bool is_objectclass_supported (Oid class_id)
 
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)
 
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)
 
int read_objtype_from_string (const char *objtype)
 
char * getObjectTypeDescription (const ObjectAddress *object, bool missing_ok)
 
char * getObjectIdentity (const ObjectAddress *address, bool missing_ok)
 
char * getObjectIdentityParts (const ObjectAddress *address, List **objname, List **objargs, bool missing_ok)
 
struct ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

const ObjectAddress InvalidObjectAddress
 

Macro Definition Documentation

◆ ObjectAddressSet

#define ObjectAddressSet (   addr,
  class_id,
  object_id 
)    ObjectAddressSubSet(addr, class_id, object_id, 0)

Definition at line 40 of file objectaddress.h.

Referenced by addFkRecurseReferenced(), addFkRecurseReferencing(), AddNewAttributeTuples(), AggregateCreate(), AlterConstraintNamespaces(), AlterDatabaseOwner(), AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEnum(), AlterEventTriggerOwner(), AlterExtensionNamespace(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner(), AlterForeignServer(), AlterForeignServerOwner(), AlterFunction(), AlterPublicationOptions(), AlterPublicationOwner(), AlterSchemaOwner(), AlterSequence(), AlterStatistics(), AlterSubscription(), AlterSubscriptionOwner(), AlterTableNamespace(), AlterTSConfiguration(), AlterTSDictionary(), AlterType(), AlterTypeNamespace(), AlterTypeOwner(), AlterUserMapping(), ATAddCheckConstraint(), ATExecAddInherit(), ATExecAlterConstraint(), ATExecAttachPartition(), ATExecAttachPartitionIdx(), ATExecClusterOn(), ATExecDetachPartition(), ATExecDropInherit(), ATExecValidateConstraint(), ATPostAlterTypeCleanup(), CastCreate(), CloneFkReferencing(), ConstraintSetParentConstraint(), CreateConstraintEntry(), CreateProceduralLanguage(), CreatePublication(), CreateSchemaCommand(), CreateStatistics(), CreateSubscription(), CreateTransform(), CreateTrigger(), DefineCollation(), DefineIndex(), DefineQueryRewrite(), DefineRelation(), DefineTSConfiguration(), DefineVirtualRelation(), domainAddConstraint(), DropClonedTriggersFromPartition(), DropSubscription(), EventTriggerCollectAlterOpFam(), EventTriggerCollectAlterTSConfig(), EventTriggerCollectCreateOpClass(), ExecAlterExtensionStmt(), ExecAlterObjectSchemaStmt(), ExecRefreshMatView(), GenerateTypeDependencies(), get_object_address_defacl(), get_object_address_opf_member(), get_object_address_publication_rel(), get_object_address_usermapping(), heap_create_with_catalog(), index_constraint_create(), index_create(), IndexSetParentIndex(), InsertExtensionTuple(), makeDictionaryDependencies(), makeOperatorDependencies(), makeParserDependencies(), makeTSTemplateDependencies(), pg_event_trigger_ddl_commands(), ProcedureCreate(), publication_add_relation(), PublicationDropTables(), RangeCreate(), recordDependencyOnCollations(), rename_constraint_internal(), rename_policy(), RenameDatabase(), RenameRelation(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameType(), StorePartitionKey(), tryAttachPartitionForeignKey(), TypeCreate(), and TypeShellMake().

◆ ObjectAddressSubSet

#define ObjectAddressSubSet (   addr,
  class_id,
  object_id,
  object_sub_id 
)

Typedef Documentation

◆ ObjectAddress

typedef struct ObjectAddress ObjectAddress

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:5312
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5131
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
bool lo_compat_privileges
Definition: inv_api.c:58
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4820
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:4970
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4791
#define castNode(_type_, nodeptr)
Definition: nodes.h:596
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:4997
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5051
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5225
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4739
int errcode(int sqlerrcode)
Definition: elog.c:691
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4863
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4713
#define linitial_node(type, l)
Definition: pg_list.h:177
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3607
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3294
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5078
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5183
#define RelationGetRelationName(relation)
Definition: rel.h:491
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4889
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:4943
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5105
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1115
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:1163
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4916
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5157
#define ereport(elevel,...)
Definition: elog.h: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:4687
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5024
int errmsg(const char *fmt,...)
Definition: elog.c:902
#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:4765
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5251
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5277

◆ get_catalog_object_by_oid()

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

Definition at line 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:569
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:706
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:357
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:476
#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:800
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h: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:596
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:691
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:706
#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:43
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:800
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:902
#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_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:527
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
List * lcons(void *datum, List *list)
Definition: list.c:453
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
char * catalogname
Definition: primnodes.h:66

◆ get_object_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:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1115
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1163
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1376
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:800
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_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:1920
static const ObjectPropertyType * get_object_property_data(Oid class_id)
ObjectType get_relkind_objtype(char relkind)

◆ 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 }

◆ 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:569
#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:1100
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:2850
#define OidIsValid(objectId)
Definition: c.h:706
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:357
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:476
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:43
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:3196
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:11018
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1115
#define FORMAT_TYPE_INVALID_AS_NULL
Definition: builtins.h:115
#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:1163
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:800
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:111
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:1467
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:677
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:825
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:83
#define _(x)
Definition: elog.c:88
#define BTEqualStrategyNumber
Definition: stratnum.h:31
FormData_pg_statistic_ext * Form_pg_statistic_ext

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 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 address,
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  ScanKeyInit(&skey[0],
5110  Anum_pg_amproc_oid,
5111  BTEqualStrategyNumber, F_OIDEQ,
5112  ObjectIdGetDatum(object->objectId));
5113 
5114  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
5115  NULL, 1, skey);
5116 
5117  tup = systable_getnext(amscan);
5118 
5119  if (!HeapTupleIsValid(tup))
5120  {
5121  if (!missing_ok)
5122  elog(ERROR, "could not find tuple for amproc entry %u",
5123  object->objectId);
5124 
5125  systable_endscan(amscan);
5126  table_close(amprocDesc, AccessShareLock);
5127  break;
5128  }
5129 
5130  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
5131 
5132  initStringInfo(&opfam);
5133  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5134  false);
5135 
5136  ltype = format_type_be_qualified(amprocForm->amproclefttype);
5137  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5138 
5139  if (objname)
5140  {
5141  *objname = lappend(*objname,
5142  psprintf("%d", amprocForm->amprocnum));
5143  *objargs = list_make2(ltype, rtype);
5144  }
5145 
5146  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5147  amprocForm->amprocnum,
5148  ltype, rtype, opfam.data);
5149 
5150  pfree(opfam.data);
5151 
5152  systable_endscan(amscan);
5153  table_close(amprocDesc, AccessShareLock);
5154  break;
5155  }
5156 
5157  case OCLASS_REWRITE:
5158  {
5159  Relation ruleDesc;
5160  HeapTuple tup;
5162 
5163  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
5164 
5165  tup = get_catalog_object_by_oid(ruleDesc, Anum_pg_rewrite_oid,
5166  object->objectId);
5167 
5168  if (!HeapTupleIsValid(tup))
5169  {
5170  if (!missing_ok)
5171  elog(ERROR, "could not find tuple for rule %u",
5172  object->objectId);
5173 
5174  table_close(ruleDesc, AccessShareLock);
5175  break;
5176  }
5177 
5178  rule = (Form_pg_rewrite) GETSTRUCT(tup);
5179 
5180  appendStringInfo(&buffer, "%s on ",
5181  quote_identifier(NameStr(rule->rulename)));
5182  getRelationIdentity(&buffer, rule->ev_class, objname, false);
5183  if (objname)
5184  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5185 
5186  table_close(ruleDesc, AccessShareLock);
5187  break;
5188  }
5189 
5190  case OCLASS_TRIGGER:
5191  {
5192  Relation trigDesc;
5193  HeapTuple tup;
5194  Form_pg_trigger trig;
5195 
5196  trigDesc = table_open(TriggerRelationId, AccessShareLock);
5197 
5198  tup = get_catalog_object_by_oid(trigDesc, Anum_pg_trigger_oid,
5199  object->objectId);
5200 
5201  if (!HeapTupleIsValid(tup))
5202  {
5203  if (!missing_ok)
5204  elog(ERROR, "could not find tuple for trigger %u",
5205  object->objectId);
5206 
5207  table_close(trigDesc, AccessShareLock);
5208  break;
5209  }
5210 
5211  trig = (Form_pg_trigger) GETSTRUCT(tup);
5212 
5213  appendStringInfo(&buffer, "%s on ",
5214  quote_identifier(NameStr(trig->tgname)));
5215  getRelationIdentity(&buffer, trig->tgrelid, objname, false);
5216  if (objname)
5217  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5218 
5219  table_close(trigDesc, AccessShareLock);
5220  break;
5221  }
5222 
5223  case OCLASS_SCHEMA:
5224  {
5225  char *nspname;
5226 
5227  nspname = get_namespace_name_or_temp(object->objectId);
5228  if (!nspname)
5229  {
5230  if (!missing_ok)
5231  elog(ERROR, "cache lookup failed for namespace %u",
5232  object->objectId);
5233  break;
5234  }
5235  appendStringInfoString(&buffer,
5236  quote_identifier(nspname));
5237  if (objname)
5238  *objname = list_make1(nspname);
5239  break;
5240  }
5241 
5242  case OCLASS_STATISTIC_EXT:
5243  {
5244  HeapTuple tup;
5245  Form_pg_statistic_ext formStatistic;
5246  char *schema;
5247 
5249  ObjectIdGetDatum(object->objectId));
5250  if (!HeapTupleIsValid(tup))
5251  {
5252  if (!missing_ok)
5253  elog(ERROR, "cache lookup failed for statistics object %u",
5254  object->objectId);
5255  break;
5256  }
5257  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
5258  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5259  appendStringInfoString(&buffer,
5261  NameStr(formStatistic->stxname)));
5262  if (objname)
5263  *objname = list_make2(schema,
5264  pstrdup(NameStr(formStatistic->stxname)));
5265  ReleaseSysCache(tup);
5266  }
5267  break;
5268 
5269  case OCLASS_TSPARSER:
5270  {
5271  HeapTuple tup;
5272  Form_pg_ts_parser formParser;
5273  char *schema;
5274 
5276  ObjectIdGetDatum(object->objectId));
5277  if (!HeapTupleIsValid(tup))
5278  {
5279  if (!missing_ok)
5280  elog(ERROR, "cache lookup failed for text search parser %u",
5281  object->objectId);
5282  break;
5283  }
5284  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
5285  schema = get_namespace_name_or_temp(formParser->prsnamespace);
5286  appendStringInfoString(&buffer,
5288  NameStr(formParser->prsname)));
5289  if (objname)
5290  *objname = list_make2(schema,
5291  pstrdup(NameStr(formParser->prsname)));
5292  ReleaseSysCache(tup);
5293  break;
5294  }
5295 
5296  case OCLASS_TSDICT:
5297  {
5298  HeapTuple tup;
5299  Form_pg_ts_dict formDict;
5300  char *schema;
5301 
5302  tup = SearchSysCache1(TSDICTOID,
5303  ObjectIdGetDatum(object->objectId));
5304  if (!HeapTupleIsValid(tup))
5305  {
5306  if (!missing_ok)
5307  elog(ERROR, "cache lookup failed for text search dictionary %u",
5308  object->objectId);
5309  break;
5310  }
5311  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
5312  schema = get_namespace_name_or_temp(formDict->dictnamespace);
5313  appendStringInfoString(&buffer,
5315  NameStr(formDict->dictname)));
5316  if (objname)
5317  *objname = list_make2(schema,
5318  pstrdup(NameStr(formDict->dictname)));
5319  ReleaseSysCache(tup);
5320  break;
5321  }
5322 
5323  case OCLASS_TSTEMPLATE:
5324  {
5325  HeapTuple tup;
5326  Form_pg_ts_template formTmpl;
5327  char *schema;
5328 
5330  ObjectIdGetDatum(object->objectId));
5331  if (!HeapTupleIsValid(tup))
5332  {
5333  if (!missing_ok)
5334  elog(ERROR, "cache lookup failed for text search template %u",
5335  object->objectId);
5336  break;
5337  }
5338  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
5339  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
5340  appendStringInfoString(&buffer,
5342  NameStr(formTmpl->tmplname)));
5343  if (objname)
5344  *objname = list_make2(schema,
5345  pstrdup(NameStr(formTmpl->tmplname)));
5346  ReleaseSysCache(tup);
5347  break;
5348  }
5349 
5350  case OCLASS_TSCONFIG:
5351  {
5352  HeapTuple tup;
5353  Form_pg_ts_config formCfg;
5354  char *schema;
5355 
5357  ObjectIdGetDatum(object->objectId));
5358  if (!HeapTupleIsValid(tup))
5359  {
5360  if (!missing_ok)
5361  elog(ERROR, "cache lookup failed for text search configuration %u",
5362  object->objectId);
5363  break;
5364  }
5365  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
5366  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
5367  appendStringInfoString(&buffer,
5369  NameStr(formCfg->cfgname)));
5370  if (objname)
5371  *objname = list_make2(schema,
5372  pstrdup(NameStr(formCfg->cfgname)));
5373  ReleaseSysCache(tup);
5374  break;
5375  }
5376 
5377  case OCLASS_ROLE:
5378  {
5379  char *username;
5380 
5381  username = GetUserNameFromId(object->objectId, missing_ok);
5382  if (!username)
5383  break;
5384  if (objname)
5385  *objname = list_make1(username);
5386  appendStringInfoString(&buffer,
5387  quote_identifier(username));
5388  break;
5389  }
5390 
5391  case OCLASS_DATABASE:
5392  {
5393  char *datname;
5394 
5395  datname = get_database_name(object->objectId);
5396  if (!datname)
5397  {
5398  if (!missing_ok)
5399  elog(ERROR, "cache lookup failed for database %u",
5400  object->objectId);
5401  break;
5402  }
5403  if (objname)
5404  *objname = list_make1(datname);
5405  appendStringInfoString(&buffer,
5406  quote_identifier(datname));
5407  break;
5408  }
5409 
5410  case OCLASS_TBLSPACE:
5411  {
5412  char *tblspace;
5413 
5414  tblspace = get_tablespace_name(object->objectId);
5415  if (!tblspace)
5416  {
5417  if (!missing_ok)
5418  elog(ERROR, "cache lookup failed for tablespace %u",
5419  object->objectId);
5420  break;
5421  }
5422  if (objname)
5423  *objname = list_make1(tblspace);
5424  appendStringInfoString(&buffer,
5425  quote_identifier(tblspace));
5426  break;
5427  }
5428 
5429  case OCLASS_FDW:
5430  {
5431  ForeignDataWrapper *fdw;
5432 
5433  fdw = GetForeignDataWrapperExtended(object->objectId,
5434  missing_ok);
5435  if (fdw)
5436  {
5438  if (objname)
5439  *objname = list_make1(pstrdup(fdw->fdwname));
5440  }
5441  break;
5442  }
5443 
5444  case OCLASS_FOREIGN_SERVER:
5445  {
5446  ForeignServer *srv;
5447 
5448  srv = GetForeignServerExtended(object->objectId,
5449  missing_ok);
5450  if (srv)
5451  {
5452  appendStringInfoString(&buffer,
5454  if (objname)
5455  *objname = list_make1(pstrdup(srv->servername));
5456  }
5457  break;
5458  }
5459 
5460  case OCLASS_USER_MAPPING:
5461  {
5462  HeapTuple tup;
5463  Oid useid;
5464  Form_pg_user_mapping umform;
5465  ForeignServer *srv;
5466  const char *usename;
5467 
5469  ObjectIdGetDatum(object->objectId));
5470  if (!HeapTupleIsValid(tup))
5471  {
5472  if (!missing_ok)
5473  elog(ERROR, "cache lookup failed for user mapping %u",
5474  object->objectId);
5475  break;
5476  }
5477  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
5478  useid = umform->umuser;
5479  srv = GetForeignServer(umform->umserver);
5480 
5481  ReleaseSysCache(tup);
5482 
5483  if (OidIsValid(useid))
5484  usename = GetUserNameFromId(useid, false);
5485  else
5486  usename = "public";
5487 
5488  if (objname)
5489  {
5490  *objname = list_make1(pstrdup(usename));
5491  *objargs = list_make1(pstrdup(srv->servername));
5492  }
5493 
5494  appendStringInfo(&buffer, "%s on server %s",
5495  quote_identifier(usename),
5496  srv->servername);
5497  break;
5498  }
5499 
5500  case OCLASS_DEFACL:
5501  {
5502  Relation defaclrel;
5503  ScanKeyData skey[1];
5504  SysScanDesc rcscan;
5505  HeapTuple tup;
5506  Form_pg_default_acl defacl;
5507  char *schema;
5508  char *username;
5509 
5510  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
5511 
5512  ScanKeyInit(&skey[0],
5513  Anum_pg_default_acl_oid,
5514  BTEqualStrategyNumber, F_OIDEQ,
5515  ObjectIdGetDatum(object->objectId));
5516 
5517  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
5518  true, NULL, 1, skey);
5519 
5520  tup = systable_getnext(rcscan);
5521 
5522  if (!HeapTupleIsValid(tup))
5523  {
5524  if (!missing_ok)
5525  elog(ERROR, "could not find tuple for default ACL %u",
5526  object->objectId);
5527 
5528  systable_endscan(rcscan);
5529  table_close(defaclrel, AccessShareLock);
5530  break;
5531 
5532  }
5533 
5534  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
5535 
5536  username = GetUserNameFromId(defacl->defaclrole, false);
5537  appendStringInfo(&buffer,
5538  "for role %s",
5539  quote_identifier(username));
5540 
5541  if (OidIsValid(defacl->defaclnamespace))
5542  {
5543  schema = get_namespace_name_or_temp(defacl->defaclnamespace);
5544  appendStringInfo(&buffer,
5545  " in schema %s",
5546  quote_identifier(schema));
5547  }
5548  else
5549  schema = NULL;
5550 
5551  switch (defacl->defaclobjtype)
5552  {
5553  case DEFACLOBJ_RELATION:
5554  appendStringInfoString(&buffer,
5555  " on tables");
5556  break;
5557  case DEFACLOBJ_SEQUENCE:
5558  appendStringInfoString(&buffer,
5559  " on sequences");
5560  break;
5561  case DEFACLOBJ_FUNCTION:
5562  appendStringInfoString(&buffer,
5563  " on functions");
5564  break;
5565  case DEFACLOBJ_TYPE:
5566  appendStringInfoString(&buffer,
5567  " on types");
5568  break;
5569  case DEFACLOBJ_NAMESPACE:
5570  appendStringInfoString(&buffer,
5571  " on schemas");
5572  break;
5573  }
5574 
5575  if (objname)
5576  {
5577  *objname = list_make1(username);
5578  if (schema)
5579  *objname = lappend(*objname, schema);
5580  *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
5581  }
5582 
5583  systable_endscan(rcscan);
5584  table_close(defaclrel, AccessShareLock);
5585  break;
5586  }
5587 
5588  case OCLASS_EXTENSION:
5589  {
5590  char *extname;
5591 
5592  extname = get_extension_name(object->objectId);
5593  if (!extname)
5594  {
5595  if (!missing_ok)
5596  elog(ERROR, "cache lookup failed for extension %u",
5597  object->objectId);
5598  break;
5599  }
5600  appendStringInfoString(&buffer, quote_identifier(extname));
5601  if (objname)
5602  *objname = list_make1(extname);
5603  break;
5604  }
5605 
5606  case OCLASS_EVENT_TRIGGER:
5607  {
5608  HeapTuple tup;
5609  Form_pg_event_trigger trigForm;
5610 
5611  /* no objname support here */
5612  if (objname)
5613  *objname = NIL;
5614 
5616  ObjectIdGetDatum(object->objectId));
5617  if (!HeapTupleIsValid(tup))
5618  {
5619  if (!missing_ok)
5620  elog(ERROR, "cache lookup failed for event trigger %u",
5621  object->objectId);
5622  break;
5623  }
5624  trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
5625  appendStringInfoString(&buffer,
5626  quote_identifier(NameStr(trigForm->evtname)));
5627  ReleaseSysCache(tup);
5628  break;
5629  }
5630 
5631  case OCLASS_POLICY:
5632  {
5633  Relation polDesc;
5634  HeapTuple tup;
5635  Form_pg_policy policy;
5636 
5637  polDesc = table_open(PolicyRelationId, AccessShareLock);
5638 
5639  tup = get_catalog_object_by_oid(polDesc, Anum_pg_policy_oid,
5640  object->objectId);
5641 
5642  if (!HeapTupleIsValid(tup))
5643  {
5644  if (!missing_ok)
5645  elog(ERROR, "could not find tuple for policy %u",
5646  object->objectId);
5647 
5648  table_close(polDesc, AccessShareLock);
5649  break;
5650  }
5651 
5652  policy = (Form_pg_policy) GETSTRUCT(tup);
5653 
5654  appendStringInfo(&buffer, "%s on ",
5655  quote_identifier(NameStr(policy->polname)));
5656  getRelationIdentity(&buffer, policy->polrelid, objname, false);
5657  if (objname)
5658  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
5659 
5660  table_close(polDesc, AccessShareLock);
5661  break;
5662  }
5663 
5664  case OCLASS_PUBLICATION:
5665  {
5666  char *pubname;
5667 
5668  pubname = get_publication_name(object->objectId, missing_ok);
5669  if (pubname)
5670  {
5671  appendStringInfoString(&buffer,
5672  quote_identifier(pubname));
5673  if (objname)
5674  *objname = list_make1(pubname);
5675  }
5676  break;
5677  }
5678 
5680  {
5681  HeapTuple tup;
5682  char *pubname;
5683  Form_pg_publication_rel prform;
5684 
5686  ObjectIdGetDatum(object->objectId));
5687  if (!HeapTupleIsValid(tup))
5688  {
5689  if (!missing_ok)
5690  elog(ERROR, "cache lookup failed for publication table %u",
5691  object->objectId);
5692  break;
5693  }
5694 
5695  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
5696  pubname = get_publication_name(prform->prpubid, false);
5697 
5698  getRelationIdentity(&buffer, prform->prrelid, objname, false);
5699  appendStringInfo(&buffer, " in publication %s", pubname);
5700 
5701  if (objargs)
5702  *objargs = list_make1(pubname);
5703 
5704  ReleaseSysCache(tup);
5705  break;
5706  }
5707 
5708  case OCLASS_SUBSCRIPTION:
5709  {
5710  char *subname;
5711 
5712  subname = get_subscription_name(object->objectId, missing_ok);
5713  if (subname)
5714  {
5715  appendStringInfoString(&buffer,
5716  quote_identifier(subname));
5717  if (objname)
5718  *objname = list_make1(subname);
5719  }
5720  break;
5721  }
5722 
5723  case OCLASS_TRANSFORM:
5724  {
5725  Relation transformDesc;
5726  HeapTuple tup;
5727  Form_pg_transform transform;
5728  char *transformLang;
5729  char *transformType;
5730 
5731  transformDesc = table_open(TransformRelationId, AccessShareLock);
5732 
5733  tup = get_catalog_object_by_oid(transformDesc,
5734  Anum_pg_transform_oid,
5735  object->objectId);
5736 
5737  if (!HeapTupleIsValid(tup))
5738  {
5739  if (!missing_ok)
5740  elog(ERROR, "could not find tuple for transform %u",
5741  object->objectId);
5742 
5743  table_close(transformDesc, AccessShareLock);
5744  break;
5745  }
5746 
5747  transform = (Form_pg_transform) GETSTRUCT(tup);
5748 
5749  transformType = format_type_be_qualified(transform->trftype);
5750  transformLang = get_language_name(transform->trflang, false);
5751 
5752  appendStringInfo(&buffer, "for %s on language %s",
5753  transformType,
5754  transformLang);
5755  if (objname)
5756  {
5757  *objname = list_make1(transformType);
5758  *objargs = list_make1(pstrdup(transformLang));
5759  }
5760 
5761  table_close(transformDesc, AccessShareLock);
5762  }
5763  break;
5764 
5765  /*
5766  * There's intentionally no default: case here; we want the
5767  * compiler to warn if a new OCLASS hasn't been handled above.
5768  */
5769  }
5770 
5771  if (!missing_ok)
5772  {
5773  /*
5774  * If a get_object_address() representation was requested, make sure
5775  * we are providing one. We don't check objargs, because many of the
5776  * cases above leave it as NIL.
5777  */
5778  if (objname && *objname == NIL)
5779  elog(ERROR, "requested object address for unsupported object class %d: text result \"%s\"",
5780  (int) getObjectClass(object), buffer.data);
5781  }
5782  else
5783  {
5784  /* an empty buffer is equivalent to no object found */
5785  if (buffer.len == 0)
5786  {
5787  Assert((objname == NULL || *objname == NIL) &&
5788  (objargs == NULL || *objargs == NIL));
5789  return NULL;
5790  }
5791  }
5792 
5793  return buffer.data;
5794 }
#define list_make2(x1, x2)
Definition: pg_list.h:208
#define list_make3(x1, x2, x3)
Definition: pg_list.h:210
#define NIL
Definition: pg_list.h:65
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, 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:569
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Definition: syscache.h:36
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10934
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1100
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
uint16 bits16
Definition: c.h:437
char * fdwname
Definition: foreign.h:28
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object, bool missing_ok)
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
char * pstrdup(const char *in)
Definition: mcxt.c:1187
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * get_extension_name(Oid ext_oid)
Definition: extension.c:185
#define AccessShareLock
Definition: lockdefs.h:36
NameData datname
Definition: pg_database.h:35
unsigned int Oid
Definition: postgres_ext.h:31
NameData subname
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2850
#define OidIsValid(objectId)
Definition: c.h:706
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:357
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)
#define list_make1(x1)
Definition: pg_list.h:206
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:476
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:43
#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
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
FormData_pg_default_acl * Form_pg_default_acl
char * get_am_name(Oid amOid)
Definition: amcmds.c:192
#define FORMAT_TYPE_FORCE_QUALIFY
Definition: builtins.h:114
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
List * lappend(List *list, void *datum)
Definition: list.c:321
static void getRelationIdentity(StringInfo buffer, Oid relid, List **object, bool missing_ok)
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:11018
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1115
#define FORMAT_TYPE_INVALID_AS_NULL
Definition: builtins.h:115
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:109
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1163
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
void format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:421
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
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
#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:800
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
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:111
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:47
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
bool LargeObjectExists(Oid loid)
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:864
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition: foreign.c:47
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3220
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1467
char * servername
Definition: foreign.h:39
FormData_pg_ts_template * Form_pg_ts_template
#define elog(elevel,...)
Definition: elog.h:228
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:677
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 PointerIsValid(pointer)
Definition: c.h:694
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25
FormData_pg_statistic_ext * Form_pg_statistic_ext

◆ getObjectTypeDescription()

char* getObjectTypeDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 4317 of file objectaddress.c.

References appendStringInfoString(), StringInfoData::data, getConstraintTypeDescription(), getObjectClass(), getProcedureTypeDescription(), getRelationTypeDescription(), initStringInfo(), StringInfoData::len, ObjectAddress::objectId, 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, and OCLASS_USER_MAPPING.

Referenced by EventTriggerSQLDropAddObject(), pg_event_trigger_ddl_commands(), pg_identify_object(), pg_identify_object_as_address(), and sepgsql_object_relabel().

4318 {
4319  StringInfoData buffer;
4320 
4321  initStringInfo(&buffer);
4322 
4323  switch (getObjectClass(object))
4324  {
4325  case OCLASS_CLASS:
4326  getRelationTypeDescription(&buffer, object->objectId,
4327  object->objectSubId,
4328  missing_ok);
4329  break;
4330 
4331  case OCLASS_PROC:
4332  getProcedureTypeDescription(&buffer, object->objectId,
4333  missing_ok);
4334  break;
4335 
4336  case OCLASS_TYPE:
4337  appendStringInfoString(&buffer, "type");
4338  break;
4339 
4340  case OCLASS_CAST:
4341  appendStringInfoString(&buffer, "cast");
4342  break;
4343 
4344  case OCLASS_COLLATION:
4345  appendStringInfoString(&buffer, "collation");
4346  break;
4347 
4348  case OCLASS_CONSTRAINT:
4349  getConstraintTypeDescription(&buffer, object->objectId,
4350  missing_ok);
4351  break;
4352 
4353  case OCLASS_CONVERSION:
4354  appendStringInfoString(&buffer, "conversion");
4355  break;
4356 
4357  case OCLASS_DEFAULT:
4358  appendStringInfoString(&buffer, "default value");
4359  break;
4360 
4361  case OCLASS_LANGUAGE:
4362  appendStringInfoString(&buffer, "language");
4363  break;
4364 
4365  case OCLASS_LARGEOBJECT:
4366  appendStringInfoString(&buffer, "large object");
4367  break;
4368 
4369  case OCLASS_OPERATOR:
4370  appendStringInfoString(&buffer, "operator");
4371  break;
4372 
4373  case OCLASS_OPCLASS:
4374  appendStringInfoString(&buffer, "operator class");
4375  break;
4376 
4377  case OCLASS_OPFAMILY:
4378  appendStringInfoString(&buffer, "operator family");
4379  break;
4380 
4381  case OCLASS_AM:
4382  appendStringInfoString(&buffer, "access method");
4383  break;
4384 
4385  case OCLASS_AMOP:
4386  appendStringInfoString(&buffer, "operator of access method");
4387  break;
4388 
4389  case OCLASS_AMPROC:
4390  appendStringInfoString(&buffer, "function of access method");
4391  break;
4392 
4393  case OCLASS_REWRITE:
4394  appendStringInfoString(&buffer, "rule");
4395  break;
4396 
4397  case OCLASS_TRIGGER:
4398  appendStringInfoString(&buffer, "trigger");
4399  break;
4400 
4401  case OCLASS_SCHEMA:
4402  appendStringInfoString(&buffer, "schema");
4403  break;
4404 
4405  case OCLASS_STATISTIC_EXT:
4406  appendStringInfoString(&buffer, "statistics object");
4407  break;
4408 
4409  case OCLASS_TSPARSER:
4410  appendStringInfoString(&buffer, "text search parser");
4411  break;
4412 
4413  case OCLASS_TSDICT:
4414  appendStringInfoString(&buffer, "text search dictionary");
4415  break;
4416 
4417  case OCLASS_TSTEMPLATE:
4418  appendStringInfoString(&buffer, "text search template");
4419  break;
4420 
4421  case OCLASS_TSCONFIG:
4422  appendStringInfoString(&buffer, "text search configuration");
4423  break;
4424 
4425  case OCLASS_ROLE:
4426  appendStringInfoString(&buffer, "role");
4427  break;
4428 
4429  case OCLASS_DATABASE:
4430  appendStringInfoString(&buffer, "database");
4431  break;
4432 
4433  case OCLASS_TBLSPACE:
4434  appendStringInfoString(&buffer, "tablespace");
4435  break;
4436 
4437  case OCLASS_FDW:
4438  appendStringInfoString(&buffer, "foreign-data wrapper");
4439  break;
4440 
4441  case OCLASS_FOREIGN_SERVER:
4442  appendStringInfoString(&buffer, "server");
4443  break;
4444 
4445  case OCLASS_USER_MAPPING:
4446  appendStringInfoString(&buffer, "user mapping");
4447  break;
4448 
4449  case OCLASS_DEFACL:
4450  appendStringInfoString(&buffer, "default acl");
4451  break;
4452 
4453  case OCLASS_EXTENSION:
4454  appendStringInfoString(&buffer, "extension");
4455  break;
4456 
4457  case OCLASS_EVENT_TRIGGER:
4458  appendStringInfoString(&buffer, "event trigger");
4459  break;
4460 
4461  case OCLASS_POLICY:
4462  appendStringInfoString(&buffer, "policy");
4463  break;
4464 
4465  case OCLASS_PUBLICATION:
4466  appendStringInfoString(&buffer, "publication");
4467  break;
4468 
4470  appendStringInfoString(&buffer, "publication relation");
4471  break;
4472 
4473  case OCLASS_SUBSCRIPTION:
4474  appendStringInfoString(&buffer, "subscription");
4475  break;
4476 
4477  case OCLASS_TRANSFORM:
4478  appendStringInfoString(&buffer, "transform");
4479  break;
4480 
4481  /*
4482  * There's intentionally no default: case here; we want the
4483  * compiler to warn if a new OCLASS hasn't been handled above.
4484  */
4485  }
4486 
4487  /* an empty string is equivalent to no object found */
4488  if (buffer.len == 0)
4489  return NULL;
4490 
4491  return buffer.data;
4492 }
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2850
static void getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok)
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
static void getConstraintTypeDescription(StringInfo buffer, Oid constroid, bool missing_ok)
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
static void getProcedureTypeDescription(StringInfo buffer, Oid procid, bool missing_ok)

◆ is_objectclass_supported()

bool is_objectclass_supported ( Oid  class_id)

Definition at line 2756 of file objectaddress.c.

References lengthof.

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

2757 {
2758  int index;
2759 
2760  for (index = 0; index < lengthof(ObjectProperty); index++)
2761  {
2762  if (ObjectProperty[index].class_oid == class_id)
2763  return true;
2764  }
2765 
2766  return false;
2767 }
#define lengthof(array)
Definition: c.h:730
Definition: type.h:89
static const ObjectPropertyType ObjectProperty[]

◆ read_objtype_from_string()

int read_objtype_from_string ( const char *  objtype)

Definition at line 2627 of file objectaddress.c.

References ereport, errcode(), errmsg(), ERROR, i, lengthof, ObjectTypeMap, object_type_map::tm_name, and object_type_map::tm_type.

Referenced by pg_get_object_address().

2628 {
2629  int i;
2630 
2631  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2632  {
2633  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2634  return ObjectTypeMap[i].tm_type;
2635  }
2636  ereport(ERROR,
2637  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2638  errmsg("unrecognized object type \"%s\"", objtype)));
2639 
2640  return -1; /* keep compiler quiet */
2641 }
int errcode(int sqlerrcode)
Definition: elog.c:691
#define lengthof(array)
Definition: c.h:730
#define ERROR
Definition: elog.h:43
static const struct object_type_map ObjectTypeMap[]
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
int i

◆ strlist_to_textarray()

struct ArrayType* strlist_to_textarray ( List list)

Definition at line 5875 of file objectaddress.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, construct_md_array(), CStringGetTextDatum, CurrentMemoryContext, lfirst, list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), name, and palloc().

Referenced by fill_hba_line(), pg_event_trigger_dropped_objects(), and pg_identify_object_as_address().

5876 {
5877  ArrayType *arr;
5878  Datum *datums;
5879  bool *nulls;
5880  int j = 0;
5881  ListCell *cell;
5882  MemoryContext memcxt;
5883  MemoryContext oldcxt;
5884  int lb[1];
5885 
5886  /* Work in a temp context; easier than individually pfree'ing the Datums */
5888  "strlist to array",
5890  oldcxt = MemoryContextSwitchTo(memcxt);
5891 
5892  datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
5893  nulls = palloc(sizeof(bool) * list_length(list));
5894 
5895  foreach(cell, list)
5896  {
5897  char *name = lfirst(cell);
5898 
5899  if (name)
5900  {
5901  nulls[j] = false;
5902  datums[j++] = CStringGetTextDatum(name);
5903  }
5904  else
5905  nulls[j] = true;
5906  }
5907 
5908  MemoryContextSwitchTo(oldcxt);
5909 
5910  lb[0] = 1;
5911  arr = construct_md_array(datums, nulls, 1, &j,
5912  lb, TEXTOID, -1, false, TYPALIGN_INT);
5913 
5914  MemoryContextDelete(memcxt);
5915 
5916  return arr;
5917 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:212
#define AllocSetContextCreate
Definition: memutils.h:170
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
uintptr_t Datum
Definition: postgres.h:367
#define lfirst(lc)
Definition: pg_list.h:169
static int list_length(const List *l)
Definition: pg_list.h:149
const char * name
Definition: encode.c:561
void * palloc(Size size)
Definition: mcxt.c:950
#define CStringGetTextDatum(s)
Definition: builtins.h:86
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3348

Variable Documentation

◆ InvalidObjectAddress