From 173d5d0b98e6bcdf1b97ddf31152a5a6b76b3841 Mon Sep 17 00:00:00 2001 From: Antonio Andelic Date: Wed, 8 May 2024 12:15:54 +0200 Subject: [PATCH] Keep parent part alive for read task --- .../MergeTree/MergeTreePrefetchedReadPool.cpp | 2 +- .../MergeTree/MergeTreeReadPoolBase.cpp | 18 ++++++++++++++++++ src/Storages/MergeTree/MergeTreeReadTask.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Storages/MergeTree/MergeTreePrefetchedReadPool.cpp b/src/Storages/MergeTree/MergeTreePrefetchedReadPool.cpp index ebd19093f68..91cbdc79624 100644 --- a/src/Storages/MergeTree/MergeTreePrefetchedReadPool.cpp +++ b/src/Storages/MergeTree/MergeTreePrefetchedReadPool.cpp @@ -53,7 +53,7 @@ MergeTreePrefetchedReadPool::PrefetchedReaders::PrefetchedReaders( MergeTreePrefetchedReadPool & read_prefetch) : is_valid(true) , readers(std::move(readers_)) - , prefetch_runner(pool, "Prefetch") + , prefetch_runner(pool, "ReadPrepare") { prefetch_runner(read_prefetch.createPrefetchedTask(readers.main.get(), priority_)); diff --git a/src/Storages/MergeTree/MergeTreeReadPoolBase.cpp b/src/Storages/MergeTree/MergeTreeReadPoolBase.cpp index 0cbb0a86b2f..d4b9ce34796 100644 --- a/src/Storages/MergeTree/MergeTreeReadPoolBase.cpp +++ b/src/Storages/MergeTree/MergeTreeReadPoolBase.cpp @@ -6,6 +6,11 @@ namespace DB { +namespace ErrorCodes +{ + extern const int LOGICAL_ERROR; +} + MergeTreeReadPoolBase::MergeTreeReadPoolBase( RangesInDataParts && parts_, VirtualFields shared_virtual_fields_, @@ -48,6 +53,19 @@ void MergeTreeReadPoolBase::fillPerPartInfos() MergeTreeReadTaskInfo read_task_info; read_task_info.data_part = part_with_ranges.data_part; + + const auto & data_part = read_task_info.data_part; + if (data_part->isProjectionPart()) + { + read_task_info.parent_part = data_part->storage.getPartIfExists( + data_part->getParentPartName(), + {MergeTreeDataPartState::PreActive, MergeTreeDataPartState::Active, MergeTreeDataPartState::Outdated}); + + if (!read_task_info.parent_part) + throw Exception(ErrorCodes::LOGICAL_ERROR, "Did not find parent part {} for projection part {}", + data_part->getParentPartName(), data_part->getDataPartStorage().getFullPath()); + } + read_task_info.part_index_in_query = part_with_ranges.part_index_in_query; read_task_info.alter_conversions = part_with_ranges.alter_conversions; diff --git a/src/Storages/MergeTree/MergeTreeReadTask.h b/src/Storages/MergeTree/MergeTreeReadTask.h index c8bb501c0e8..3af95b9cdce 100644 --- a/src/Storages/MergeTree/MergeTreeReadTask.h +++ b/src/Storages/MergeTree/MergeTreeReadTask.h @@ -56,6 +56,8 @@ struct MergeTreeReadTaskInfo { /// Data part which should be read while performing this task DataPartPtr data_part; + /// Parent part of the projection part + DataPartPtr parent_part; /// For `part_index` virtual column size_t part_index_in_query; /// Alter converversionss that should be applied on-fly for part.