diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AlterTableClauseVisitor.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AlterTableClauseVisitor.java index c2d54655b9e5a..4ac4ad33fc6f9 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AlterTableClauseVisitor.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AlterTableClauseVisitor.java @@ -352,6 +352,11 @@ public Void visitOptimizeClause(OptimizeClause clause, ConnectContext context) { ErrorReport.reportSemanticException(ErrorCode.ERR_COMMON_ERROR, "Optimize materialized view is not supported"); } + if (olapTable.getAutomaticBucketSize() > 0) { + ErrorReport.reportSemanticException(ErrorCode.ERR_COMMON_ERROR, + "Random distribution table already supports automatic scaling and does not require optimization"); + } + List sortKeyIdxes = Lists.newArrayList(); List columnDefs = olapTable.getColumns().stream().map(Column::toColumnDef).collect(Collectors.toList()); if (clause.getSortKeys() != null) { diff --git a/test/sql/test_optimize_table/R/test_optimize_table b/test/sql/test_optimize_table/R/test_optimize_table index c89f593cdf951..b8d1d5edbc1c5 100644 --- a/test/sql/test_optimize_table/R/test_optimize_table +++ b/test/sql/test_optimize_table/R/test_optimize_table @@ -72,6 +72,15 @@ function: wait_optimize_table_finish() None -- !result +-- name: test_disable_random +create table t(k int); +-- result: +-- !result +alter table t distributed by random buckets 10; +-- result: +E: (5064, 'Getting analyzing error. Detail message: Random distribution table already supports automatic scaling and does not require optimization.') +-- !result + diff --git a/test/sql/test_optimize_table/T/test_optimize_table b/test/sql/test_optimize_table/T/test_optimize_table index c11c2ba69eb9d..ef64db5d54009 100644 --- a/test/sql/test_optimize_table/T/test_optimize_table +++ b/test/sql/test_optimize_table/T/test_optimize_table @@ -1,3 +1,7 @@ +-- name: test_disable_random +create table t(k int); +alter table t distributed by random buckets 10; + -- name: test_optimize_table create table t(k int) distributed by hash(k) buckets 10; show partitions from t;