I would even say that DropCastById belongs in the new file, which is just the attached. However, none of the Drop.*ById or Remove.*ById functions seem to be in backend/catalog/ at all, and moving just a single one seems to make things even more inconsistent. I think all these catalog-accessing functions should be in backend/catalog/ but I'm not in a hurry to patch half of backend/commands/ to move them all.
(I think the current arrangement is just fallout from having created the dependency.c system to drop objects, which rid us of a bunch of bespoke deletion-handling code.) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
diff --git a/src/backend/catalog/pg_cast.c b/src/backend/catalog/pg_cast.c index 3854455637..bd2a369aad 100644 --- a/src/backend/catalog/pg_cast.c +++ b/src/backend/catalog/pg_cast.c @@ -14,7 +14,9 @@ */ #include "postgres.h" +#include "access/genam.h" #include "access/htup_details.h" +#include "access/skey.h" #include "access/table.h" #include "catalog/catalog.h" #include "catalog/dependency.h" @@ -24,6 +26,7 @@ #include "catalog/pg_proc.h" #include "catalog/pg_type.h" #include "utils/builtins.h" +#include "utils/fmgroids.h" #include "utils/rel.h" #include "utils/syscache.h" @@ -121,3 +124,29 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext, return myself; } + +void +DropCastById(Oid castOid) +{ + Relation relation; + ScanKeyData scankey; + SysScanDesc scan; + HeapTuple tuple; + + relation = table_open(CastRelationId, RowExclusiveLock); + + ScanKeyInit(&scankey, + Anum_pg_cast_oid, + BTEqualStrategyNumber, F_OIDEQ, + ObjectIdGetDatum(castOid)); + scan = systable_beginscan(relation, CastOidIndexId, true, + NULL, 1, &scankey); + + tuple = systable_getnext(scan); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "could not find tuple for cast %u", castOid); + CatalogTupleDelete(relation, &tuple->t_self); + + systable_endscan(scan); + table_close(relation, RowExclusiveLock); +} diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 5eac55aaca..355e93840a 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -1645,33 +1645,6 @@ CreateCast(CreateCastStmt *stmt) return myself; } -void -DropCastById(Oid castOid) -{ - Relation relation; - ScanKeyData scankey; - SysScanDesc scan; - HeapTuple tuple; - - relation = table_open(CastRelationId, RowExclusiveLock); - - ScanKeyInit(&scankey, - Anum_pg_cast_oid, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(castOid)); - scan = systable_beginscan(relation, CastOidIndexId, true, - NULL, 1, &scankey); - - tuple = systable_getnext(scan); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "could not find tuple for cast %u", castOid); - CatalogTupleDelete(relation, &tuple->t_self); - - systable_endscan(scan); - table_close(relation, RowExclusiveLock); -} - - static void check_transform_function(Form_pg_proc procstruct) { diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h index 2620ff40f0..78ba395f17 100644 --- a/src/include/catalog/pg_cast.h +++ b/src/include/catalog/pg_cast.h @@ -95,5 +95,6 @@ extern ObjectAddress CastCreate(Oid sourcetypeid, char castcontext, char castmethod, DependencyType behavior); +extern void DropCastById(Oid castOid); #endif /* PG_CAST_H */ diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h index c77c9a6ed5..1d22cc8083 100644 --- a/src/include/commands/defrem.h +++ b/src/include/commands/defrem.h @@ -56,7 +56,6 @@ extern ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt extern void RemoveFunctionById(Oid funcOid); extern ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt); extern ObjectAddress CreateCast(CreateCastStmt *stmt); -extern void DropCastById(Oid castOid); extern ObjectAddress CreateTransform(CreateTransformStmt *stmt); extern void DropTransformById(Oid transformOid); extern void IsThereFunctionInNamespace(const char *proname, int pronargs,