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