Re: STATISTICS retained in CREATE TABLE ... LIKE (INCLUDING ALL)?

From: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stephen Froehlich <s(dot)froehlich(at)cablelabs(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Subject: Re: STATISTICS retained in CREATE TABLE ... LIKE (INCLUDING ALL)?
Date: 2018-01-26 07:30:52
Message-ID: CAKJS1f9pL8+v4LDGiePWrUqkLHqvek5L54wW=Ba1fMKz8o0Pag@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice

On 21 January 2018 at 19:21, David Rowley <david(dot)rowley(at)2ndquadrant(dot)com> wrote:
> On 20 January 2018 at 18:50, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Stephen Froehlich <s(dot)froehlich(at)cablelabs(dot)com> writes:
>>> Are custom statistics in PG10 retained in LIKE (INCLUDING ALL) or do I need to recreate the statistics by hand each time I create a new table?
>>
>> LIKE doesn't know about those, no. Perhaps it should.
>
> Agreed. ALL does not mean MOST.

(Moving to -hackers)

The attached implements this.

Looking at "LIKE ALL" in more detail in the docs it claims to be
equivalent to "INCLUDING DEFAULTS INCLUDING IDENTITY INCLUDING
CONSTRAINTS INCLUDING INDEXES INCLUDING STORAGE INCLUDING COMMENTS",
so it didn't seem right to magically have LIKE ALL include something
that there's no option to include individually, so I added INCLUDING
STATISTICS.

This also required writing code allow statistics to be created without
a name. The code I added to choose the default name is in the form
<tablename>_<column1>_<column2>_stat. I'm sure someone will want
something else, but that's just what I've personally standardised on.
I'd also be fine with "stx" or "sta". Making this work required a bit
of shuffling of error checking in CreateStatistics() so that we
generate a name before complaining about any duplicate name.

I'm unsure if this should be categorised as a bug fix or a new feature.

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
create_table_like_statistics_v1.patch application/octet-stream 19.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Konstantin Knizhnik 2018-01-26 07:44:24 Re: JIT compiling with LLVM v9.0
Previous Message Amit Kapila 2018-01-26 07:06:14 Re: [HACKERS] Parallel tuplesort (for parallel B-Tree index creation)

Browse pgsql-novice by date

  From Date Subject
Next Message Tels 2018-01-26 11:03:08 Re: STATISTICS retained in CREATE TABLE ... LIKE (INCLUDING ALL)?
Previous Message ferraresso@tin.it 2018-01-23 13:03:08 R: Re: R: Re: create subscription, connection string, password in log not hide