mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Unify drop-by-OID functions
There are a number of Remove${Something}ById() functions that are essentially identical in structure and only different in which catalog they are working on. Refactor this to be one generic function. The information about which oid column, index, etc. to use was already available in ObjectProperty for most catalogs, in a few cases it was easily added. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/331d9661-1743-857f-1cbb-d5728bcd62cb%402ndquadrant.com
This commit is contained in:
@ -835,30 +835,6 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Drop foreign-data wrapper by OID
|
||||
*/
|
||||
void
|
||||
RemoveForeignDataWrapperById(Oid fdwId)
|
||||
{
|
||||
HeapTuple tp;
|
||||
Relation rel;
|
||||
|
||||
rel = table_open(ForeignDataWrapperRelationId, RowExclusiveLock);
|
||||
|
||||
tp = SearchSysCache1(FOREIGNDATAWRAPPEROID, ObjectIdGetDatum(fdwId));
|
||||
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwId);
|
||||
|
||||
CatalogTupleDelete(rel, &tp->t_self);
|
||||
|
||||
ReleaseSysCache(tp);
|
||||
|
||||
table_close(rel, RowExclusiveLock);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create a foreign server
|
||||
*/
|
||||
@ -1085,30 +1061,6 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Drop foreign server by OID
|
||||
*/
|
||||
void
|
||||
RemoveForeignServerById(Oid srvId)
|
||||
{
|
||||
HeapTuple tp;
|
||||
Relation rel;
|
||||
|
||||
rel = table_open(ForeignServerRelationId, RowExclusiveLock);
|
||||
|
||||
tp = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(srvId));
|
||||
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "cache lookup failed for foreign server %u", srvId);
|
||||
|
||||
CatalogTupleDelete(rel, &tp->t_self);
|
||||
|
||||
ReleaseSysCache(tp);
|
||||
|
||||
table_close(rel, RowExclusiveLock);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Common routine to check permission for user-mapping-related DDL
|
||||
* commands. We allow server owners to operate on any mapping, and
|
||||
@ -1435,29 +1387,6 @@ RemoveUserMapping(DropUserMappingStmt *stmt)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Drop user mapping by OID. This is called to clean up dependencies.
|
||||
*/
|
||||
void
|
||||
RemoveUserMappingById(Oid umId)
|
||||
{
|
||||
HeapTuple tp;
|
||||
Relation rel;
|
||||
|
||||
rel = table_open(UserMappingRelationId, RowExclusiveLock);
|
||||
|
||||
tp = SearchSysCache1(USERMAPPINGOID, ObjectIdGetDatum(umId));
|
||||
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "cache lookup failed for user mapping %u", umId);
|
||||
|
||||
CatalogTupleDelete(rel, &tp->t_self);
|
||||
|
||||
ReleaseSysCache(tp);
|
||||
|
||||
table_close(rel, RowExclusiveLock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a foreign table
|
||||
* call after DefineRelation().
|
||||
|
Reference in New Issue
Block a user