Make viewquery a copy in rewriteTargetView()
authorStephen Frost
Mon, 21 Dec 2015 15:34:20 +0000 (10:34 -0500)
committerStephen Frost
Mon, 21 Dec 2015 15:34:20 +0000 (10:34 -0500)
commit496943ec2b6de0f22cd9e18f673e13635b5972ef
treecace174a6042ba44850e98beb69f33d61fde5c50
parent0c28e767c612c9e90ae8ab188cf9b21114a34ddc
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.
src/backend/rewrite/rewriteHandler.c
src/test/regress/expected/updatable_views.out
src/test/regress/sql/updatable_views.sql