1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-12 21:01:52 +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:
Peter Eisentraut
2020-06-09 09:10:14 +02:00
parent b27c90bbe4
commit b1d32d3e32
23 changed files with 175 additions and 619 deletions

View File

@ -1657,105 +1657,6 @@ dropProcedures(List *opfamilyname, Oid amoid, Oid opfamilyoid,
}
}
/*
* Deletion subroutines for use by dependency.c.
*/
void
RemoveOpFamilyById(Oid opfamilyOid)
{
Relation rel;
HeapTuple tup;
rel = table_open(OperatorFamilyRelationId, RowExclusiveLock);
tup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamilyOid));
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "cache lookup failed for opfamily %u", opfamilyOid);
CatalogTupleDelete(rel, &tup->t_self);
ReleaseSysCache(tup);
table_close(rel, RowExclusiveLock);
}
void
RemoveOpClassById(Oid opclassOid)
{
Relation rel;
HeapTuple tup;
rel = table_open(OperatorClassRelationId, RowExclusiveLock);
tup = SearchSysCache1(CLAOID, ObjectIdGetDatum(opclassOid));
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "cache lookup failed for opclass %u", opclassOid);
CatalogTupleDelete(rel, &tup->t_self);
ReleaseSysCache(tup);
table_close(rel, RowExclusiveLock);
}
void
RemoveAmOpEntryById(Oid entryOid)
{
Relation rel;
HeapTuple tup;
ScanKeyData skey[1];
SysScanDesc scan;
ScanKeyInit(&skey[0],
Anum_pg_amop_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(entryOid));
rel = table_open(AccessMethodOperatorRelationId, RowExclusiveLock);
scan = systable_beginscan(rel, AccessMethodOperatorOidIndexId, true,
NULL, 1, skey);
/* we expect exactly one match */
tup = systable_getnext(scan);
if (!HeapTupleIsValid(tup))
elog(ERROR, "could not find tuple for amop entry %u", entryOid);
CatalogTupleDelete(rel, &tup->t_self);
systable_endscan(scan);
table_close(rel, RowExclusiveLock);
}
void
RemoveAmProcEntryById(Oid entryOid)
{
Relation rel;
HeapTuple tup;
ScanKeyData skey[1];
SysScanDesc scan;
ScanKeyInit(&skey[0],
Anum_pg_amproc_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(entryOid));
rel = table_open(AccessMethodProcedureRelationId, RowExclusiveLock);
scan = systable_beginscan(rel, AccessMethodProcedureOidIndexId, true,
NULL, 1, skey);
/* we expect exactly one match */
tup = systable_getnext(scan);
if (!HeapTupleIsValid(tup))
elog(ERROR, "could not find tuple for amproc entry %u", entryOid);
CatalogTupleDelete(rel, &tup->t_self);
systable_endscan(scan);
table_close(rel, RowExclusiveLock);
}
/*
* Subroutine for ALTER OPERATOR CLASS SET SCHEMA/RENAME
*