From 905a4d996acef8931614dd8fa38d247a123fe180 Mon Sep 17 00:00:00 2001 From: Sharu Goel <30777678+thephantomthief@users.noreply.github.com> Date: Wed, 2 Feb 2022 00:12:19 +0530 Subject: [PATCH] Fix table type dependency on owner Previously, when creating a table type, the underlying table had a dependency on both the table type and the the role that created it. The DROP OWNED BY command will try to drop the table, and fail because the table depends on the table type. This commit removes the underlying table's dependency on the role, and instead adds a dependency for the table type on the role. This way, DROP OWNED BY will try to drop the table type instead, and succeed in dropping both the table type and the underlying table. Task: BABEL-2706 Author: Zitao Quan Signed-off-by: Sharu Goel --- src/backend/commands/tablecmds.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 7a366f94f16..150a970cdcc 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -1191,12 +1191,19 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, * created composite type as the desired table type. * So, remove the composite type's dependency on the relation, and record * the relation's dependency on the composite type. + * Also, remove the relation's dependency on the owner, and record the + * composite type's dependency on the owner. */ if (stmt->tsql_tabletype) { deleteDependencyRecordsForClass(typaddress->classId, typaddress->objectId, RelationRelationId, DEPENDENCY_INTERNAL); recordDependencyOn(&address, typaddress, DEPENDENCY_INTERNAL); + + deleteSharedDependencyRecordsFor(address.classId, address.objectId, + address.objectSubId); + recordDependencyOnOwner(typaddress->classId, typaddress->objectId, + ownerId); } /*