Skip to content

Commit cb1b9b9

Browse files
committed
Lock all relations referred to in updatable views
Even views considered "simple" enough to be automatically updatable may have mulitple relations involved (eg: in a where clause). We need to make sure and lock those relations when rewriting the query. Back-patch to 9.3 where updatable views were added. Pointed out by Andres, patch thanks to Dean Rasheed.
1 parent 75232ad commit cb1b9b9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/backend/rewrite/rewriteHandler.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,21 @@ rewriteTargetView(Query *parsetree, Relation view)
24052405

24062406
heap_close(base_rel, NoLock);
24072407

2408+
/*
2409+
* If the view query contains any sublink subqueries then we need to also
2410+
* acquire locks on any relations they refer to. We know that there won't
2411+
* be any subqueries in the range table or CTEs, so we can skip those, as
2412+
* in AcquireRewriteLocks.
2413+
*/
2414+
if (viewquery->hasSubLinks)
2415+
{
2416+
acquireLocksOnSubLinks_context context;
2417+
2418+
context.for_execute = true;
2419+
query_tree_walker(viewquery, acquireLocksOnSubLinks, &context,
2420+
QTW_IGNORE_RC_SUBQUERIES);
2421+
}
2422+
24082423
/*
24092424
* Create a new target RTE describing the base relation, and add it to the
24102425
* outer query's rangetable. (What's happening in the next few steps is

0 commit comments

Comments
 (0)