Merge pull request #70253 from ClickHouse/backport/24.9/70144

Backport #70144 to 24.9: Fix possible hung in ALTER COLUMN with Dynamic type
This commit is contained in:
robot-clickhouse-ci-2 2024-10-02 03:29:53 +02:00 committed by GitHub
commit 566db64394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 6 deletions

View File

@ -513,12 +513,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());
}
}
}
@ -1362,6 +1356,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);

View File

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