From 111c04c2bdf3c0e83f33e05aa90a8a0a22e8bf63 Mon Sep 17 00:00:00 2001 From: metdos Date: Fri, 10 Nov 2017 10:59:47 +0200 Subject: [PATCH] Warn on CLUSTER command for distributed tables --- .../distributed/executor/multi_utility.c | 31 +++++++++++++++++++ .../expected/multi_index_statements.out | 9 +++++- .../regress/sql/multi_index_statements.sql | 10 +++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/executor/multi_utility.c b/src/backend/distributed/executor/multi_utility.c index b952ab403..5604bba07 100644 --- a/src/backend/distributed/executor/multi_utility.c +++ b/src/backend/distributed/executor/multi_utility.c @@ -568,6 +568,37 @@ multi_ProcessUtility(PlannedStmt *pstmt, ProcessVacuumStmt(vacuumStmt, queryString); } + /* warn for CLUSTER command on distributed tables */ + if (IsA(parsetree, ClusterStmt)) + { + ClusterStmt *clusterStmt = (ClusterStmt *) parsetree; + bool showPropagationWarning = false; + + /* CLUSTER all */ + if (clusterStmt->relation == NULL) + { + showPropagationWarning = true; + } + else + { + Oid relationId = InvalidOid; + bool missingOK = false; + + relationId = RangeVarGetRelid(clusterStmt->relation, AccessShareLock, + missingOK); + + if (OidIsValid(relationId)) + { + showPropagationWarning = IsDistributedTable(relationId); + } + } + + if (showPropagationWarning) + { + ereport(WARNING, (errmsg("not propagating CLUSTER command to worker nodes"))); + } + } + /* * Ensure value is valid, we can't do some checks during CREATE * EXTENSION. This is important to register some invalidation callbacks. diff --git a/src/test/regress/expected/multi_index_statements.out b/src/test/regress/expected/multi_index_statements.out index cc2ac53bf..0adf8e33b 100644 --- a/src/test/regress/expected/multi_index_statements.out +++ b/src/test/regress/expected/multi_index_statements.out @@ -92,9 +92,16 @@ CREATE INDEX IF NOT EXISTS lineitem_orderkey_index on index_test_hash(a); NOTICE: relation "lineitem_orderkey_index" already exists, skipping -- Verify that we can create indexes concurrently CREATE INDEX CONCURRENTLY lineitem_concurrently_index ON lineitem (l_orderkey); +-- Verify that we warn out on CLUSTER command for distributed tables and no parameter +CLUSTER index_test_hash USING index_test_hash_index_a; +WARNING: not propagating CLUSTER command to worker nodes +CLUSTER; +WARNING: not propagating CLUSTER command to worker nodes -- Verify that no-name local CREATE INDEX CONCURRENTLY works CREATE TABLE local_table (id integer, name text); -CREATE INDEX CONCURRENTLY ON local_table(id); +CREATE INDEX CONCURRENTLY local_table_index ON local_table(id); +-- Vefify we don't warn out on CLUSTER command for local tables +CLUSTER local_table USING local_table_index; DROP TABLE local_table; -- Verify that all indexes got created on the master node and one of the workers SELECT * FROM pg_indexes WHERE tablename = 'lineitem' or tablename like 'index_test_%' ORDER BY indexname; diff --git a/src/test/regress/sql/multi_index_statements.sql b/src/test/regress/sql/multi_index_statements.sql index df5a1647f..65c6ecc7e 100644 --- a/src/test/regress/sql/multi_index_statements.sql +++ b/src/test/regress/sql/multi_index_statements.sql @@ -66,9 +66,17 @@ CREATE INDEX IF NOT EXISTS lineitem_orderkey_index on index_test_hash(a); -- Verify that we can create indexes concurrently CREATE INDEX CONCURRENTLY lineitem_concurrently_index ON lineitem (l_orderkey); +-- Verify that we warn out on CLUSTER command for distributed tables and no parameter +CLUSTER index_test_hash USING index_test_hash_index_a; +CLUSTER; + -- Verify that no-name local CREATE INDEX CONCURRENTLY works CREATE TABLE local_table (id integer, name text); -CREATE INDEX CONCURRENTLY ON local_table(id); +CREATE INDEX CONCURRENTLY local_table_index ON local_table(id); + +-- Vefify we don't warn out on CLUSTER command for local tables +CLUSTER local_table USING local_table_index; + DROP TABLE local_table; -- Verify that all indexes got created on the master node and one of the workers