diff options
author | Stephen Frost | 2015-09-08 21:02:49 +0000 |
---|---|---|
committer | Pavan Deolasee | 2016-10-26 07:40:06 +0000 |
commit | 9331c06da040d2d99da08f97f9daceb9ac17ceaf (patch) | |
tree | 17b238a2242d74318df863a5790e90c645ac932f | |
parent | 816571af0b0f8743c3a0e6c8a81469ee2d075f8e (diff) |
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.
-rw-r--r-- | src/backend/rewrite/rewriteHandler.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index c902a96935..0e4ae86662 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -2910,6 +2910,21 @@ rewriteTargetView(Query *parsetree, Relation view) heap_close(base_rel, NoLock); /* + * If the view query contains any sublink subqueries then we need to also + * acquire locks on any relations they refer to. We know that there won't + * be any subqueries in the range table or CTEs, so we can skip those, as + * in AcquireRewriteLocks. + */ + if (viewquery->hasSubLinks) + { + acquireLocksOnSubLinks_context context; + + context.for_execute = true; + query_tree_walker(viewquery, acquireLocksOnSubLinks, &context, + QTW_IGNORE_RC_SUBQUERIES); + } + + /* * Create a new target RTE describing the base relation, and add it to the * outer query's rangetable. (What's happening in the next few steps is * very much like what the planner would do to "pull up" the view into the |