diff --git a/src/Storages/MergeTree/MergeTreeReaderCompact.cpp b/src/Storages/MergeTree/MergeTreeReaderCompact.cpp index 06635c39838..a4fa3a30d23 100644 --- a/src/Storages/MergeTree/MergeTreeReaderCompact.cpp +++ b/src/Storages/MergeTree/MergeTreeReaderCompact.cpp @@ -149,7 +149,8 @@ void MergeTreeReaderCompact::readData( size_t rows_to_read, const InputStreamGetter & getter, ISerialization::SubstreamsCache & cache, - std::unordered_map & columns_cache_for_subcolumns) + std::unordered_map & columns_cache_for_subcolumns, + const ColumnNameLevel & name_level_for_offsets) { try { @@ -172,7 +173,8 @@ void MergeTreeReaderCompact::readData( const auto & type_in_storage = name_and_type.getTypeInStorage(); const auto & name_in_storage = name_and_type.getNameInStorage(); - if (auto cache_for_subcolumns_it = columns_cache_for_subcolumns.find(name_in_storage); cache_for_subcolumns_it != columns_cache_for_subcolumns.end()) + auto cache_for_subcolumns_it = columns_cache_for_subcolumns.find(name_in_storage); + if (!name_level_for_offsets.has_value() && cache_for_subcolumns_it != columns_cache_for_subcolumns.end()) { auto subcolumn = type_in_storage->getSubcolumn(name_and_type.getSubcolumnName(), cache_for_subcolumns_it->second); /// TODO: Avoid extra copying. @@ -195,7 +197,8 @@ void MergeTreeReaderCompact::readData( else column->assumeMutable()->insertRangeFrom(*subcolumn, 0, subcolumn->size()); - columns_cache_for_subcolumns[name_in_storage] = temp_column; + if (!name_level_for_offsets.has_value()) + columns_cache_for_subcolumns[name_in_storage] = temp_column; } } else diff --git a/src/Storages/MergeTree/MergeTreeReaderCompact.h b/src/Storages/MergeTree/MergeTreeReaderCompact.h index f18ee8808ec..7dbebb75a91 100644 --- a/src/Storages/MergeTree/MergeTreeReaderCompact.h +++ b/src/Storages/MergeTree/MergeTreeReaderCompact.h @@ -46,7 +46,8 @@ protected: size_t rows_to_read, const InputStreamGetter & getter, ISerialization::SubstreamsCache & cache, - std::unordered_map & columns_cache_for_subcolumns); + std::unordered_map & columns_cache_for_subcolumns, + const ColumnNameLevel & name_level_for_offsets); void readPrefix( const NameAndTypePair & name_and_type, diff --git a/src/Storages/MergeTree/MergeTreeReaderCompactSingleBuffer.cpp b/src/Storages/MergeTree/MergeTreeReaderCompactSingleBuffer.cpp index 50224eba82d..0c3e67d5078 100644 --- a/src/Storages/MergeTree/MergeTreeReaderCompactSingleBuffer.cpp +++ b/src/Storages/MergeTree/MergeTreeReaderCompactSingleBuffer.cpp @@ -62,7 +62,7 @@ try }; readPrefix(columns_to_read[pos], buffer_getter, buffer_getter_for_prefix, columns_for_offsets[pos]); - readData(columns_to_read[pos], column, rows_to_read, buffer_getter, cache, columns_cache_for_subcolumns); + readData(columns_to_read[pos], column, rows_to_read, buffer_getter, cache, columns_cache_for_subcolumns, columns_for_offsets[pos]); } ++from_mark;