Fix detach/attach for ReplicatedVersionedCollapsingMergeTree after alter

This commit is contained in:
alesapin 2021-09-02 17:47:00 +03:00
parent ab3e005e6a
commit ba78a737dc
2 changed files with 23 additions and 1 deletions

View File

@ -46,7 +46,15 @@ ReplicatedMergeTreeTableMetadata::ReplicatedMergeTreeTableMetadata(const MergeTr
primary_key = formattedAST(metadata_snapshot->getPrimaryKey().expression_list_ast);
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
/// shouldn't be defined as a part of key definition AST. 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;

View File

@ -19,10 +19,20 @@ SETTINGS index_granularity = 8192;
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;
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;
SHOW CREATE TABLE table_for_alter;
@ -35,4 +45,8 @@ SELECT * FROM table_for_alter ORDER BY d;
SHOW CREATE TABLE table_for_alter;
DETACH TABLE table_for_alter;
ATTACH TABLE table_for_alter;
DROP TABLE IF EXISTS table_for_alter;