Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 83d0049

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 b74af40 commit 83d0049

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
@@ -2626,6 +2626,21 @@ rewriteTargetView(Query *parsetree, Relation view)
26262626

26272627
heap_close(base_rel, NoLock);
26282628

2629+
/*
2630+
* If the view query contains any sublink subqueries then we need to also
2631+
* acquire locks on any relations they refer to. We know that there won't
2632+
* be any subqueries in the range table or CTEs, so we can skip those, as
2633+
* in AcquireRewriteLocks.
2634+
*/
2635+
if (viewquery->hasSubLinks)
2636+
{
2637+
acquireLocksOnSubLinks_context context;
2638+
2639+
context.for_execute = true;
2640+
query_tree_walker(viewquery, acquireLocksOnSubLinks, &context,
2641+
QTW_IGNORE_RC_SUBQUERIES);
2642+
}
2643+
26292644
/*
26302645
* Create a new target RTE describing the base relation, and add it to the
26312646
* outer query's rangetable. (What's happening in the next few steps is

0 commit comments

Comments
 (0)