Обсуждение: pgsql: Clone extended stats in CREATE TABLE (LIKE INCLUDING ALL)

Поиск
Список
Период
Сортировка

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

От
Alvaro Herrera
Дата:
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(-)


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

От
Thomas Munro
Дата:
On Tue, Mar 6, 2018 at 11:39 AM, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
> Clone extended stats in CREATE TABLE (LIKE INCLUDING ALL)

Is this commit responsible for this valgrind error?

https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lousyjack&dt=2018-03-05%2023%3A03%3A01

==430== Invalid read of size 2
==430==    at 0x4C33F6F: memcpy@GLIBC_2.2.5 (vg_replace_strmem.c:1021)
==430==    by 0x483419: heap_fill_tuple (heaptuple.c:276)
==430==    by 0x4842C6: heap_form_tuple (heaptuple.c:771)
==430==    by 0x6474B5: CreateStatistics (statscmds.c:322)
==430==    by 0x865784: ProcessUtilitySlow (utility.c:1668)
==430==    by 0x8642A2: standard_ProcessUtility (utility.c:935)
==430==    by 0x863347: ProcessUtility (utility.c:358)
==430==    by 0x862498: PortalRunUtility (pquery.c:1178)
==430==    by 0x86268F: PortalRunMulti (pquery.c:1324)
==430==    by 0x861BFD: PortalRun (pquery.c:799)
==430==    by 0x85B947: exec_simple_query (postgres.c:1120)
==430==    by 0x85FEE6: PostgresMain (postgres.c:4144)
==430==    by 0x7CA783: BackendRun (postmaster.c:4412)
==430==    by 0x7C9E6D: BackendStartup (postmaster.c:4084)
==430==    by 0x7C635B: ServerLoop (postmaster.c:1757)
==430==    by 0x7C58F0: PostmasterMain (postmaster.c:1365)
==430==    by 0x702B56: main (main.c:228)
==430==  Address 0x994d5ce is 14 bytes inside a block of size 15 client-defined
==430==    at 0x9FA33A: palloc (mcxt.c:858)
==430==    by 0x5EBE0C: downcase_identifier (scansup.c:146)
==430==    by 0x5EBDE3: downcase_truncate_identifier (scansup.c:133)
==430==    by 0x5B6E51: core_yylex (scan.l:1000)
==430==    by 0x5B9F65: base_yylex (parser.c:101)
==430==    by 0x589F45: base_yyparse (gram.c:24973)
==430==    by 0x5B9EBF: raw_parser (parser.c:53)
==430==    by 0x85B112: pg_parse_query (postgres.c:616)
==430==    by 0x85B5C1: exec_simple_query (postgres.c:942)
==430==    by 0x85FEE6: PostgresMain (postgres.c:4144)
==430==    by 0x7CA783: BackendRun (postmaster.c:4412)
==430==    by 0x7C9E6D: BackendStartup (postmaster.c:4084)
==430==    by 0x7C635B: ServerLoop (postmaster.c:1757)
==430==    by 0x7C58F0: PostmasterMain (postmaster.c:1365)
==430==    by 0x702B56: main (main.c:228)
==430==

-- 
Thomas Munro
http://www.enterprisedb.com