Fix CREATE MATVIEW/CREATE TABLE AS ... WITH NO DATA to not plan the query.
authorTom Lane
Mon, 27 Jun 2016 19:57:21 +0000 (15:57 -0400)
committerTom Lane
Mon, 27 Jun 2016 19:57:21 +0000 (15:57 -0400)
commitdc9e03bf474a42c46cab1ec02456bcd43be45c58
treea09d9074ab612a42a9e6882b0119870c5d4d86f8
parent61b24fef89a9f7e381e6d83029b63e062d32812b
Fix CREATE MATVIEW/CREATE TABLE AS ... WITH NO DATA to not plan the query.

Previously, these commands always planned the given query and went through
executor startup before deciding not to actually run the query if WITH NO
DATA is specified.  This behavior is problematic for pg_dump because it
may cause errors to be raised that we would rather not see before a
REFRESH MATERIALIZED VIEW command is issued.  See for example bug #13907
from Marian Krucina.  This change is not sufficient to fix that particular
bug, because we also need to tweak pg_dump to issue the REFRESH later,
but it's a necessary step on the way.

A user-visible side effect of doing things this way is that the returned
command tag for WITH NO DATA cases will now be "CREATE MATERIALIZED VIEW"
or "CREATE TABLE AS", not "SELECT 0".  We could preserve the old behavior
but it would take more code, and arguably that was just an implementation
artifact not intended behavior anyhow.

In 9.5 and HEAD, also get rid of the static variable CreateAsReladdr, which
was trouble waiting to happen; there is not any prohibition on nested
CREATE commands.

Back-patch to 9.3 where CREATE MATERIALIZED VIEW was introduced.

Michael Paquier and Tom Lane

Report: <20160202161407[email protected]>
src/backend/commands/createas.c
src/backend/commands/view.c
src/backend/nodes/makefuncs.c
src/include/nodes/makefuncs.h
src/test/regress/expected/matview.out
src/test/regress/expected/select_into.out
src/test/regress/sql/matview.sql
src/test/regress/sql/select_into.sql