diff options
author | Stephen Frost <sfrost@snowman.net> | 2015-09-08 17:02:49 -0400 |
---|---|---|
committer | Stephen Frost <sfrost@snowman.net> | 2015-09-08 17:02:49 -0400 |
commit | c3e0ddd403d74b161cd83cdccbb0adc45788934f (patch) | |
tree | 64983089c9305de88626d72c24dbd546562c76c4 /src | |
parent | 3ae16798f0f9d2d941e50062b579c28c9b946c9e (diff) | |
download | postgresql-c3e0ddd403d74b161cd83cdccbb0adc45788934f.tar.gz postgresql-c3e0ddd403d74b161cd83cdccbb0adc45788934f.zip |
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.
Diffstat (limited to 'src')
-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 761047ca082..db3c2c7a76e 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -2765,6 +2765,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 |