Commit c533c147 authored by Robert Haas's avatar Robert Haas

Add a missing_ok argument to get_object_address().

This lays the groundwork for an upcoming patch to streamline the
handling of DROP commands.

KaiGai Kohei
parent e1cd66f7
This diff is collapsed.
......@@ -69,7 +69,7 @@ CommentObject(CommentStmt *stmt)
* against concurrent DROP operations.
*/
address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,
&relation, ShareUpdateExclusiveLock);
&relation, ShareUpdateExclusiveLock, false);
/* Require ownership of the target object. */
check_object_ownership(GetUserId(), stmt->objtype, address,
......
......@@ -2703,7 +2703,7 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt)
* against concurrent DROP and ALTER EXTENSION ADD/DROP operations.
*/
object = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,
&relation, ShareUpdateExclusiveLock);
&relation, ShareUpdateExclusiveLock, false);
/* Permission check: must own target object, too */
check_object_ownership(GetUserId(), stmt->objtype, object,
......
......@@ -88,7 +88,7 @@ ExecSecLabelStmt(SecLabelStmt *stmt)
* guard against concurrent modifications.
*/
address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,
&relation, ShareUpdateExclusiveLock);
&relation, ShareUpdateExclusiveLock, false);
/* Require ownership of the target object. */
check_object_ownership(GetUserId(), stmt->objtype, address,
......
......@@ -132,7 +132,8 @@ get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
* were unique across the entire database.
*/
Oid
get_rewrite_oid_without_relid(const char *rulename, Oid *reloid)
get_rewrite_oid_without_relid(const char *rulename,
Oid *reloid, bool missing_ok)
{
Relation RewriteRelation;
HeapScanDesc scanDesc;
......@@ -151,20 +152,26 @@ get_rewrite_oid_without_relid(const char *rulename, Oid *reloid)
htup = heap_getnext(scanDesc, ForwardScanDirection);
if (!HeapTupleIsValid(htup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" does not exist", rulename)));
ruleoid = HeapTupleGetOid(htup);
if (reloid != NULL)
*reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
if (HeapTupleIsValid(htup = heap_getnext(scanDesc, ForwardScanDirection)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("there are multiple rules named \"%s\"", rulename),
errhint("Specify a relation name as well as a rule name.")));
{
if (!missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" does not exist", rulename)));
ruleoid = InvalidOid;
}
else
{
ruleoid = HeapTupleGetOid(htup);
if (reloid != NULL)
*reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
htup = heap_getnext(scanDesc, ForwardScanDirection);
if (HeapTupleIsValid(htup))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("there are multiple rules named \"%s\"", rulename),
errhint("Specify a relation name as well as a rule name.")));
}
heap_endscan(scanDesc);
heap_close(RewriteRelation, AccessShareLock);
......
......@@ -28,7 +28,8 @@ typedef struct ObjectAddress
} ObjectAddress;
extern ObjectAddress get_object_address(ObjectType objtype, List *objname,
List *objargs, Relation *relp, LOCKMODE lockmode);
List *objargs, Relation *relp,
LOCKMODE lockmode, bool missing_ok);
extern void check_object_ownership(Oid roleid,
ObjectType objtype, ObjectAddress address,
......
......@@ -23,6 +23,7 @@ extern void SetRelationRuleStatus(Oid relationId, bool relHasRules,
bool relIsBecomingView);
extern Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok);
extern Oid get_rewrite_oid_without_relid(const char *rulename, Oid *relid);
extern Oid get_rewrite_oid_without_relid(const char *rulename,
Oid *relid, bool missing_ok);
#endif /* REWRITESUPPORT_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment