From 3a17f075f9ccac2eb7a969be5e455bb29a9e40e2 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 18 Mar 2024 08:07:37 +0100 Subject: [PATCH v4] Remove ObjectClass ObjectClass is an enum whose values correspond to catalog OIDs. But the extra layer of redirection, which is used only in small parts of the code, and the similarity to ObjectType, are confusing and cumbersome. One advantage has been that some switches processing the OCLASS enum don't have "default:" cases. This is so that the compiler tells us when we fail to add support for some new object class. But you can also handle that with some assertions and proper test coverage. It's not even clear how strong this benefit is. For example, in AlterObjectNamespace_oid(), you could still put a new OCLASS into the "ignore object types that don't have schema-qualified names" case, and it might or might not be wrong. Also, there are already various OCLASS switches that do have a default case, so it's not even clear what the preferred coding style should be. Discussion: https://www.postgresql.org/message-id/flat/CAGECzQT3caUbcCcszNewCCmMbCuyP7XNAm60J3ybd6PN5kH2Dw%40mail.gmail.com --- src/backend/catalog/dependency.c | 239 ++++---------------- src/backend/catalog/objectaddress.c | 316 ++++++++++++--------------- src/backend/commands/alter.c | 73 ++----- src/backend/commands/event_trigger.c | 130 ++--------- src/backend/commands/tablecmds.c | 62 ++---- src/include/catalog/dependency.h | 51 ----- src/include/commands/event_trigger.h | 2 +- src/tools/pgindent/typedefs.list | 1 - 8 files changed, 233 insertions(+), 641 deletions(-) diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c index eadcf6af0df..6e8f6a57051 100644 --- a/src/backend/catalog/dependency.c +++ b/src/backend/catalog/dependency.c @@ -206,7 +206,7 @@ deleteObjectsInList(ObjectAddresses *targetObjects, Relation *depRel, if (extra->flags & DEPFLAG_REVERSE) normal = true; - if (EventTriggerSupportsObjectClass(getObjectClass(thisobj))) + if (EventTriggerSupportsObject(thisobj)) { EventTriggerSQLDropAddObject(thisobj, original, normal); } @@ -1349,9 +1349,9 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags) static void doDeletion(const ObjectAddress *object, int flags) { - switch (getObjectClass(object)) + switch (object->classId) { - case OCLASS_CLASS: + case RelationRelationId: { char relKind = get_rel_relkind(object->objectId); @@ -1382,104 +1382,102 @@ doDeletion(const ObjectAddress *object, int flags) break; } - case OCLASS_PROC: + case ProcedureRelationId: RemoveFunctionById(object->objectId); break; - case OCLASS_TYPE: + case TypeRelationId: RemoveTypeById(object->objectId); break; - case OCLASS_CONSTRAINT: + case ConstraintRelationId: RemoveConstraintById(object->objectId); break; - case OCLASS_DEFAULT: + case AttrDefaultRelationId: RemoveAttrDefaultById(object->objectId); break; - case OCLASS_LARGEOBJECT: + case LargeObjectRelationId: LargeObjectDrop(object->objectId); break; - case OCLASS_OPERATOR: + case OperatorRelationId: RemoveOperatorById(object->objectId); break; - case OCLASS_REWRITE: + case RewriteRelationId: RemoveRewriteRuleById(object->objectId); break; - case OCLASS_TRIGGER: + case TriggerRelationId: RemoveTriggerById(object->objectId); break; - case OCLASS_STATISTIC_EXT: + case StatisticExtRelationId: RemoveStatisticsById(object->objectId); break; - case OCLASS_TSCONFIG: + case TSConfigRelationId: RemoveTSConfigurationById(object->objectId); break; - case OCLASS_EXTENSION: + case ExtensionRelationId: RemoveExtensionById(object->objectId); break; - case OCLASS_POLICY: + case PolicyRelationId: RemovePolicyById(object->objectId); break; - case OCLASS_PUBLICATION_NAMESPACE: + case PublicationNamespaceRelationId: RemovePublicationSchemaById(object->objectId); break; - case OCLASS_PUBLICATION_REL: + case PublicationRelRelationId: RemovePublicationRelById(object->objectId); break; - case OCLASS_PUBLICATION: + case PublicationRelationId: RemovePublicationById(object->objectId); break; - case OCLASS_CAST: - case OCLASS_COLLATION: - case OCLASS_CONVERSION: - case OCLASS_LANGUAGE: - case OCLASS_OPCLASS: - case OCLASS_OPFAMILY: - case OCLASS_AM: - case OCLASS_AMOP: - case OCLASS_AMPROC: - case OCLASS_SCHEMA: - case OCLASS_TSPARSER: - case OCLASS_TSDICT: - case OCLASS_TSTEMPLATE: - case OCLASS_FDW: - case OCLASS_FOREIGN_SERVER: - case OCLASS_USER_MAPPING: - case OCLASS_DEFACL: - case OCLASS_EVENT_TRIGGER: - case OCLASS_TRANSFORM: - case OCLASS_ROLE_MEMBERSHIP: + case CastRelationId: + case CollationRelationId: + case ConversionRelationId: + case LanguageRelationId: + case OperatorClassRelationId: + case OperatorFamilyRelationId: + case AccessMethodRelationId: + case AccessMethodOperatorRelationId: + case AccessMethodProcedureRelationId: + case NamespaceRelationId: + case TSParserRelationId: + case TSDictionaryRelationId: + case TSTemplateRelationId: + case ForeignDataWrapperRelationId: + case ForeignServerRelationId: + case UserMappingRelationId: + case DefaultAclRelationId: + case EventTriggerRelationId: + case TransformRelationId: + case AuthMemRelationId: DropObjectById(object); break; /* * These global object types are not supported here. */ - case OCLASS_ROLE: - case OCLASS_DATABASE: - case OCLASS_TBLSPACE: - case OCLASS_SUBSCRIPTION: - case OCLASS_PARAMETER_ACL: + case AuthIdRelationId: + case DatabaseRelationId: + case TableSpaceRelationId: + case SubscriptionRelationId: + case ParameterAclRelationId: elog(ERROR, "global objects cannot be deleted by doDeletion"); break; - /* - * There's intentionally no default: case here; we want the - * compiler to warn if a new OCLASS hasn't been handled above. - */ + default: + elog(ERROR, "unsupported object class: %u", object->classId); } } @@ -2774,153 +2772,6 @@ free_object_addresses(ObjectAddresses *addrs) pfree(addrs); } -/* - * Determine the class of a given object identified by objectAddress. - * - * We implement it as a function instead of an array because the OIDs aren't - * consecutive. - */ -ObjectClass -getObjectClass(const ObjectAddress *object) -{ - /* only pg_class entries can have nonzero objectSubId */ - if (object->classId != RelationRelationId && - object->objectSubId != 0) - elog(ERROR, "invalid non-zero objectSubId for object class %u", - object->classId); - - switch (object->classId) - { - case RelationRelationId: - /* caller must check objectSubId */ - return OCLASS_CLASS; - - case ProcedureRelationId: - return OCLASS_PROC; - - case TypeRelationId: - return OCLASS_TYPE; - - case CastRelationId: - return OCLASS_CAST; - - case CollationRelationId: - return OCLASS_COLLATION; - - case ConstraintRelationId: - return OCLASS_CONSTRAINT; - - case ConversionRelationId: - return OCLASS_CONVERSION; - - case AttrDefaultRelationId: - return OCLASS_DEFAULT; - - case LanguageRelationId: - return OCLASS_LANGUAGE; - - case LargeObjectRelationId: - return OCLASS_LARGEOBJECT; - - case OperatorRelationId: - return OCLASS_OPERATOR; - - case OperatorClassRelationId: - return OCLASS_OPCLASS; - - case OperatorFamilyRelationId: - return OCLASS_OPFAMILY; - - case AccessMethodRelationId: - return OCLASS_AM; - - case AccessMethodOperatorRelationId: - return OCLASS_AMOP; - - case AccessMethodProcedureRelationId: - return OCLASS_AMPROC; - - case RewriteRelationId: - return OCLASS_REWRITE; - - case TriggerRelationId: - return OCLASS_TRIGGER; - - case NamespaceRelationId: - return OCLASS_SCHEMA; - - case StatisticExtRelationId: - return OCLASS_STATISTIC_EXT; - - case TSParserRelationId: - return OCLASS_TSPARSER; - - case TSDictionaryRelationId: - return OCLASS_TSDICT; - - case TSTemplateRelationId: - return OCLASS_TSTEMPLATE; - - case TSConfigRelationId: - return OCLASS_TSCONFIG; - - case AuthIdRelationId: - return OCLASS_ROLE; - - case AuthMemRelationId: - return OCLASS_ROLE_MEMBERSHIP; - - case DatabaseRelationId: - return OCLASS_DATABASE; - - case TableSpaceRelationId: - return OCLASS_TBLSPACE; - - case ForeignDataWrapperRelationId: - return OCLASS_FDW; - - case ForeignServerRelationId: - return OCLASS_FOREIGN_SERVER; - - case UserMappingRelationId: - return OCLASS_USER_MAPPING; - - case DefaultAclRelationId: - return OCLASS_DEFACL; - - case ExtensionRelationId: - return OCLASS_EXTENSION; - - case EventTriggerRelationId: - return OCLASS_EVENT_TRIGGER; - - case ParameterAclRelationId: - return OCLASS_PARAMETER_ACL; - - case PolicyRelationId: - return OCLASS_POLICY; - - case PublicationNamespaceRelationId: - return OCLASS_PUBLICATION_NAMESPACE; - - case PublicationRelationId: - return OCLASS_PUBLICATION; - - case PublicationRelRelationId: - return OCLASS_PUBLICATION_REL; - - case SubscriptionRelationId: - return OCLASS_SUBSCRIPTION; - - case TransformRelationId: - return OCLASS_TRANSFORM; - } - - /* shouldn't get here */ - elog(ERROR, "unrecognized object class: %u", object->classId); - return OCLASS_CLASS; /* keep compiler quiet */ -} - /* * delete initial ACL for extension objects */ diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index 360c6b2ba63..7b536ac6fde 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -655,7 +655,6 @@ static const struct object_type_map ObjectTypeMap[] = { - /* OCLASS_CLASS, all kinds of relations */ { "table", OBJECT_TABLE }, @@ -704,7 +703,6 @@ static const struct object_type_map { "foreign table column", OBJECT_COLUMN }, - /* OCLASS_PROC */ { "aggregate", OBJECT_AGGREGATE }, @@ -714,162 +712,123 @@ static const struct object_type_map { "procedure", OBJECT_PROCEDURE }, - /* OCLASS_TYPE */ { "type", OBJECT_TYPE }, - /* OCLASS_CAST */ { "cast", OBJECT_CAST }, - /* OCLASS_COLLATION */ { "collation", OBJECT_COLLATION }, - /* OCLASS_CONSTRAINT */ { "table constraint", OBJECT_TABCONSTRAINT }, { "domain constraint", OBJECT_DOMCONSTRAINT }, - /* OCLASS_CONVERSION */ { "conversion", OBJECT_CONVERSION }, - /* OCLASS_DEFAULT */ { "default value", OBJECT_DEFAULT }, - /* OCLASS_LANGUAGE */ { "language", OBJECT_LANGUAGE }, - /* OCLASS_LARGEOBJECT */ { "large object", OBJECT_LARGEOBJECT }, - /* OCLASS_OPERATOR */ { "operator", OBJECT_OPERATOR }, - /* OCLASS_OPCLASS */ { "operator class", OBJECT_OPCLASS }, - /* OCLASS_OPFAMILY */ { "operator family", OBJECT_OPFAMILY }, - /* OCLASS_AM */ { "access method", OBJECT_ACCESS_METHOD }, - /* OCLASS_AMOP */ { "operator of access method", OBJECT_AMOP }, - /* OCLASS_AMPROC */ { "function of access method", OBJECT_AMPROC }, - /* OCLASS_REWRITE */ { "rule", OBJECT_RULE }, - /* OCLASS_TRIGGER */ { "trigger", OBJECT_TRIGGER }, - /* OCLASS_SCHEMA */ { "schema", OBJECT_SCHEMA }, - /* OCLASS_TSPARSER */ { "text search parser", OBJECT_TSPARSER }, - /* OCLASS_TSDICT */ { "text search dictionary", OBJECT_TSDICTIONARY }, - /* OCLASS_TSTEMPLATE */ { "text search template", OBJECT_TSTEMPLATE }, - /* OCLASS_TSCONFIG */ { "text search configuration", OBJECT_TSCONFIGURATION }, - /* OCLASS_ROLE */ { "role", OBJECT_ROLE }, - /* OCLASS_ROLE_MEMBERSHIP */ { "role membership", -1 /* unmapped */ }, - /* OCLASS_DATABASE */ { "database", OBJECT_DATABASE }, - /* OCLASS_TBLSPACE */ { "tablespace", OBJECT_TABLESPACE }, - /* OCLASS_FDW */ { "foreign-data wrapper", OBJECT_FDW }, - /* OCLASS_FOREIGN_SERVER */ { "server", OBJECT_FOREIGN_SERVER }, - /* OCLASS_USER_MAPPING */ { "user mapping", OBJECT_USER_MAPPING }, - /* OCLASS_DEFACL */ { "default acl", OBJECT_DEFACL }, - /* OCLASS_EXTENSION */ { "extension", OBJECT_EXTENSION }, - /* OCLASS_EVENT_TRIGGER */ { "event trigger", OBJECT_EVENT_TRIGGER }, - /* OCLASS_PARAMETER_ACL */ { "parameter ACL", OBJECT_PARAMETER_ACL }, - /* OCLASS_POLICY */ { "policy", OBJECT_POLICY }, - /* OCLASS_PUBLICATION */ { "publication", OBJECT_PUBLICATION }, - /* OCLASS_PUBLICATION_NAMESPACE */ { "publication namespace", OBJECT_PUBLICATION_NAMESPACE }, - /* OCLASS_PUBLICATION_REL */ { "publication relation", OBJECT_PUBLICATION_REL }, - /* OCLASS_SUBSCRIPTION */ { "subscription", OBJECT_SUBSCRIPTION }, - /* OCLASS_TRANSFORM */ { "transform", OBJECT_TRANSFORM }, - /* OCLASS_STATISTIC_EXT */ { "statistics object", OBJECT_STATISTIC_EXT } @@ -2922,9 +2881,9 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) initStringInfo(&buffer); - switch (getObjectClass(object)) + switch (object->classId) { - case OCLASS_CLASS: + case RelationRelationId: if (object->objectSubId == 0) getRelationDescription(&buffer, object->objectId, missing_ok); else @@ -2947,7 +2906,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) } break; - case OCLASS_PROC: + case ProcedureRelationId: { bits16 flags = FORMAT_PROC_INVALID_AS_NULL; char *proname = format_procedure_extended(object->objectId, @@ -2960,7 +2919,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_TYPE: + case TypeRelationId: { bits16 flags = FORMAT_TYPE_INVALID_AS_NULL; char *typname = format_type_extended(object->objectId, -1, @@ -2973,7 +2932,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_CAST: + case CastRelationId: { Relation castDesc; ScanKeyData skey[1]; @@ -3015,7 +2974,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_COLLATION: + case CollationRelationId: { HeapTuple collTup; Form_pg_collation coll; @@ -3046,7 +3005,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_CONSTRAINT: + case ConstraintRelationId: { HeapTuple conTup; Form_pg_constraint con; @@ -3084,7 +3043,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_CONVERSION: + case ConversionRelationId: { HeapTuple conTup; Form_pg_conversion conv; @@ -3115,7 +3074,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_DEFAULT: + case AttrDefaultRelationId: { ObjectAddress colobject; @@ -3135,7 +3094,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_LANGUAGE: + case LanguageRelationId: { char *langname = get_language_name(object->objectId, missing_ok); @@ -3146,14 +3105,14 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_LARGEOBJECT: + case LargeObjectRelationId: if (!LargeObjectExists(object->objectId)) break; appendStringInfo(&buffer, _("large object %u"), object->objectId); break; - case OCLASS_OPERATOR: + case OperatorRelationId: { bits16 flags = FORMAT_OPERATOR_INVALID_AS_NULL; char *oprname = format_operator_extended(object->objectId, @@ -3166,7 +3125,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_OPCLASS: + case OperatorClassRelationId: { HeapTuple opcTup; Form_pg_opclass opcForm; @@ -3209,11 +3168,11 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_OPFAMILY: + case OperatorFamilyRelationId: getOpFamilyDescription(&buffer, object->objectId, missing_ok); break; - case OCLASS_AM: + case AccessMethodRelationId: { HeapTuple tup; @@ -3233,7 +3192,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_AMOP: + case AccessMethodOperatorRelationId: { Relation amopDesc; HeapTuple tup; @@ -3290,7 +3249,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_AMPROC: + case AccessMethodProcedureRelationId: { Relation amprocDesc; ScanKeyData skey[1]; @@ -3347,7 +3306,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_REWRITE: + case RewriteRelationId: { Relation ruleDesc; ScanKeyData skey[1]; @@ -3393,7 +3352,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_TRIGGER: + case TriggerRelationId: { Relation trigDesc; ScanKeyData skey[1]; @@ -3439,7 +3398,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_SCHEMA: + case NamespaceRelationId: { char *nspname; @@ -3455,7 +3414,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_STATISTIC_EXT: + case StatisticExtRelationId: { HeapTuple stxTup; Form_pg_statistic_ext stxForm; @@ -3487,7 +3446,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_TSPARSER: + case TSParserRelationId: { HeapTuple tup; Form_pg_ts_parser prsForm; @@ -3517,7 +3476,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_TSDICT: + case TSDictionaryRelationId: { HeapTuple tup; Form_pg_ts_dict dictForm; @@ -3548,7 +3507,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_TSTEMPLATE: + case TSTemplateRelationId: { HeapTuple tup; Form_pg_ts_template tmplForm; @@ -3579,7 +3538,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_TSCONFIG: + case TSConfigRelationId: { HeapTuple tup; Form_pg_ts_config cfgForm; @@ -3610,7 +3569,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_ROLE: + case AuthIdRelationId: { char *username = GetUserNameFromId(object->objectId, missing_ok); @@ -3620,7 +3579,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_ROLE_MEMBERSHIP: + case AuthMemRelationId: { Relation amDesc; ScanKeyData skey[1]; @@ -3662,7 +3621,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_DATABASE: + case DatabaseRelationId: { char *datname; @@ -3678,7 +3637,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_TBLSPACE: + case TableSpaceRelationId: { char *tblspace; @@ -3694,7 +3653,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_FDW: + case ForeignDataWrapperRelationId: { ForeignDataWrapper *fdw; @@ -3705,7 +3664,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_FOREIGN_SERVER: + case ForeignServerRelationId: { ForeignServer *srv; @@ -3715,7 +3674,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_USER_MAPPING: + case UserMappingRelationId: { HeapTuple tup; Oid useid; @@ -3749,7 +3708,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_DEFACL: + case DefaultAclRelationId: { Relation defaclrel; ScanKeyData skey[1]; @@ -3857,7 +3816,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_EXTENSION: + case ExtensionRelationId: { char *extname; @@ -3873,7 +3832,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_EVENT_TRIGGER: + case EventTriggerRelationId: { HeapTuple tup; @@ -3892,7 +3851,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_PARAMETER_ACL: + case ParameterAclRelationId: { HeapTuple tup; Datum nameDatum; @@ -3915,7 +3874,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_POLICY: + case PolicyRelationId: { Relation policy_rel; ScanKeyData skey[1]; @@ -3961,7 +3920,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_PUBLICATION: + case PublicationRelationId: { char *pubname = get_publication_name(object->objectId, missing_ok); @@ -3971,7 +3930,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_PUBLICATION_NAMESPACE: + case PublicationNamespaceRelationId: { char *pubname; char *nspname; @@ -3987,7 +3946,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_PUBLICATION_REL: + case PublicationRelRelationId: { HeapTuple tup; char *pubname; @@ -4018,7 +3977,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_SUBSCRIPTION: + case SubscriptionRelationId: { char *subname = get_subscription_name(object->objectId, missing_ok); @@ -4028,7 +3987,7 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - case OCLASS_TRANSFORM: + case TransformRelationId: { HeapTuple trfTup; Form_pg_transform trfForm; @@ -4053,10 +4012,8 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok) break; } - /* - * There's intentionally no default: case here; we want the - * compiler to warn if a new OCLASS hasn't been handled above. - */ + default: + elog(ERROR, "unsupported object class: %u", object->classId); } /* an empty buffer is equivalent to no object found */ @@ -4418,180 +4375,178 @@ getObjectTypeDescription(const ObjectAddress *object, bool missing_ok) initStringInfo(&buffer); - switch (getObjectClass(object)) + switch (object->classId) { - case OCLASS_CLASS: + case RelationRelationId: getRelationTypeDescription(&buffer, object->objectId, object->objectSubId, missing_ok); break; - case OCLASS_PROC: + case ProcedureRelationId: getProcedureTypeDescription(&buffer, object->objectId, missing_ok); break; - case OCLASS_TYPE: + case TypeRelationId: appendStringInfoString(&buffer, "type"); break; - case OCLASS_CAST: + case CastRelationId: appendStringInfoString(&buffer, "cast"); break; - case OCLASS_COLLATION: + case CollationRelationId: appendStringInfoString(&buffer, "collation"); break; - case OCLASS_CONSTRAINT: + case ConstraintRelationId: getConstraintTypeDescription(&buffer, object->objectId, missing_ok); break; - case OCLASS_CONVERSION: + case ConversionRelationId: appendStringInfoString(&buffer, "conversion"); break; - case OCLASS_DEFAULT: + case AttrDefaultRelationId: appendStringInfoString(&buffer, "default value"); break; - case OCLASS_LANGUAGE: + case LanguageRelationId: appendStringInfoString(&buffer, "language"); break; - case OCLASS_LARGEOBJECT: + case LargeObjectRelationId: appendStringInfoString(&buffer, "large object"); break; - case OCLASS_OPERATOR: + case OperatorRelationId: appendStringInfoString(&buffer, "operator"); break; - case OCLASS_OPCLASS: + case OperatorClassRelationId: appendStringInfoString(&buffer, "operator class"); break; - case OCLASS_OPFAMILY: + case OperatorFamilyRelationId: appendStringInfoString(&buffer, "operator family"); break; - case OCLASS_AM: + case AccessMethodRelationId: appendStringInfoString(&buffer, "access method"); break; - case OCLASS_AMOP: + case AccessMethodOperatorRelationId: appendStringInfoString(&buffer, "operator of access method"); break; - case OCLASS_AMPROC: + case AccessMethodProcedureRelationId: appendStringInfoString(&buffer, "function of access method"); break; - case OCLASS_REWRITE: + case RewriteRelationId: appendStringInfoString(&buffer, "rule"); break; - case OCLASS_TRIGGER: + case TriggerRelationId: appendStringInfoString(&buffer, "trigger"); break; - case OCLASS_SCHEMA: + case NamespaceRelationId: appendStringInfoString(&buffer, "schema"); break; - case OCLASS_STATISTIC_EXT: + case StatisticExtRelationId: appendStringInfoString(&buffer, "statistics object"); break; - case OCLASS_TSPARSER: + case TSParserRelationId: appendStringInfoString(&buffer, "text search parser"); break; - case OCLASS_TSDICT: + case TSDictionaryRelationId: appendStringInfoString(&buffer, "text search dictionary"); break; - case OCLASS_TSTEMPLATE: + case TSTemplateRelationId: appendStringInfoString(&buffer, "text search template"); break; - case OCLASS_TSCONFIG: + case TSConfigRelationId: appendStringInfoString(&buffer, "text search configuration"); break; - case OCLASS_ROLE: + case AuthIdRelationId: appendStringInfoString(&buffer, "role"); break; - case OCLASS_ROLE_MEMBERSHIP: + case AuthMemRelationId: appendStringInfoString(&buffer, "role membership"); break; - case OCLASS_DATABASE: + case DatabaseRelationId: appendStringInfoString(&buffer, "database"); break; - case OCLASS_TBLSPACE: + case TableSpaceRelationId: appendStringInfoString(&buffer, "tablespace"); break; - case OCLASS_FDW: + case ForeignDataWrapperRelationId: appendStringInfoString(&buffer, "foreign-data wrapper"); break; - case OCLASS_FOREIGN_SERVER: + case ForeignServerRelationId: appendStringInfoString(&buffer, "server"); break; - case OCLASS_USER_MAPPING: + case UserMappingRelationId: appendStringInfoString(&buffer, "user mapping"); break; - case OCLASS_DEFACL: + case DefaultAclRelationId: appendStringInfoString(&buffer, "default acl"); break; - case OCLASS_EXTENSION: + case ExtensionRelationId: appendStringInfoString(&buffer, "extension"); break; - case OCLASS_EVENT_TRIGGER: + case EventTriggerRelationId: appendStringInfoString(&buffer, "event trigger"); break; - case OCLASS_PARAMETER_ACL: + case ParameterAclRelationId: appendStringInfoString(&buffer, "parameter ACL"); break; - case OCLASS_POLICY: + case PolicyRelationId: appendStringInfoString(&buffer, "policy"); break; - case OCLASS_PUBLICATION: + case PublicationRelationId: appendStringInfoString(&buffer, "publication"); break; - case OCLASS_PUBLICATION_NAMESPACE: + case PublicationNamespaceRelationId: appendStringInfoString(&buffer, "publication namespace"); break; - case OCLASS_PUBLICATION_REL: + case PublicationRelRelationId: appendStringInfoString(&buffer, "publication relation"); break; - case OCLASS_SUBSCRIPTION: + case SubscriptionRelationId: appendStringInfoString(&buffer, "subscription"); break; - case OCLASS_TRANSFORM: + case TransformRelationId: appendStringInfoString(&buffer, "transform"); break; - /* - * There's intentionally no default: case here; we want the - * compiler to warn if a new OCLASS hasn't been handled above. - */ + default: + elog(ERROR, "unsupported object class: %u", object->classId); } /* the result can never be empty */ @@ -4777,9 +4732,9 @@ getObjectIdentityParts(const ObjectAddress *object, *objargs = NIL; } - switch (getObjectClass(object)) + switch (object->classId) { - case OCLASS_CLASS: + case RelationRelationId: { char *attr = NULL; @@ -4812,7 +4767,7 @@ getObjectIdentityParts(const ObjectAddress *object, } break; - case OCLASS_PROC: + case ProcedureRelationId: { bits16 flags = FORMAT_PROC_FORCE_QUALIFY | FORMAT_PROC_INVALID_AS_NULL; char *proname = format_procedure_extended(object->objectId, @@ -4828,7 +4783,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_TYPE: + case TypeRelationId: { bits16 flags = FORMAT_TYPE_INVALID_AS_NULL | FORMAT_TYPE_FORCE_QUALIFY; char *typeout; @@ -4844,7 +4799,7 @@ getObjectIdentityParts(const ObjectAddress *object, } break; - case OCLASS_CAST: + case CastRelationId: { Relation castRel; HeapTuple tup; @@ -4881,7 +4836,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_COLLATION: + case CollationRelationId: { HeapTuple collTup; Form_pg_collation coll; @@ -4908,7 +4863,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_CONSTRAINT: + case ConstraintRelationId: { HeapTuple conTup; Form_pg_constraint con; @@ -4955,7 +4910,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_CONVERSION: + case ConversionRelationId: { HeapTuple conTup; Form_pg_conversion conForm; @@ -4982,7 +4937,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_DEFAULT: + case AttrDefaultRelationId: { ObjectAddress colobject; @@ -5003,7 +4958,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_LANGUAGE: + case LanguageRelationId: { HeapTuple langTup; Form_pg_language langForm; @@ -5025,7 +4980,8 @@ getObjectIdentityParts(const ObjectAddress *object, ReleaseSysCache(langTup); break; } - case OCLASS_LARGEOBJECT: + + case LargeObjectRelationId: if (!LargeObjectExists(object->objectId)) break; appendStringInfo(&buffer, "%u", @@ -5034,7 +4990,7 @@ getObjectIdentityParts(const ObjectAddress *object, *objname = list_make1(psprintf("%u", object->objectId)); break; - case OCLASS_OPERATOR: + case OperatorRelationId: { bits16 flags = FORMAT_OPERATOR_FORCE_QUALIFY | FORMAT_OPERATOR_INVALID_AS_NULL; char *oprname = format_operator_extended(object->objectId, @@ -5049,7 +5005,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_OPCLASS: + case OperatorClassRelationId: { HeapTuple opcTup; Form_pg_opclass opcForm; @@ -5090,12 +5046,12 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_OPFAMILY: + case OperatorFamilyRelationId: getOpFamilyIdentity(&buffer, object->objectId, objname, missing_ok); break; - case OCLASS_AM: + case AccessMethodRelationId: { char *amname; @@ -5113,7 +5069,7 @@ getObjectIdentityParts(const ObjectAddress *object, } break; - case OCLASS_AMOP: + case AccessMethodOperatorRelationId: { Relation amopDesc; HeapTuple tup; @@ -5175,7 +5131,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_AMPROC: + case AccessMethodProcedureRelationId: { Relation amprocDesc; ScanKeyData skey[1]; @@ -5237,7 +5193,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_REWRITE: + case RewriteRelationId: { Relation ruleDesc; HeapTuple tup; @@ -5270,7 +5226,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_TRIGGER: + case TriggerRelationId: { Relation trigDesc; HeapTuple tup; @@ -5303,7 +5259,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_SCHEMA: + case NamespaceRelationId: { char *nspname; @@ -5322,7 +5278,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_STATISTIC_EXT: + case StatisticExtRelationId: { HeapTuple tup; Form_pg_statistic_ext formStatistic; @@ -5349,7 +5305,7 @@ getObjectIdentityParts(const ObjectAddress *object, } break; - case OCLASS_TSPARSER: + case TSParserRelationId: { HeapTuple tup; Form_pg_ts_parser formParser; @@ -5376,7 +5332,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_TSDICT: + case TSDictionaryRelationId: { HeapTuple tup; Form_pg_ts_dict formDict; @@ -5403,7 +5359,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_TSTEMPLATE: + case TSTemplateRelationId: { HeapTuple tup; Form_pg_ts_template formTmpl; @@ -5430,7 +5386,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_TSCONFIG: + case TSConfigRelationId: { HeapTuple tup; Form_pg_ts_config formCfg; @@ -5457,7 +5413,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_ROLE: + case AuthIdRelationId: { char *username; @@ -5471,7 +5427,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_ROLE_MEMBERSHIP: + case AuthMemRelationId: { Relation authMemDesc; ScanKeyData skey[1]; @@ -5514,7 +5470,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_DATABASE: + case DatabaseRelationId: { char *datname; @@ -5533,7 +5489,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_TBLSPACE: + case TableSpaceRelationId: { char *tblspace; @@ -5552,7 +5508,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_FDW: + case ForeignDataWrapperRelationId: { ForeignDataWrapper *fdw; @@ -5567,7 +5523,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_FOREIGN_SERVER: + case ForeignServerRelationId: { ForeignServer *srv; @@ -5583,7 +5539,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_USER_MAPPING: + case UserMappingRelationId: { HeapTuple tup; Oid useid; @@ -5623,7 +5579,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_DEFACL: + case DefaultAclRelationId: { Relation defaclrel; ScanKeyData skey[1]; @@ -5710,7 +5666,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_EXTENSION: + case ExtensionRelationId: { char *extname; @@ -5728,7 +5684,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_EVENT_TRIGGER: + case EventTriggerRelationId: { HeapTuple tup; Form_pg_event_trigger trigForm; @@ -5752,7 +5708,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_PARAMETER_ACL: + case ParameterAclRelationId: { HeapTuple tup; Datum nameDatum; @@ -5777,7 +5733,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_POLICY: + case PolicyRelationId: { Relation polDesc; HeapTuple tup; @@ -5810,7 +5766,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_PUBLICATION: + case PublicationRelationId: { char *pubname; @@ -5825,7 +5781,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_PUBLICATION_NAMESPACE: + case PublicationNamespaceRelationId: { char *pubname; char *nspname; @@ -5849,7 +5805,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_PUBLICATION_REL: + case PublicationRelRelationId: { HeapTuple tup; char *pubname; @@ -5878,7 +5834,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_SUBSCRIPTION: + case SubscriptionRelationId: { char *subname; @@ -5893,7 +5849,7 @@ getObjectIdentityParts(const ObjectAddress *object, break; } - case OCLASS_TRANSFORM: + case TransformRelationId: { Relation transformDesc; HeapTuple tup; @@ -5935,10 +5891,8 @@ getObjectIdentityParts(const ObjectAddress *object, } break; - /* - * There's intentionally no default: case here; we want the - * compiler to warn if a new OCLASS hasn't been handled above. - */ + default: + elog(ERROR, "unsupported object class: %u", object->classId); } if (!missing_ok) @@ -5949,8 +5903,8 @@ getObjectIdentityParts(const ObjectAddress *object, * cases above leave it as NIL. */ if (objname && *objname == NIL) - elog(ERROR, "requested object address for unsupported object class %d: text result \"%s\"", - (int) getObjectClass(object), buffer.data); + elog(ERROR, "requested object address for unsupported object class %u: text result \"%s\"", + object->classId, buffer.data); } else { diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index cd740140fd7..12802b9d3fd 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -32,6 +32,7 @@ #include "catalog/pg_largeobject_metadata.h" #include "catalog/pg_namespace.h" #include "catalog/pg_opclass.h" +#include "catalog/pg_operator.h" #include "catalog/pg_opfamily.h" #include "catalog/pg_proc.h" #include "catalog/pg_statistic_ext.h" @@ -603,8 +604,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, * so it only needs to cover object types that can be members of an * extension, and it doesn't have to deal with certain special cases * such as not wanting to process array types --- those should never - * be direct members of an extension anyway. Nonetheless, we insist - * on listing all OCLASS types in the switch. + * be direct members of an extension anyway. * * Returns the OID of the object's previous namespace, or InvalidOid if * object doesn't have a schema. @@ -614,15 +614,10 @@ AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, ObjectAddresses *objsMoved) { Oid oldNspOid = InvalidOid; - ObjectAddress dep; - dep.classId = classId; - dep.objectId = objid; - dep.objectSubId = 0; - - switch (getObjectClass(&dep)) + switch (classId) { - case OCLASS_CLASS: + case RelationRelationId: { Relation rel; @@ -635,21 +630,21 @@ AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, break; } - case OCLASS_TYPE: + case TypeRelationId: oldNspOid = AlterTypeNamespace_oid(objid, nspOid, objsMoved); break; - case OCLASS_PROC: - case OCLASS_COLLATION: - case OCLASS_CONVERSION: - case OCLASS_OPERATOR: - case OCLASS_OPCLASS: - case OCLASS_OPFAMILY: - case OCLASS_STATISTIC_EXT: - case OCLASS_TSPARSER: - case OCLASS_TSDICT: - case OCLASS_TSTEMPLATE: - case OCLASS_TSCONFIG: + case ProcedureRelationId: + case CollationRelationId: + case ConversionRelationId: + case OperatorRelationId: + case OperatorClassRelationId: + case OperatorFamilyRelationId: + case StatisticExtRelationId: + case TSParserRelationId: + case TSDictionaryRelationId: + case TSTemplateRelationId: + case TSConfigRelationId: { Relation catalog; @@ -662,41 +657,9 @@ AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, } break; - case OCLASS_CAST: - case OCLASS_CONSTRAINT: - case OCLASS_DEFAULT: - case OCLASS_LANGUAGE: - case OCLASS_LARGEOBJECT: - case OCLASS_AM: - case OCLASS_AMOP: - case OCLASS_AMPROC: - case OCLASS_REWRITE: - case OCLASS_TRIGGER: - case OCLASS_SCHEMA: - case OCLASS_ROLE: - case OCLASS_ROLE_MEMBERSHIP: - case OCLASS_DATABASE: - case OCLASS_TBLSPACE: - case OCLASS_FDW: - case OCLASS_FOREIGN_SERVER: - case OCLASS_USER_MAPPING: - case OCLASS_DEFACL: - case OCLASS_EXTENSION: - case OCLASS_EVENT_TRIGGER: - case OCLASS_PARAMETER_ACL: - case OCLASS_POLICY: - case OCLASS_PUBLICATION: - case OCLASS_PUBLICATION_NAMESPACE: - case OCLASS_PUBLICATION_REL: - case OCLASS_SUBSCRIPTION: - case OCLASS_TRANSFORM: + default: /* ignore object types that don't have schema-qualified names */ - break; - - /* - * There's intentionally no default: case here; we want the - * compiler to warn if a new OCLASS hasn't been handled above. - */ + Assert(get_object_attnum_namespace(classId) == InvalidAttrNumber); } return oldNspOid; diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c index c95e9cf6f0e..0d3214df9ca 100644 --- a/src/backend/commands/event_trigger.c +++ b/src/backend/commands/event_trigger.c @@ -21,12 +21,16 @@ #include "catalog/dependency.h" #include "catalog/indexing.h" #include "catalog/objectaccess.h" +#include "catalog/pg_authid.h" +#include "catalog/pg_auth_members.h" #include "catalog/pg_database.h" #include "catalog/pg_event_trigger.h" #include "catalog/pg_namespace.h" #include "catalog/pg_opclass.h" #include "catalog/pg_opfamily.h" +#include "catalog/pg_parameter_acl.h" #include "catalog/pg_proc.h" +#include "catalog/pg_tablespace.h" #include "catalog/pg_trigger.h" #include "catalog/pg_ts_config.h" #include "catalog/pg_type.h" @@ -1125,6 +1129,8 @@ EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata) /* * Do event triggers support this object type? + * + * See also event trigger support matrix in event-trigger.sgml. */ bool EventTriggerSupportsObjectType(ObjectType obtype) @@ -1135,133 +1141,39 @@ EventTriggerSupportsObjectType(ObjectType obtype) case OBJECT_TABLESPACE: case OBJECT_ROLE: case OBJECT_PARAMETER_ACL: - /* no support for global objects */ + /* no support for global objects (except subscriptions) */ return false; case OBJECT_EVENT_TRIGGER: /* no support for event triggers on event triggers */ return false; - case OBJECT_ACCESS_METHOD: - case OBJECT_AGGREGATE: - case OBJECT_AMOP: - case OBJECT_AMPROC: - case OBJECT_ATTRIBUTE: - case OBJECT_CAST: - case OBJECT_COLUMN: - case OBJECT_COLLATION: - case OBJECT_CONVERSION: - case OBJECT_DEFACL: - case OBJECT_DEFAULT: - case OBJECT_DOMAIN: - case OBJECT_DOMCONSTRAINT: - case OBJECT_EXTENSION: - case OBJECT_FDW: - case OBJECT_FOREIGN_SERVER: - case OBJECT_FOREIGN_TABLE: - case OBJECT_FUNCTION: - case OBJECT_INDEX: - case OBJECT_LANGUAGE: - case OBJECT_LARGEOBJECT: - case OBJECT_MATVIEW: - case OBJECT_OPCLASS: - case OBJECT_OPERATOR: - case OBJECT_OPFAMILY: - case OBJECT_POLICY: - case OBJECT_PROCEDURE: - case OBJECT_PUBLICATION: - case OBJECT_PUBLICATION_NAMESPACE: - case OBJECT_PUBLICATION_REL: - case OBJECT_ROUTINE: - case OBJECT_RULE: - case OBJECT_SCHEMA: - case OBJECT_SEQUENCE: - case OBJECT_SUBSCRIPTION: - case OBJECT_STATISTIC_EXT: - case OBJECT_TABCONSTRAINT: - case OBJECT_TABLE: - case OBJECT_TRANSFORM: - case OBJECT_TRIGGER: - case OBJECT_TSCONFIGURATION: - case OBJECT_TSDICTIONARY: - case OBJECT_TSPARSER: - case OBJECT_TSTEMPLATE: - case OBJECT_TYPE: - case OBJECT_USER_MAPPING: - case OBJECT_VIEW: + default: return true; - - /* - * There's intentionally no default: case here; we want the - * compiler to warn if a new ObjectType hasn't been handled above. - */ } - - /* Shouldn't get here, but if we do, say "no support" */ - return false; } /* * Do event triggers support this object class? + * + * See also event trigger support matrix in event-trigger.sgml. */ bool -EventTriggerSupportsObjectClass(ObjectClass objclass) +EventTriggerSupportsObject(const ObjectAddress *object) { - switch (objclass) + switch (object->classId) { - case OCLASS_DATABASE: - case OCLASS_TBLSPACE: - case OCLASS_ROLE: - case OCLASS_ROLE_MEMBERSHIP: - case OCLASS_PARAMETER_ACL: - /* no support for global objects */ + case DatabaseRelationId: + case TableSpaceRelationId: + case AuthIdRelationId: + case AuthMemRelationId: + case ParameterAclRelationId: + /* no support for global objects (except subscriptions) */ return false; - case OCLASS_EVENT_TRIGGER: + case EventTriggerRelationId: /* no support for event triggers on event triggers */ return false; - case OCLASS_CLASS: - case OCLASS_PROC: - case OCLASS_TYPE: - case OCLASS_CAST: - case OCLASS_COLLATION: - case OCLASS_CONSTRAINT: - case OCLASS_CONVERSION: - case OCLASS_DEFAULT: - case OCLASS_LANGUAGE: - case OCLASS_LARGEOBJECT: - case OCLASS_OPERATOR: - case OCLASS_OPCLASS: - case OCLASS_OPFAMILY: - case OCLASS_AM: - case OCLASS_AMOP: - case OCLASS_AMPROC: - case OCLASS_REWRITE: - case OCLASS_TRIGGER: - case OCLASS_SCHEMA: - case OCLASS_STATISTIC_EXT: - case OCLASS_TSPARSER: - case OCLASS_TSDICT: - case OCLASS_TSTEMPLATE: - case OCLASS_TSCONFIG: - case OCLASS_FDW: - case OCLASS_FOREIGN_SERVER: - case OCLASS_USER_MAPPING: - case OCLASS_DEFACL: - case OCLASS_EXTENSION: - case OCLASS_POLICY: - case OCLASS_PUBLICATION: - case OCLASS_PUBLICATION_NAMESPACE: - case OCLASS_PUBLICATION_REL: - case OCLASS_SUBSCRIPTION: - case OCLASS_TRANSFORM: + default: return true; - - /* - * There's intentionally no default: case here; we want the - * compiler to warn if a new OCLASS hasn't been handled above. - */ } - - /* Shouldn't get here, but if we do, say "no support" */ - return false; } /* @@ -1373,7 +1285,7 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no if (!currentEventTriggerState) return; - Assert(EventTriggerSupportsObjectClass(getObjectClass(object))); + Assert(EventTriggerSupportsObject(object)); /* don't report temp schemas except my own */ if (object->classId == NamespaceRelationId && diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 3ed0618b4e6..a4173ff0782 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -43,6 +43,8 @@ #include "catalog/pg_largeobject.h" #include "catalog/pg_namespace.h" #include "catalog/pg_opclass.h" +#include "catalog/pg_policy.h" +#include "catalog/pg_rewrite.h" #include "catalog/pg_statistic_ext.h" #include "catalog/pg_tablespace.h" #include "catalog/pg_trigger.h" @@ -13833,9 +13835,9 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, foundObject.objectId = foundDep->objid; foundObject.objectSubId = foundDep->objsubid; - switch (getObjectClass(&foundObject)) + switch (foundObject.classId) { - case OCLASS_CLASS: + case RelationRelationId: { char relKind = get_rel_relkind(foundObject.objectId); @@ -13862,12 +13864,12 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, break; } - case OCLASS_CONSTRAINT: + case ConstraintRelationId: Assert(foundObject.objectSubId == 0); RememberConstraintForRebuilding(foundObject.objectId, tab); break; - case OCLASS_REWRITE: + case RewriteRelationId: /* XXX someday see if we can cope with revising views */ if (subtype == AT_AlterColumnType) ereport(ERROR, @@ -13878,7 +13880,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, colName))); break; - case OCLASS_TRIGGER: + case TriggerRelationId: /* * A trigger can depend on a column because the column is @@ -13898,7 +13900,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, colName))); break; - case OCLASS_POLICY: + case PolicyRelationId: /* * A policy can depend on a column because the column is @@ -13917,7 +13919,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, colName))); break; - case OCLASS_DEFAULT: + case AttrDefaultRelationId: { ObjectAddress col = GetAttrDefaultColumnAddress(foundObject.objectId); @@ -13952,7 +13954,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, break; } - case OCLASS_STATISTIC_EXT: + case StatisticExtRelationId: /* * Give the extended-stats machinery a chance to fix anything @@ -13961,53 +13963,15 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, RememberStatisticsForRebuilding(foundObject.objectId, tab); break; - case OCLASS_PROC: - case OCLASS_TYPE: - case OCLASS_CAST: - case OCLASS_COLLATION: - case OCLASS_CONVERSION: - case OCLASS_LANGUAGE: - case OCLASS_LARGEOBJECT: - case OCLASS_OPERATOR: - case OCLASS_OPCLASS: - case OCLASS_OPFAMILY: - case OCLASS_AM: - case OCLASS_AMOP: - case OCLASS_AMPROC: - case OCLASS_SCHEMA: - case OCLASS_TSPARSER: - case OCLASS_TSDICT: - case OCLASS_TSTEMPLATE: - case OCLASS_TSCONFIG: - case OCLASS_ROLE: - case OCLASS_ROLE_MEMBERSHIP: - case OCLASS_DATABASE: - case OCLASS_TBLSPACE: - case OCLASS_FDW: - case OCLASS_FOREIGN_SERVER: - case OCLASS_USER_MAPPING: - case OCLASS_DEFACL: - case OCLASS_EXTENSION: - case OCLASS_EVENT_TRIGGER: - case OCLASS_PARAMETER_ACL: - case OCLASS_PUBLICATION: - case OCLASS_PUBLICATION_NAMESPACE: - case OCLASS_PUBLICATION_REL: - case OCLASS_SUBSCRIPTION: - case OCLASS_TRANSFORM: + default: /* - * We don't expect any of these sorts of objects to depend on - * a column. + * We don't expect any other sorts of objects to depend on a + * column. */ elog(ERROR, "unexpected object depending on column: %s", getObjectDescription(&foundObject, false)); break; - - /* - * There's intentionally no default: case here; we want the - * compiler to warn if a new OCLASS hasn't been handled above. - */ } } diff --git a/src/include/catalog/dependency.h b/src/include/catalog/dependency.h index 436b081738b..ec654010d43 100644 --- a/src/include/catalog/dependency.h +++ b/src/include/catalog/dependency.h @@ -81,55 +81,6 @@ typedef enum SharedDependencyType /* expansible list of ObjectAddresses (private in dependency.c) */ typedef struct ObjectAddresses ObjectAddresses; -/* - * This enum covers all system catalogs whose OIDs can appear in - * pg_depend.classId or pg_shdepend.classId. - */ -typedef enum ObjectClass -{ - OCLASS_CLASS, /* pg_class */ - OCLASS_PROC, /* pg_proc */ - OCLASS_TYPE, /* pg_type */ - OCLASS_CAST, /* pg_cast */ - OCLASS_COLLATION, /* pg_collation */ - OCLASS_CONSTRAINT, /* pg_constraint */ - OCLASS_CONVERSION, /* pg_conversion */ - OCLASS_DEFAULT, /* pg_attrdef */ - OCLASS_LANGUAGE, /* pg_language */ - OCLASS_LARGEOBJECT, /* pg_largeobject */ - OCLASS_OPERATOR, /* pg_operator */ - OCLASS_OPCLASS, /* pg_opclass */ - OCLASS_OPFAMILY, /* pg_opfamily */ - OCLASS_AM, /* pg_am */ - OCLASS_AMOP, /* pg_amop */ - OCLASS_AMPROC, /* pg_amproc */ - OCLASS_REWRITE, /* pg_rewrite */ - OCLASS_TRIGGER, /* pg_trigger */ - OCLASS_SCHEMA, /* pg_namespace */ - OCLASS_STATISTIC_EXT, /* pg_statistic_ext */ - OCLASS_TSPARSER, /* pg_ts_parser */ - OCLASS_TSDICT, /* pg_ts_dict */ - OCLASS_TSTEMPLATE, /* pg_ts_template */ - OCLASS_TSCONFIG, /* pg_ts_config */ - OCLASS_ROLE, /* pg_authid */ - OCLASS_ROLE_MEMBERSHIP, /* pg_auth_members */ - OCLASS_DATABASE, /* pg_database */ - OCLASS_TBLSPACE, /* pg_tablespace */ - OCLASS_FDW, /* pg_foreign_data_wrapper */ - OCLASS_FOREIGN_SERVER, /* pg_foreign_server */ - OCLASS_USER_MAPPING, /* pg_user_mapping */ - OCLASS_DEFACL, /* pg_default_acl */ - OCLASS_EXTENSION, /* pg_extension */ - OCLASS_EVENT_TRIGGER, /* pg_event_trigger */ - OCLASS_PARAMETER_ACL, /* pg_parameter_acl */ - OCLASS_POLICY, /* pg_policy */ - OCLASS_PUBLICATION, /* pg_publication */ - OCLASS_PUBLICATION_NAMESPACE, /* pg_publication_namespace */ - OCLASS_PUBLICATION_REL, /* pg_publication_rel */ - OCLASS_SUBSCRIPTION, /* pg_subscription */ - OCLASS_TRANSFORM, /* pg_transform */ -} ObjectClass; - /* flag bits for performDeletion/performMultipleDeletions: */ #define PERFORM_DELETION_INTERNAL 0x0001 /* internal action */ #define PERFORM_DELETION_CONCURRENTLY 0x0002 /* concurrent drop */ @@ -162,8 +113,6 @@ extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, DependencyType self_behavior, bool reverse_self); -extern ObjectClass getObjectClass(const ObjectAddress *object); - extern ObjectAddresses *new_object_addresses(void); extern void add_exact_object_address(const ObjectAddress *object, diff --git a/src/include/commands/event_trigger.h b/src/include/commands/event_trigger.h index f8fb659f91c..90fc1af5f69 100644 --- a/src/include/commands/event_trigger.h +++ b/src/include/commands/event_trigger.h @@ -51,7 +51,7 @@ extern ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId); extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId); extern bool EventTriggerSupportsObjectType(ObjectType obtype); -extern bool EventTriggerSupportsObjectClass(ObjectClass objclass); +extern bool EventTriggerSupportsObject(const ObjectAddress *object); extern void EventTriggerDDLCommandStart(Node *parsetree); extern void EventTriggerDDLCommandEnd(Node *parsetree); extern void EventTriggerSQLDrop(Node *parsetree); diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index 6ca93b1e478..d50e12a598c 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -1674,7 +1674,6 @@ ObjectAddressAndFlags ObjectAddressExtra ObjectAddressStack ObjectAddresses -ObjectClass ObjectPropertyType ObjectType ObjectWithArgs base-commit: ca108be72e7abf1f801c8e49dcffbbbbf412c0d9 -- 2.44.0