diff --git a/src/Storages/MergeTree/MergeTreeDataPartWriterCompact.cpp b/src/Storages/MergeTree/MergeTreeDataPartWriterCompact.cpp index 70beaec5e5e..22df2abecf3 100644 --- a/src/Storages/MergeTree/MergeTreeDataPartWriterCompact.cpp +++ b/src/Storages/MergeTree/MergeTreeDataPartWriterCompact.cpp @@ -29,9 +29,6 @@ MergeTreeDataPartWriterCompact::MergeTreeDataPartWriterCompact( , marks(*marks_file) { const auto & storage_columns = metadata_snapshot->getColumns(); - - /// Create compressed stream for every different codec. - std::unordered_map streams_by_codec; for (const auto & column : columns_list) { auto codec = storage_columns.getCodecOrDefault(column.name, default_codec); @@ -226,7 +223,7 @@ void MergeTreeDataPartWriterCompact::addToChecksums(MergeTreeDataPartChecksums & size_t uncompressed_size = 0; CityHash_v1_0_2::uint128 uncompressed_hash{0, 0}; - for (const auto & stream : compressed_streams) + for (const auto & [_, stream] : streams_by_codec) { uncompressed_size += stream->hashing_buf.count(); auto stream_hash = stream->hashing_buf.getHash(); diff --git a/src/Storages/MergeTree/MergeTreeDataPartWriterCompact.h b/src/Storages/MergeTree/MergeTreeDataPartWriterCompact.h index 2f24c515fb3..a121554f4be 100644 --- a/src/Storages/MergeTree/MergeTreeDataPartWriterCompact.h +++ b/src/Storages/MergeTree/MergeTreeDataPartWriterCompact.h @@ -62,6 +62,11 @@ private: }; using CompressedStreamPtr = std::shared_ptr; + + /// Create compressed stream for every different codec. + std::unordered_map streams_by_codec; + + /// For better performance save pointer to stream by every column. std::vector compressed_streams; /// marks -> marks_file