static AclResult LockTableAclCheck(Oid relid, LOCKMODE lockmode, Oid userid);
static void RangeVarCallbackForLockTable(const RangeVar *rv, Oid relid,
Oid oldrelid, void *arg);
-static void LockViewRecurse(Oid reloid, LOCKMODE lockmode, bool nowait, List *ancestor_views);
+static void LockViewRecurse(Oid reloid, LOCKMODE lockmode, bool nowait,
+ List *ancestor_views);
/*
* LOCK TABLE
strcmp(rte->eref->aliasname, "new") == 0))
continue;
- /* Check infinite recursion in the view definition. */
+ /*
+ * We might be dealing with a self-referential view. If so, we
+ * can just stop recursing, since we already locked it.
+ */
if (list_member_oid(context->ancestor_views, relid))
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("infinite recursion detected in rules for relation \"%s\"",
- get_rel_name(relid))));
+ continue;
/* Check permissions with the view owner's privilege. */
aclresult = LockTableAclCheck(relid, context->lockmode, context->viewowner);
get_rel_name(relid))));
if (rte->relkind == RELKIND_VIEW)
- LockViewRecurse(relid, context->lockmode, context->nowait, context->ancestor_views);
+ LockViewRecurse(relid, context->lockmode, context->nowait,
+ context->ancestor_views);
else if (rte->inh)
LockTableRecurse(relid, context->lockmode, context->nowait);
}
}
static void
-LockViewRecurse(Oid reloid, LOCKMODE lockmode, bool nowait, List *ancestor_views)
+LockViewRecurse(Oid reloid, LOCKMODE lockmode, bool nowait,
+ List *ancestor_views)
{
LockViewRecurse_context context;
-
Relation view;
Query *viewquery;
+ /* caller has already locked the view */
view = table_open(reloid, NoLock);
viewquery = get_view_query(view);
(2 rows)
ROLLBACK;
--- detecting infinite recursions in view definitions
+-- Verify that we cope with infinite recursion in view definitions.
CREATE OR REPLACE VIEW lock_view2 AS SELECT * from lock_view3;
BEGIN TRANSACTION;
LOCK TABLE lock_view2 IN EXCLUSIVE MODE;
-ERROR: infinite recursion detected in rules for relation "lock_view2"
ROLLBACK;
CREATE VIEW lock_view7 AS SELECT * from lock_view2;
BEGIN TRANSACTION;
LOCK TABLE lock_view7 IN EXCLUSIVE MODE;
-ERROR: infinite recursion detected in rules for relation "lock_view2"
ROLLBACK;
-- Verify that we can lock a table with inheritance children.
CREATE TABLE lock_tbl2 (b BIGINT) INHERITS (lock_tbl1);