pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Fix CREATE MATVIEW/CREATE TABLE AS ... WITH NO DATA to not plan
Date: Mon, 27 Jun 2016 19:58:01 +0000
Message-ID: <E1bHcfR-00077y-Og@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

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.2778.24659@wrigleys.postgresql.org>

Branch
------
REL9_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/dc9e03bf474a42c46cab1ec02456bcd43be45c58

Modified Files
--------------
src/backend/commands/createas.c           | 362 +++++++++++++++++++-----------
src/backend/commands/view.c               |  22 +-
src/backend/nodes/makefuncs.c             |  30 +++
src/include/nodes/makefuncs.h             |   3 +
src/test/regress/expected/matview.out     |  63 +++++-
src/test/regress/expected/select_into.out |  38 ++++
src/test/regress/sql/matview.sql          |  39 +++-
src/test/regress/sql/select_into.sql      |  19 ++
8 files changed, 404 insertions(+), 172 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


view thread (4+ messages)  latest in thread

Message-ID: <E1bHcfR-00077y-Og@gemulon.postgresql.org>
Permalink:  ../E1bHcfR-00077y-Og@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1bHcfR-00077y-Og@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix CREATE MATVIEW/CREATE TABLE AS ... WITH NO DATA to not plan
  In-Reply-To: <E1bHcfR-00077y-Og@gemulon.postgresql.org>
  References: <E1bHcfR-00077y-Og@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox