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; -