pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Sanitize IF NOT EXISTS in EXPLAIN for CTAS and matviews
Date: Wed, 30 Dec 2020 12:24:53 +0000
Message-ID: <E1kuaX7-0000Q9-MT@gemulon.postgresql.org> (raw)

Sanitize IF NOT EXISTS in EXPLAIN for CTAS and matviews

IF NOT EXISTS was ignored when specified in an EXPLAIN query for CREATE
MATERIALIZED VIEW or CREATE TABLE AS.  Hence, if this clause was
specified, the caller would get a failure if the relation already
exists instead of a success with a NOTICE message.

This commit makes the behavior of IF NOT EXISTS in EXPLAIN consistent
with the non-EXPLAIN'd DDL queries, preventing a failure with IF NOT
EXISTS if the relation to-be-created already exists.  The skip is done
before the SELECT query used for the relation is planned or executed,
and a "dummy" plan is generated instead depending on the format used by
EXPLAIN.

Author: Bharath Rupireddy
Reviewed-by: Zhijie Hou, Michael Paquier
Discussion: https://postgr.es/m/CALj2ACVa3oJ9O_wcGd+FtHWZds04dEKcakxphGz5POVgD4wC7Q@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e665769e6d1e84b6650f53ed297058fc11152f7f

Modified Files
--------------
src/backend/commands/createas.c           | 53 ++++++++++++++++++++++---------
src/backend/commands/explain.c            | 16 ++++++++++
src/include/commands/createas.h           |  2 ++
src/test/regress/expected/matview.out     | 38 ++++++++++++++++++++++
src/test/regress/expected/select_into.out | 42 ++++++++++++++++++++++++
src/test/regress/sql/matview.sql          | 23 ++++++++++++++
src/test/regress/sql/select_into.sql      | 21 ++++++++++++
7 files changed, 180 insertions(+), 15 deletions(-)



Message-ID: <E1kuaX7-0000Q9-MT@gemulon.postgresql.org>
Permalink:  ../E1kuaX7-0000Q9-MT@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kuaX7-0000Q9-MT@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: michael@paquier.xyz
  Subject: Re: pgsql: Sanitize IF NOT EXISTS in EXPLAIN for CTAS and matviews
  In-Reply-To: <E1kuaX7-0000Q9-MT@gemulon.postgresql.org>
  References: <E1kuaX7-0000Q9-MT@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