From 1ff7186d20cd9e11128b1e0548646ad5ed719117 Mon Sep 17 00:00:00 2001 From: Ahmet Gedemenli Date: Wed, 1 Sep 2021 12:15:13 +0300 Subject: [PATCH] Extended statistics on expressions - PG14 a4d75c8 (#5224) (cherry picked from commit 1268415f123b5d99cfacfe207c8670240efc1c00) --- .../deparser/deparse_statistics_stmts.c | 8 ++++++++ src/test/regress/expected/pg14.out | 14 ++++++++++++++ src/test/regress/sql/pg14.sql | 9 ++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/deparser/deparse_statistics_stmts.c b/src/backend/distributed/deparser/deparse_statistics_stmts.c index e6f8fc262..732341c28 100644 --- a/src/backend/distributed/deparser/deparse_statistics_stmts.c +++ b/src/backend/distributed/deparser/deparse_statistics_stmts.c @@ -241,6 +241,14 @@ AppendColumnNames(StringInfo buf, CreateStatsStmt *stmt) foreach_ptr(column, stmt->exprs) { + if (!column->name) + { + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg( + "only simple column references are allowed in CREATE STATISTICS"))); + } + const char *columnName = quote_identifier(column->name); appendStringInfoString(buf, columnName); diff --git a/src/test/regress/expected/pg14.out b/src/test/regress/expected/pg14.out index 8c820cbab..2d7dd89c1 100644 --- a/src/test/regress/expected/pg14.out +++ b/src/test/regress/expected/pg14.out @@ -142,6 +142,20 @@ DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx -- should error saying table space doesn't exist reindex(TABLESPACE test_tablespace1) index idx; ERROR: tablespace "test_tablespace1" does not exist +reset citus.log_remote_commands; +-- CREATE STATISTICS only allow simple column references +CREATE TABLE tbl1(a timestamp, b int); +SELECT create_distributed_table('tbl1','a'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +-- the last one should error out +CREATE STATISTICS s1 (dependencies) ON a, b FROM tbl1; +CREATE STATISTICS s2 (mcv) ON a, b FROM tbl1; +CREATE STATISTICS s3 (ndistinct) ON date_trunc('month', a), date_trunc('day', a) FROM tbl1; +ERROR: only simple column references are allowed in CREATE STATISTICS set citus.log_remote_commands to off; -- error out in case of ALTER TABLE .. DETACH PARTITION .. CONCURRENTLY/FINALIZE -- only if it's a distributed partitioned table diff --git a/src/test/regress/sql/pg14.sql b/src/test/regress/sql/pg14.sql index 12efe99b9..66c39482f 100644 --- a/src/test/regress/sql/pg14.sql +++ b/src/test/regress/sql/pg14.sql @@ -37,6 +37,14 @@ reindex(TABLESPACE test_tablespace, verbose false) index idx ; reindex(verbose, TABLESPACE test_tablespace) index idx ; -- should error saying table space doesn't exist reindex(TABLESPACE test_tablespace1) index idx; +reset citus.log_remote_commands; +-- CREATE STATISTICS only allow simple column references +CREATE TABLE tbl1(a timestamp, b int); +SELECT create_distributed_table('tbl1','a'); +-- the last one should error out +CREATE STATISTICS s1 (dependencies) ON a, b FROM tbl1; +CREATE STATISTICS s2 (mcv) ON a, b FROM tbl1; +CREATE STATISTICS s3 (ndistinct) ON date_trunc('month', a), date_trunc('day', a) FROM tbl1; set citus.log_remote_commands to off; -- error out in case of ALTER TABLE .. DETACH PARTITION .. CONCURRENTLY/FINALIZE @@ -73,4 +81,3 @@ SELECT attname || ' ' || attcompression FROM pg_attribute WHERE attrelid::regcla set client_min_messages to error; drop schema pg14 cascade; -