From a0ac3f2c62e19355005d4fc5f0fa5a0214b3fac9 Mon Sep 17 00:00:00 2001 From: Zhibai Song Date: Wed, 5 Mar 2025 23:34:13 +0000 Subject: [PATCH] alter procedure/function will unexpectly delete pg_depend records Backgroud: Previously when we implement alter procedure/function feature, we did follow steps in update metadata: 1. Create a new procedure/function 2. use the old oid to replace the new oid in the pg_proc metadata 3. clean the pg_depend records refer to the new oid Analysis: But for the first step in creating a new proc/function, if the parameter list is not change, it'll just update the old tuple, so in such case old oid will be the same with new oid, in such case we should not drop pg_depend records. Fix: Skip drop pg_depend records if old oid = new oid Issue-resolved: BABEL-5601 Signed-off-by: Zhibai Song --- contrib/babelfishpg_tsql/src/pl_handler.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/pl_handler.c b/contrib/babelfishpg_tsql/src/pl_handler.c index 4b1e7d0ba0..13b3bfe8fb 100644 --- a/contrib/babelfishpg_tsql/src/pl_handler.c +++ b/contrib/babelfishpg_tsql/src/pl_handler.c @@ -2729,10 +2729,17 @@ bbf_ProcessUtility(PlannedStmt *pstmt, */ alter_bbf_schema_permissions_catalog(stmt->func, cfs->parameters, stmt->objtype, oldoid); } - /* Clean up table entries for the create function statement */ - deleteDependencyRecordsFor(DefaultAclRelationId, address.objectId, false); - deleteDependencyRecordsFor(ProcedureRelationId, address.objectId, false); - deleteSharedDependencyRecordsFor(ProcedureRelationId, address.objectId, 0); + /* Clean up table entries for the create function statement if applicable*/ + if (address.objectId != oldoid) + { + /* + * if this is the same procedure, it'll update the existing one, + * in such case, should not delete dependent records + */ + deleteDependencyRecordsFor(DefaultAclRelationId, address.objectId, false); + deleteDependencyRecordsFor(ProcedureRelationId, address.objectId, false); + deleteSharedDependencyRecordsFor(ProcedureRelationId, address.objectId, 0); + } CommitTransactionCommand(); } PG_FINALLY();