1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-14 08:21:07 +03:00

Further consolidation of DROP statement handling.

This gets rid of an impressive amount of duplicative code, with only
minimal behavior changes.  DROP FOREIGN DATA WRAPPER now requires object
ownership rather than superuser privileges, matching the documentation
we already have.  We also eliminate the historical warning about dropping
a built-in function as unuseful.  All operations are now performed in the
same order for all object types handled by dropcmds.c.

KaiGai Kohei, with minor revisions by me
This commit is contained in:
Robert Haas
2011-11-17 21:31:29 -05:00
parent 709aca5960
commit fc6d1006bd
21 changed files with 241 additions and 1148 deletions

View File

@ -30,71 +30,6 @@
#include "utils/syscache.h"
#include "utils/tqual.h"
/*
* RemoveRewriteRule
*
* Delete a rule given its name.
*/
void
RemoveRewriteRule(RangeVar *relation, const char *ruleName,
DropBehavior behavior, bool missing_ok)
{
HeapTuple tuple;
Oid eventRelationOid;
Oid owningRel;
ObjectAddress object;
/* lock level should match RemoveRewriteRuleById */
owningRel = RangeVarGetRelid(relation, AccessExclusiveLock,
false, false);
/*
* Find the tuple for the target rule.
*/
tuple = SearchSysCache2(RULERELNAME,
ObjectIdGetDatum(owningRel),
PointerGetDatum(ruleName));
/*
* complain if no rule with such name exists
*/
if (!HeapTupleIsValid(tuple))
{
if (!missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" for relation \"%s\" does not exist",
ruleName, get_rel_name(owningRel))));
else
ereport(NOTICE,
(errmsg("rule \"%s\" for relation \"%s\" does not exist, skipping",
ruleName, get_rel_name(owningRel))));
return;
}
/*
* Verify user has appropriate permissions.
*/
eventRelationOid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;
Assert(eventRelationOid == owningRel);
if (!pg_class_ownercheck(eventRelationOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
get_rel_name(eventRelationOid));
/*
* Do the deletion
*/
object.classId = RewriteRelationId;
object.objectId = HeapTupleGetOid(tuple);
object.objectSubId = 0;
ReleaseSysCache(tuple);
performDeletion(&object, behavior);
}
/*
* Guts of rule deletion.
*/