Skip to content

Commit

Permalink
alter procedure/function will unexpectly delete pg_depend records
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Zhibai Song committed Mar 5, 2025
1 parent 948d8b9 commit a0ac3f2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions contrib/babelfishpg_tsql/src/pl_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a0ac3f2

Please sign in to comment.