pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Andreas Karlsson <andreas@proxel.se>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTE query;
Date: Mon, 18 Feb 2019 08:49:50 +0900
Message-ID: <20190217234950.GC1864@paquier.xyz> (raw)
In-Reply-To: <a349376e-a135-e4a4-818e-41e4c605c80a@proxel.se>
References: <2ddcc188-e37c-a0be-32bf-a56b07c3559e@proxel.se>
	<20190206114912.GE14980@paquier.xyz>
	<2c6f2b5b-a673-fd1c-ad9c-1c7676cee7d6@proxel.se>
	<20190207013135.GD4074@paquier.xyz>
	<20190211125359.GB3981@paquier.xyz>
	<20190215081451.GD2240@paquier.xyz>
	<a349376e-a135-e4a4-818e-41e4c605c80a@proxel.se>

On Sun, Feb 17, 2019 at 03:31:05PM +0100, Andreas Karlsson wrote:
> Yeah, noticed the same thing myself while refactoring the CTAS code, but I
> guess the output could be like the current output for "EXPLAIN ANALYZE
> <CTAS> WITH NO DATA;", i.e. a top plan with "(never executed)" (see below
> for an example).

Yes, that matches my ideas on the matter (when excluding some
partitions at execution time for pruning something similar is used),
except that I would have used "(never executed as relation exists)" or
similar so as it is possible to make the difference between a relation
not created and no data inserted if using a CTAS IF NOT EXISTS with NO
DATA.

> The main thing which bothers me right now about my refactoring is how
> different the code paths for CTAS and EXPLAIN ANALYZE CTAS are, which leads
> to weirdness like this. I wonder if we cannot make them share more code e.g.
> by having ExplainOneUtility() call into some function in createas.c.

I think that we are on the same page here.  The code path creating the
CTAS relation includes the if_not_exists check which should be used by
EXPLAIN, EXECUTE and normal CTAS, and return an ObjectAddress maybe
invalid if the relation has not been created.  I have not looked in
details, but it seems that we would need to pass down if_not_exists to
the IntoClause.

> Maybe I should give it a shot and then start a new thread for the
> refactoring once I have looked more into this.

Thanks!  That's not something which would get back-patched, and the
new APIs can be designed more carefully.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (10+ messages)  latest in thread

Message-ID: <20190217234950.GC1864@paquier.xyz>
Permalink:  ../20190217234950.GC1864@paquier.xyz/
Also on:    postgresql.org/message-id/20190217234950.GC1864@paquier.xyz

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: michael@paquier.xyz, andreas@proxel.se, pgsql-hackers@lists.postgresql.org
  Subject: Re: Add missing CREATE TABLE IF NOT EXISTS table_name AS EXECUTE query;
  In-Reply-To: <20190217234950.GC1864@paquier.xyz>

* 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