Don't allow to drop or rename version column

This commit is contained in:
alesapin 2021-02-10 22:23:48 +03:00
parent 420f2958e2
commit 891fce3275
3 changed files with 46 additions and 7 deletions

View File

@ -1490,8 +1490,10 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, const S
getPartitionIDFromQuery(command.partition, global_context);
}
if (command.column_name == merging_params.version_column)
{
/// Some type changes for version column is allowed despite it's a part of sorting key
if (command.type == AlterCommand::MODIFY_COLUMN && command.column_name == merging_params.version_column)
if (command.type == AlterCommand::MODIFY_COLUMN)
{
const IDataType * new_type = command.data_type.get();
const IDataType * old_type = old_types[command.column_name];
@ -1501,6 +1503,19 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, const S
/// No other checks required
continue;
}
else if (command.type == AlterCommand::DROP_COLUMN)
{
throw Exception(
"Trying to ALTER DROP version " + backQuoteIfNeed(command.column_name) + " column",
ErrorCodes::ALTER_OF_COLUMN_IS_FORBIDDEN);
}
else if (command.type == AlterCommand::RENAME_COLUMN)
{
throw Exception(
"Trying to ALTER RENAME version " + backQuoteIfNeed(command.column_name) + " column",
ErrorCodes::ALTER_OF_COLUMN_IS_FORBIDDEN);
}
}
if (command.type == AlterCommand::MODIFY_ORDER_BY && !is_custom_partitioned)
{

View File

@ -0,0 +1 @@
1 1 1

View File

@ -0,0 +1,23 @@
DROP TABLE IF EXISTS alter_drop_version;
CREATE TABLE alter_drop_version
(
`key` UInt64,
`value` String,
`ver` Int8
)
ENGINE = ReplacingMergeTree(ver)
ORDER BY key;
INSERT INTO alter_drop_version VALUES (1, '1', 1);
ALTER TABLE alter_drop_version DROP COLUMN ver; --{serverError 524}
ALTER TABLE alter_drop_version RENAME COLUMN ver TO rev; --{serverError 524}
DETACH TABLE alter_drop_version;
ATTACH TABLE alter_drop_version;
SELECT * FROM alter_drop_version;
DROP TABLE IF EXISTS alter_drop_version;