PG16 - Throw meaningful error for stats without a name on Citus tables (#7136)

Relevant PG commit:
624aa2a13b
624aa2a13bd02dd584bb0995c883b5b93b2152df
pull/7139/head
Naisila Puka 2023-08-23 10:25:01 +03:00 committed by GitHub
parent 371f094b68
commit 36b51d617c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -77,6 +77,14 @@ PreprocessCreateStatisticsStmt(Node *node, const char *queryString,
EnsureCoordinator();
if (!(stmt->defnames))
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot create statistics without a name on a "
"Citus table"),
errhint("Consider specifying a name for the statistics")));
}
QualifyTreeNode((Node *) stmt);
Oid statsOid = get_statistics_object_oid(stmt->defnames, true);

View File

@ -65,6 +65,28 @@ SET citus.log_remote_commands TO OFF;
-- only verifying it works and not printing log
-- remote commands because it can be flaky
VACUUM (ONLY_DATABASE_STATS);
-- Proper error when creating statistics without a name on a Citus table
-- Relevant PG commit:
-- https://github.com/postgres/postgres/commit/624aa2a13bd02dd584bb0995c883b5b93b2152df
CREATE TABLE test_stats (
a int,
b int
);
SELECT create_distributed_table('test_stats', 'a');
create_distributed_table
---------------------------------------------------------------------
(1 row)
CREATE STATISTICS (dependencies) ON a, b FROM test_stats;
ERROR: cannot create statistics without a name on a Citus table
HINT: Consider specifying a name for the statistics
CREATE STATISTICS (ndistinct, dependencies) on a, b from test_stats;
ERROR: cannot create statistics without a name on a Citus table
HINT: Consider specifying a name for the statistics
CREATE STATISTICS (ndistinct, dependencies, mcv) on a, b from test_stats;
ERROR: cannot create statistics without a name on a Citus table
HINT: Consider specifying a name for the statistics
\set VERBOSITY terse
SET client_min_messages TO ERROR;
DROP SCHEMA pg16 CASCADE;

View File

@ -45,6 +45,21 @@ SET citus.log_remote_commands TO OFF;
-- remote commands because it can be flaky
VACUUM (ONLY_DATABASE_STATS);
-- Proper error when creating statistics without a name on a Citus table
-- Relevant PG commit:
-- https://github.com/postgres/postgres/commit/624aa2a13bd02dd584bb0995c883b5b93b2152df
CREATE TABLE test_stats (
a int,
b int
);
SELECT create_distributed_table('test_stats', 'a');
CREATE STATISTICS (dependencies) ON a, b FROM test_stats;
CREATE STATISTICS (ndistinct, dependencies) on a, b from test_stats;
CREATE STATISTICS (ndistinct, dependencies, mcv) on a, b from test_stats;
\set VERBOSITY terse
SET client_min_messages TO ERROR;
DROP SCHEMA pg16 CASCADE;