diff options
author | Peter Eisentraut | 2024-03-26 07:51:18 +0000 |
---|---|---|
committer | Peter Eisentraut | 2024-03-26 09:08:56 +0000 |
commit | 89e5ef7e21812916c9cf9fcf56e45f0f74034656 (patch) | |
tree | 4ba9e8a3aadbc9c114f9f5a68512b0e954a853ef /src/backend/commands/alter.c | |
parent | 8c4f2d5475b9f0411baf38590c054ba1fb566780 (diff) |
Remove ObjectClass type
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.
Reviewed-by: jian he <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAGECzQT3caUbcCcszNewCCmMbCuyP7XNAm60J3ybd6PN5kH2Dw%40mail.gmail.com
Diffstat (limited to 'src/backend/commands/alter.c')
-rw-r--r-- | src/backend/commands/alter.c | 73 |
1 files changed, 18 insertions, 55 deletions
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; |