Make viewquery a copy in rewriteTargetView()
authorStephen Frost
Mon, 21 Dec 2015 15:34:23 +0000 (10:34 -0500)
committerStephen Frost
Mon, 21 Dec 2015 15:34:23 +0000 (10:34 -0500)
commitf02137da88c49125a20d7c51ae9932e47eb61f93
treed9c9eb34fc9fbe2aa17d99cc3cbc478a87b3722e
parent590d201ef73c7f34f919b8fd9ecf17d81de25aa4
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