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) ...@@ -69,7 +69,7 @@ CommentObject(CommentStmt *stmt)
* against concurrent DROP operations. * against concurrent DROP operations.
*/ */
address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs, address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,
&relation, ShareUpdateExclusiveLock); &relation, ShareUpdateExclusiveLock, false);
/* Require ownership of the target object. */ /* Require ownership of the target object. */
check_object_ownership(GetUserId(), stmt->objtype, address, check_object_ownership(GetUserId(), stmt->objtype, address,
......
...@@ -2703,7 +2703,7 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt) ...@@ -2703,7 +2703,7 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt)
* against concurrent DROP and ALTER EXTENSION ADD/DROP operations. * against concurrent DROP and ALTER EXTENSION ADD/DROP operations.
*/ */
object = get_object_address(stmt->objtype, stmt->objname, stmt->objargs, object = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,
&relation, ShareUpdateExclusiveLock); &relation, ShareUpdateExclusiveLock, false);
/* Permission check: must own target object, too */ /* Permission check: must own target object, too */
check_object_ownership(GetUserId(), stmt->objtype, object, check_object_ownership(GetUserId(), stmt->objtype, object,
......
...@@ -88,7 +88,7 @@ ExecSecLabelStmt(SecLabelStmt *stmt) ...@@ -88,7 +88,7 @@ ExecSecLabelStmt(SecLabelStmt *stmt)
* guard against concurrent modifications. * guard against concurrent modifications.
*/ */
address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs, address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,
&relation, ShareUpdateExclusiveLock); &relation, ShareUpdateExclusiveLock, false);
/* Require ownership of the target object. */ /* Require ownership of the target object. */
check_object_ownership(GetUserId(), stmt->objtype, address, check_object_ownership(GetUserId(), stmt->objtype, address,
......
...@@ -132,7 +132,8 @@ get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok) ...@@ -132,7 +132,8 @@ get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
* were unique across the entire database. * were unique across the entire database.
*/ */
Oid 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; Relation RewriteRelation;
HeapScanDesc scanDesc; HeapScanDesc scanDesc;
...@@ -151,20 +152,26 @@ get_rewrite_oid_without_relid(const char *rulename, Oid *reloid) ...@@ -151,20 +152,26 @@ get_rewrite_oid_without_relid(const char *rulename, Oid *reloid)
htup = heap_getnext(scanDesc, ForwardScanDirection); htup = heap_getnext(scanDesc, ForwardScanDirection);
if (!HeapTupleIsValid(htup)) if (!HeapTupleIsValid(htup))
ereport(ERROR, {
(errcode(ERRCODE_UNDEFINED_OBJECT), if (!missing_ok)
errmsg("rule \"%s\" does not exist", rulename))); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
ruleoid = HeapTupleGetOid(htup); errmsg("rule \"%s\" does not exist", rulename)));
if (reloid != NULL) ruleoid = InvalidOid;
*reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class; }
else
if (HeapTupleIsValid(htup = heap_getnext(scanDesc, ForwardScanDirection))) {
ereport(ERROR, ruleoid = HeapTupleGetOid(htup);
(errcode(ERRCODE_DUPLICATE_OBJECT), if (reloid != NULL)
errmsg("there are multiple rules named \"%s\"", rulename), *reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
errhint("Specify a relation name as well as a rule name.")));
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_endscan(scanDesc);
heap_close(RewriteRelation, AccessShareLock); heap_close(RewriteRelation, AccessShareLock);
......
...@@ -28,7 +28,8 @@ typedef struct ObjectAddress ...@@ -28,7 +28,8 @@ typedef struct ObjectAddress
} ObjectAddress; } ObjectAddress;
extern ObjectAddress get_object_address(ObjectType objtype, List *objname, 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, extern void check_object_ownership(Oid roleid,
ObjectType objtype, ObjectAddress address, ObjectType objtype, ObjectAddress address,
......
...@@ -23,6 +23,7 @@ extern void SetRelationRuleStatus(Oid relationId, bool relHasRules, ...@@ -23,6 +23,7 @@ extern void SetRelationRuleStatus(Oid relationId, bool relHasRules,
bool relIsBecomingView); bool relIsBecomingView);
extern Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok); 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 */ #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