Merge pull request #28528 from ClickHouse/fix_detach_attach_versioned_collapsing

Fix detach/attach for ReplicatedVersionedCollapsingMergeTree after alter
This commit is contained in:
alesapin 2021-09-03 10:13:52 +03:00 committed by GitHub
commit 1894524438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View File

@ -46,7 +46,15 @@ ReplicatedMergeTreeTableMetadata::ReplicatedMergeTreeTableMetadata(const MergeTr
primary_key = formattedAST(metadata_snapshot->getPrimaryKey().expression_list_ast); primary_key = formattedAST(metadata_snapshot->getPrimaryKey().expression_list_ast);
if (metadata_snapshot->isPrimaryKeyDefined()) if (metadata_snapshot->isPrimaryKeyDefined())
sorting_key = formattedAST(metadata_snapshot->getSortingKey().expression_list_ast); {
/// We don't use preparsed AST `sorting_key.expression_list_ast` because
/// it contain version column for VersionedCollapsingMergeTree, which
/// is not stored in ZooKeeper for compatibility reasons. So the best
/// compatible way is just to convert definition_ast to list and
/// serialize it. In all other places key.expression_list_ast should be
/// used.
sorting_key = formattedAST(extractKeyExpressionList(metadata_snapshot->getSortingKey().definition_ast));
}
data_format_version = data.format_version; data_format_version = data.format_version;

View File

@ -1,6 +1,6 @@
2019-10-01 a 1 aa 1 1 1 2019-10-01 a 1 aa 1 1 1
2019-10-01 a 1 aa 1 1 1 0 2019-10-01 a 1 aa 1 1 1 0
CREATE TABLE default.table_for_alter\n(\n `d` Date,\n `a` String,\n `b` UInt8,\n `x` String,\n `y` Int8,\n `version` UInt64,\n `sign` Int8 DEFAULT 1,\n `order` UInt32\n)\nENGINE = ReplicatedVersionedCollapsingMergeTree(\'/clickhouse/tables/01526_alter_add/t1\', \'1\', sign, version)\nPARTITION BY y\nPRIMARY KEY d\nORDER BY (d, order)\nSETTINGS index_granularity = 8192 CREATE TABLE default.table_for_alter\n(\n `d` Date,\n `a` String,\n `b` UInt8,\n `x` String,\n `y` Int8,\n `version` UInt64,\n `sign` Int8 DEFAULT 1,\n `order` UInt32\n)\nENGINE = ReplicatedVersionedCollapsingMergeTree(\'/clickhouse/tables/default/01526_alter_add/t1\', \'1\', sign, version)\nPARTITION BY y\nPRIMARY KEY d\nORDER BY (d, order)\nSETTINGS index_granularity = 8192
2019-10-01 a 1 aa 1 1 1 0 0 2019-10-01 a 1 aa 1 1 1 0 0
2019-10-02 b 2 bb 2 2 2 1 2 2019-10-02 b 2 bb 2 2 2 1 2
CREATE TABLE default.table_for_alter\n(\n `d` Date,\n `a` String,\n `b` UInt8,\n `x` String,\n `y` Int8,\n `version` UInt64,\n `sign` Int8 DEFAULT 1,\n `order` UInt32,\n `datum` UInt32\n)\nENGINE = ReplicatedVersionedCollapsingMergeTree(\'/clickhouse/tables/01526_alter_add/t1\', \'1\', sign, version)\nPARTITION BY y\nPRIMARY KEY d\nORDER BY (d, order, datum)\nSETTINGS index_granularity = 8192 CREATE TABLE default.table_for_alter\n(\n `d` Date,\n `a` String,\n `b` UInt8,\n `x` String,\n `y` Int8,\n `version` UInt64,\n `sign` Int8 DEFAULT 1,\n `order` UInt32,\n `datum` UInt32\n)\nENGINE = ReplicatedVersionedCollapsingMergeTree(\'/clickhouse/tables/default/01526_alter_add/t1\', \'1\', sign, version)\nPARTITION BY y\nPRIMARY KEY d\nORDER BY (d, order, datum)\nSETTINGS index_granularity = 8192

View File

@ -12,17 +12,27 @@ CREATE TABLE table_for_alter
`version` UInt64, `version` UInt64,
`sign` Int8 DEFAULT 1 `sign` Int8 DEFAULT 1
) )
ENGINE = ReplicatedVersionedCollapsingMergeTree('/clickhouse/tables/01526_alter_add/t1', '1', sign, version) ENGINE = ReplicatedVersionedCollapsingMergeTree('/clickhouse/tables/{database}/01526_alter_add/t1', '1', sign, version)
PARTITION BY y PARTITION BY y
ORDER BY d ORDER BY d
SETTINGS index_granularity = 8192; SETTINGS index_granularity = 8192;
INSERT INTO table_for_alter VALUES(toDate('2019-10-01'), 'a', 1, 'aa', 1, 1, 1); INSERT INTO table_for_alter VALUES(toDate('2019-10-01'), 'a', 1, 'aa', 1, 1, 1);
DETACH TABLE table_for_alter;
ATTACH TABLE table_for_alter;
SELECT * FROM table_for_alter; SELECT * FROM table_for_alter;
ALTER TABLE table_for_alter ADD COLUMN order UInt32, MODIFY ORDER BY (d, order); ALTER TABLE table_for_alter ADD COLUMN order UInt32, MODIFY ORDER BY (d, order);
DETACH TABLE table_for_alter;
ATTACH TABLE table_for_alter;
SELECT * FROM table_for_alter; SELECT * FROM table_for_alter;
SHOW CREATE TABLE table_for_alter; SHOW CREATE TABLE table_for_alter;
@ -35,4 +45,8 @@ SELECT * FROM table_for_alter ORDER BY d;
SHOW CREATE TABLE table_for_alter; SHOW CREATE TABLE table_for_alter;
DETACH TABLE table_for_alter;
ATTACH TABLE table_for_alter;
DROP TABLE IF EXISTS table_for_alter; DROP TABLE IF EXISTS table_for_alter;