mirror of
https://github.com/postgres/postgres.git
synced 2025-07-20 05:03:10 +03:00
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
This commit is contained in:
@ -137,6 +137,8 @@ DROP TABLE inhz;
|
||||
CREATE TABLE ctlt1 (a text CHECK (length(a) > 2) PRIMARY KEY, b text);
|
||||
CREATE INDEX ctlt1_b_key ON ctlt1 (b);
|
||||
CREATE INDEX ctlt1_fnidx ON ctlt1 ((a || b));
|
||||
CREATE STATISTICS ctlt1_a_b_stat ON a,b FROM ctlt1;
|
||||
COMMENT ON STATISTICS ctlt1_a_b_stat IS 'ab stats';
|
||||
COMMENT ON COLUMN ctlt1.a IS 'A';
|
||||
COMMENT ON COLUMN ctlt1.b IS 'B';
|
||||
COMMENT ON CONSTRAINT ctlt1_a_check ON ctlt1 IS 't1_a_check';
|
||||
@ -240,6 +242,8 @@ Indexes:
|
||||
"ctlt_all_expr_idx" btree ((a || b))
|
||||
Check constraints:
|
||||
"ctlt1_a_check" CHECK (length(a) > 2)
|
||||
Statistics objects:
|
||||
"public"."ctlt_all_a_b_stat" (ndistinct, dependencies) ON a, b FROM ctlt_all
|
||||
|
||||
SELECT c.relname, objsubid, description FROM pg_description, pg_index i, pg_class c WHERE classoid = 'pg_class'::regclass AND objoid = i.indexrelid AND c.oid = i.indexrelid AND i.indrelid = 'ctlt_all'::regclass ORDER BY c.relname, objsubid;
|
||||
relname | objsubid | description
|
||||
@ -248,6 +252,12 @@ SELECT c.relname, objsubid, description FROM pg_description, pg_index i, pg_clas
|
||||
ctlt_all_pkey | 0 | index pkey
|
||||
(2 rows)
|
||||
|
||||
SELECT s.stxname, objsubid, description FROM pg_description, pg_statistic_ext s WHERE classoid = 'pg_statistic_ext'::regclass AND objoid = s.oid AND s.stxrelid = 'ctlt_all'::regclass ORDER BY s.stxname, objsubid;
|
||||
stxname | objsubid | description
|
||||
-------------------+----------+-------------
|
||||
ctlt_all_a_b_stat | 0 | ab stats
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE inh_error1 () INHERITS (ctlt1, ctlt4);
|
||||
NOTICE: merging multiple inherited definitions of column "a"
|
||||
ERROR: inherited column "a" has a storage parameter conflict
|
||||
|
@ -71,6 +71,8 @@ DROP TABLE inhz;
|
||||
CREATE TABLE ctlt1 (a text CHECK (length(a) > 2) PRIMARY KEY, b text);
|
||||
CREATE INDEX ctlt1_b_key ON ctlt1 (b);
|
||||
CREATE INDEX ctlt1_fnidx ON ctlt1 ((a || b));
|
||||
CREATE STATISTICS ctlt1_a_b_stat ON a,b FROM ctlt1;
|
||||
COMMENT ON STATISTICS ctlt1_a_b_stat IS 'ab stats';
|
||||
COMMENT ON COLUMN ctlt1.a IS 'A';
|
||||
COMMENT ON COLUMN ctlt1.b IS 'B';
|
||||
COMMENT ON CONSTRAINT ctlt1_a_check ON ctlt1 IS 't1_a_check';
|
||||
@ -108,6 +110,7 @@ SELECT description FROM pg_description, pg_constraint c WHERE classoid = 'pg_con
|
||||
CREATE TABLE ctlt_all (LIKE ctlt1 INCLUDING ALL);
|
||||
\d+ ctlt_all
|
||||
SELECT c.relname, objsubid, description FROM pg_description, pg_index i, pg_class c WHERE classoid = 'pg_class'::regclass AND objoid = i.indexrelid AND c.oid = i.indexrelid AND i.indrelid = 'ctlt_all'::regclass ORDER BY c.relname, objsubid;
|
||||
SELECT s.stxname, objsubid, description FROM pg_description, pg_statistic_ext s WHERE classoid = 'pg_statistic_ext'::regclass AND objoid = s.oid AND s.stxrelid = 'ctlt_all'::regclass ORDER BY s.stxname, objsubid;
|
||||
|
||||
CREATE TABLE inh_error1 () INHERITS (ctlt1, ctlt4);
|
||||
CREATE TABLE inh_error2 (LIKE ctlt4 INCLUDING STORAGE) INHERITS (ctlt1);
|
||||
|
Reference in New Issue
Block a user