Fix alter modify for decimal columns when type size doesn't change

This commit is contained in:
alesapin 2021-03-15 11:22:15 +03:00
parent afa24938bc
commit 69b8ded578
3 changed files with 75 additions and 39 deletions

View File

@ -907,7 +907,6 @@ void StorageReplicatedMergeTree::setTableStructure(
StorageInMemoryMetadata new_metadata = getInMemoryMetadata();
StorageInMemoryMetadata old_metadata = getInMemoryMetadata();
if (new_columns != new_metadata.columns)
new_metadata.columns = new_columns;
if (!metadata_diff.empty())
@ -976,8 +975,6 @@ void StorageReplicatedMergeTree::setTableStructure(
}
/// Changes in columns may affect following metadata fields
if (new_metadata.columns != old_metadata.columns)
{
new_metadata.column_ttls_by_name.clear();
for (const auto & [name, ast] : new_metadata.columns.getColumnTTLs())
{
@ -1014,7 +1011,6 @@ void StorageReplicatedMergeTree::setTableStructure(
if (!metadata_diff.ttl_table_changed && new_metadata.table_ttl.definition_ast != nullptr)
new_metadata.table_ttl = TTLTableDescription::getTTLForTableFromAST(
new_metadata.table_ttl.definition_ast, new_metadata.columns, global_context, new_metadata.primary_key);
}
/// Even if the primary/sorting/partition keys didn't change we must reinitialize it
/// because primary/partition key column types might have changed.

View File

@ -0,0 +1,9 @@
1 5.00000000
2 6.00000000
CREATE TABLE default.test_alter_decimal\n(\n `n` UInt64,\n `d` Decimal(18, 8)\n)\nENGINE = ReplicatedMergeTree(\'/clickhouse/01761_alter_decimal_zookeeper\', \'r1\')\nORDER BY tuple()\nSETTINGS index_granularity = 8192
1 5.00000000
2 6.00000000
CREATE TABLE default.test_alter_decimal\n(\n `n` UInt64,\n `d` Decimal(18, 8)\n)\nENGINE = ReplicatedMergeTree(\'/clickhouse/01761_alter_decimal_zookeeper\', \'r1\')\nORDER BY tuple()\nSETTINGS index_granularity = 8192
1 5.00000000
2 6.00000000
3 7.00000000

View File

@ -0,0 +1,31 @@
DROP TABLE IF EXISTS test_alter_decimal;
CREATE TABLE test_alter_decimal
(n UInt64, d Decimal(15, 8))
ENGINE = ReplicatedMergeTree('/clickhouse/01761_alter_decimal_zookeeper', 'r1')
ORDER BY tuple();
INSERT INTO test_alter_decimal VALUES (1, toDecimal32(5, 5));
INSERT INTO test_alter_decimal VALUES (2, toDecimal32(6, 6));
SELECT * FROM test_alter_decimal ORDER BY n;
ALTER TABLE test_alter_decimal MODIFY COLUMN d Decimal(18, 8);
SHOW CREATE TABLE test_alter_decimal;
SELECT * FROM test_alter_decimal ORDER BY n;
DETACH TABLE test_alter_decimal;
ATTACH TABLE test_alter_decimal;
SHOW CREATE TABLE test_alter_decimal;
INSERT INTO test_alter_decimal VALUES (3, toDecimal32(7, 7));
OPTIMIZE TABLE test_alter_decimal FINAL;
SELECT * FROM test_alter_decimal ORDER BY n;
DROP TABLE IF EXISTS test_alter_decimal;