From e8651ec0f4c3114c68a669d3785f621610b5c807 Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Tue, 1 Oct 2024 22:27:09 +0000 Subject: [PATCH] Backport #70144 to 24.8: Fix possible hung in ALTER COLUMN with Dynamic type --- src/Interpreters/MutationsInterpreter.cpp | 21 +++++++++++++------ .../03246_alter_update_dynamic_hung.reference | 0 .../03246_alter_update_dynamic_hung.sql | 7 +++++++ 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 tests/queries/0_stateless/03246_alter_update_dynamic_hung.reference create mode 100644 tests/queries/0_stateless/03246_alter_update_dynamic_hung.sql diff --git a/src/Interpreters/MutationsInterpreter.cpp b/src/Interpreters/MutationsInterpreter.cpp index 0b93b5989b1..58e9c469568 100644 --- a/src/Interpreters/MutationsInterpreter.cpp +++ b/src/Interpreters/MutationsInterpreter.cpp @@ -500,12 +500,6 @@ static void validateUpdateColumns( throw Exception(ErrorCodes::NO_SUCH_COLUMN_IN_TABLE, "There is no column {} in table", backQuote(column_name)); } } - else if (storage_columns.getColumn(GetColumnsOptions::Ordinary, column_name).type->hasDynamicSubcolumns()) - { - throw Exception(ErrorCodes::CANNOT_UPDATE_COLUMN, - "Cannot update column {} with type {}: updates of columns with dynamic subcolumns are not supported", - backQuote(column_name), storage_columns.getColumn(GetColumnsOptions::Ordinary, column_name).type->getName()); - } } } @@ -1340,6 +1334,21 @@ void MutationsInterpreter::validate() } } + const auto & storage_columns = source.getStorageSnapshot(metadata_snapshot, context)->metadata->getColumns(); + for (const auto & command : commands) + { + for (const auto & [column_name, _] : command.column_to_update_expression) + { + auto column = storage_columns.tryGetColumn(GetColumnsOptions::Ordinary, column_name); + if (column && column->type->hasDynamicSubcolumns()) + { + throw Exception(ErrorCodes::CANNOT_UPDATE_COLUMN, + "Cannot update column {} with type {}: updates of columns with dynamic subcolumns are not supported", + backQuote(column_name), storage_columns.getColumn(GetColumnsOptions::Ordinary, column_name).type->getName()); + } + } + } + QueryPlan plan; initQueryPlan(stages.front(), plan); diff --git a/tests/queries/0_stateless/03246_alter_update_dynamic_hung.reference b/tests/queries/0_stateless/03246_alter_update_dynamic_hung.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/03246_alter_update_dynamic_hung.sql b/tests/queries/0_stateless/03246_alter_update_dynamic_hung.sql new file mode 100644 index 00000000000..e3bf7bb5a37 --- /dev/null +++ b/tests/queries/0_stateless/03246_alter_update_dynamic_hung.sql @@ -0,0 +1,7 @@ +SET allow_experimental_dynamic_type = 1; +DROP TABLE IF EXISTS t0; +CREATE TABLE t0 (c0 Int) ENGINE = MergeTree() ORDER BY tuple(); +INSERT INTO t0 (c0) VALUES (1); +ALTER TABLE t0 UPDATE c0 = EXISTS (SELECT 1 FROM t1 CROSS JOIN t0) WHERE 1; +ALTER TABLE t0 MODIFY COLUMN c0 Dynamic; --{serverError UNFINISHED} +DROP TABLE t0;