pgsql: Make viewquery a copy in rewriteTargetView()

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make viewquery a copy in rewriteTargetView()
Date: 2015-12-21 15:35:24
Message-ID: E1aB2Ue-0002Di-93@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make viewquery a copy in rewriteTargetView()

Rather than expect the Query returned by get_view_query() to be
read-only and then copy bits and pieces of it out, simply copy the
entire structure when we get it. This addresses an issue where
AcquireRewriteLocks, which is called by acquireLocksOnSubLinks(),
scribbles on the parsetree passed in, which was actually an entry
in relcache, leading to segfaults with certain view definitions.
This also future-proofs us a bit for anyone adding more code to this
path.

The acquireLocksOnSubLinks() was added in commit c3e0ddd40.

Back-patch to 9.3 as that commit was.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/6f8cb1e23485bd6d45e8865760436e1a5ce65a6d

Modified Files
--------------
src/backend/rewrite/rewriteHandler.c | 34 ++++++++-----
src/test/regress/expected/updatable_views.out | 67 +++++++++++++++++++++++++
src/test/regress/sql/updatable_views.sql | 44 ++++++++++++++++
3 files changed, 133 insertions(+), 12 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2015-12-21 20:09:02 pgsql: Fix calculation of space needed for parsed words in tab completi
Previous Message Tom Lane 2015-12-20 23:30:14 pgsql: Remove silly completion for "DELETE FROM tabname ...".