pgsql: Clone extended stats in CREATE TABLE (LIKE INCLUDING ALL)

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Clone extended stats in CREATE TABLE (LIKE INCLUDING ALL)
Date: 2018-03-05 22:39:01
Message-ID: E1esyl3-0001qV-OW@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Clone extended stats in CREATE TABLE (LIKE INCLUDING ALL)

The LIKE INCLUDING ALL clause to CREATE TABLE intuitively indicates
cloning of extended statistics on the source table, but it failed to do
so. Patch it up so that it does. Also include an INCLUDING STATISTICS
option to the LIKE clause, so that the behavior can be requested
individually, or excluded individually.

While at it, reorder the INCLUDING options, both in code and in docs, in
alphabetical order which makes more sense than feature-implementation
order that was previously used.

Backpatch this to Postgres 10, where extended statistics were
introduced, because this is seen as an oversight in a fresh feature
which is better to get consistent from the get-go instead of changing
only in pg11.

In pg11, comments on statistics objects are cloned too. In pg10 they
are not, because I (Álvaro) was too coward to change the parse node as
required to support it. Also, in pg10 I chose not to renumber the
parser symbols for the various INCLUDING options in LIKE, for the same
reason. Any corresponding user-visible changes (docs) are backpatched,
though.

Reported-by: Stephen Froehlich
Author: David Rowley
Reviewed-by: Álvaro Herrera, Tomas Vondra
Discussion: https://postgr.es/m/CY1PR0601MB1927315B45667A1B679D0FD5E5EF0@CY1PR0601MB1927.namprd06.prod.outlook.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5564c11815486bdfe87eb46ebc7c070293fa6956

Modified Files
--------------
doc/src/sgml/ref/create_table.sgml | 8 +-
src/backend/commands/indexcmds.c | 5 +-
src/backend/commands/statscmds.c | 169 ++++++++++++++++++++----
src/backend/nodes/copyfuncs.c | 1 +
src/backend/nodes/equalfuncs.c | 1 +
src/backend/nodes/outfuncs.c | 1 +
src/backend/parser/gram.y | 7 +-
src/backend/parser/parse_utilcmd.c | 143 ++++++++++++++++++++
src/include/nodes/parsenodes.h | 12 +-
src/test/regress/expected/create_table_like.out | 10 ++
src/test/regress/sql/create_table_like.sql | 3 +
11 files changed, 323 insertions(+), 37 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2018-03-05 23:30:25 pgsql: Fix HEAP_INSERT_IS_SPECULATIVE to HEAP_INSERT_SPECULATIVE in com
Previous Message Tom Lane 2018-03-05 21:20:11 pgsql: Temporarily instrument postgres_fdw test to look for statistics

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2018-03-05 22:43:20 Re: STATISTICS retained in CREATE TABLE ... LIKE (INCLUDING ALL)?
Previous Message Alexander Korotkov 2018-03-05 22:31:23 Re: [HACKERS] GUC for cleanup indexes threshold.