aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2024-03-26 08:51:18 +0100
committerPeter Eisentraut <peter@eisentraut.org>2024-03-26 10:08:56 +0100
commit89e5ef7e21812916c9cf9fcf56e45f0f74034656 (patch)
tree4ba9e8a3aadbc9c114f9f5a68512b0e954a853ef /src/backend/commands/tablecmds.c
parent8c4f2d5475b9f0411baf38590c054ba1fb566780 (diff)
downloadpostgresql-89e5ef7e21812916c9cf9fcf56e45f0f74034656.tar.gz
postgresql-89e5ef7e21812916c9cf9fcf56e45f0f74034656.zip
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 <jian.universality@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/CAGECzQT3caUbcCcszNewCCmMbCuyP7XNAm60J3ybd6PN5kH2Dw%40mail.gmail.com
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c62
1 files changed, 13 insertions, 49 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 259b4237a24..635d54645d3 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -44,6 +44,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"
@@ -13977,9 +13979,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);
@@ -14006,12 +14008,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,
@@ -14022,7 +14024,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype,
colName)));
break;
- case OCLASS_TRIGGER:
+ case TriggerRelationId:
/*
* A trigger can depend on a column because the column is
@@ -14042,7 +14044,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype,
colName)));
break;
- case OCLASS_POLICY:
+ case PolicyRelationId:
/*
* A policy can depend on a column because the column is
@@ -14061,7 +14063,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype,
colName)));
break;
- case OCLASS_DEFAULT:
+ case AttrDefaultRelationId:
{
ObjectAddress col = GetAttrDefaultColumnAddress(foundObject.objectId);
@@ -14096,7 +14098,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype,
break;
}
- case OCLASS_STATISTIC_EXT:
+ case StatisticExtRelationId:
/*
* Give the extended-stats machinery a chance to fix anything
@@ -14105,53 +14107,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.
- */
}
}