diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.cpp b/dbms/src/Storages/MergeTree/MergeTreeData.cpp index 2cd02f7e5aa..4bc8ff9eafd 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeData.cpp @@ -106,7 +106,6 @@ MergeTreeData::MergeTreeData( bool attach, BrokenPartCallback broken_part_callback_) : global_context(context_), - index_granularity_info(settings_, full_path_), merging_params(merging_params_), settings(settings_), partition_by_ast(partition_by_ast_), @@ -198,7 +197,7 @@ MergeTreeData::MergeTreeData( "MergeTree data format version on disk doesn't support custom partitioning", ErrorCodes::METADATA_MISMATCH); } - + index_granularity_info.init(settings, format_version, full_path); } @@ -226,23 +225,27 @@ std::optional MergeTreeData::IndexGranularityInfo::getMrkExtensionF return {}; } -MergeTreeData::IndexGranularityInfo::IndexGranularityInfo(const MergeTreeSettings & settings, const std::string & full_path) - : fixed_index_granularity(settings.index_granularity) - , index_granularity_bytes(settings.index_granularity_bytes) +void MergeTreeData::IndexGranularityInfo::init( + const MergeTreeSettings & settings, + const MergeTreeDataFormatVersion & format_version, + const std::string & full_path) { + fixed_index_granularity = settings.index_granularity; auto mrk_ext = getMrkExtensionFromFS(full_path); /// Granularity is fixed - if (index_granularity_bytes == 0 || (mrk_ext && *mrk_ext == "mrk")) + if (index_granularity_bytes == 0 || (mrk_ext && *mrk_ext == "mrk") || format_version < MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING) { is_adaptive = false; mark_size_in_bytes = sizeof(UInt64) * 2; marks_file_extension = ".mrk"; + index_granularity_bytes = 0; } else { is_adaptive = true; mark_size_in_bytes = sizeof(UInt64) * 3; marks_file_extension = ".mrk2"; + index_granularity_bytes = settings.index_granularity_bytes; } } diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.h b/dbms/src/Storages/MergeTree/MergeTreeData.h index e425dc117f8..d0a86cd5c0d 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.h +++ b/dbms/src/Storages/MergeTree/MergeTreeData.h @@ -304,7 +304,7 @@ public: /// Approximate bytes size of one granule size_t index_granularity_bytes; - IndexGranularityInfo(const MergeTreeSettings & settings, const std::string & full_path); + void init(const MergeTreeSettings & settings, const MergeTreeDataFormatVersion & format_version, const std::string & full_path); String getMarksFilePath(const String & column_path) const { diff --git a/dbms/src/Storages/MergeTree/ReplicatedMergeTreeTableMetadata.cpp b/dbms/src/Storages/MergeTree/ReplicatedMergeTreeTableMetadata.cpp index b122785c5fd..46c37eb3dfe 100644 --- a/dbms/src/Storages/MergeTree/ReplicatedMergeTreeTableMetadata.cpp +++ b/dbms/src/Storages/MergeTree/ReplicatedMergeTreeTableMetadata.cpp @@ -45,9 +45,9 @@ ReplicatedMergeTreeTableMetadata::ReplicatedMergeTreeTableMetadata(const MergeTr if (data.format_version >= MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING) partition_key = formattedAST(MergeTreeData::extractKeyExpressionList(data.partition_by_ast)); + ttl_table = formattedAST(data.ttl_table_ast); skip_indices = data.getIndices().toString(); index_granularity_bytes = data.index_granularity_info.index_granularity_bytes; - ttl_table = formattedAST(data.ttl_table_ast); } void ReplicatedMergeTreeTableMetadata::write(WriteBuffer & out) const @@ -107,6 +107,9 @@ void ReplicatedMergeTreeTableMetadata::read(ReadBuffer & in) if (checkString("sorting key: ", in)) in >> sorting_key >> "\n"; + if (checkString("ttl: ", in)) + in >> ttl_table >> "\n"; + if (checkString("indices: ", in)) in >> skip_indices >> "\n"; @@ -115,8 +118,6 @@ void ReplicatedMergeTreeTableMetadata::read(ReadBuffer & in) else index_granularity_bytes = 0; - if (checkString("ttl: ", in)) - in >> ttl_table >> "\n"; } ReplicatedMergeTreeTableMetadata ReplicatedMergeTreeTableMetadata::parse(const String & s)