Backport #70144 to 24.8: Fix possible hung in ALTER COLUMN with Dynamic type

This commit is contained in:
robot-clickhouse 2024-10-01 22:27:09 +00:00
parent a933c92173
commit e8651ec0f4
3 changed files with 22 additions and 6 deletions

View File

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

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;