8000 Lock all relations referred to in updatable views · postgrespro/postgres@c3e0ddd · GitHub
[go: up one dir, main page]

Skip to content
  • Commit c3e0ddd

    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 3ae1679 commit c3e0ddd

    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
    +
    * If the view query contains any sublink subqueries then we need to also
    Original file line numberDiff line numberDiff line change
    @@ -2764,6 +2764,21 @@ rewriteTargetView(Query *parsetree, Relation view)
    27642764

    27652765
    heap_close(base_rel, NoLock);
    27662766

    2767+
    /*
    2768
    2769+
    * acquire locks on any relations they refer to. We know that there won't
    2770+
    * be any subqueries in the range table or CTEs, so we can skip those, as
    2771+
    * in AcquireRewriteLocks.
    2772+
    */
    2773+
    if (viewquery->hasSubLinks)
    2774+
    {
    2775+
    acquireLocksOnSubLinks_context context;
    2776+
    2777+
    context.for_execute = true;
    2778+
    query_tree_walker(viewquery, acquireLocksOnSubLinks, &context,
    2779+
    QTW_IGNORE_RC_SUBQUERIES);
    2780+
    }
    2781+
    27672782
    /*
    27682783
    * Create a new target RTE describing the base relation, and add it to the
    27692784
    * outer query's rangetable. (What's happening in the next few steps is

    0 commit comments

    Comments
     (0)
    0