diff --git a/src/Storages/MergeTree/MergePlainMergeTreeTask.cpp b/src/Storages/MergeTree/MergePlainMergeTreeTask.cpp index 64065c7cfa1..871672c442b 100644 --- a/src/Storages/MergeTree/MergePlainMergeTreeTask.cpp +++ b/src/Storages/MergeTree/MergePlainMergeTreeTask.cpp @@ -4,6 +4,8 @@ #include #include #include +#include + namespace DB { @@ -106,6 +108,19 @@ void MergePlainMergeTreeTask::prepare() std::move(profile_counters_snapshot)); }; + transfer_profile_counters_to_initial_query = [this, query_thread_group = CurrentThread::getGroup()] () + { + if (query_thread_group) + { + auto task_thread_group = (*merge_list_entry)->thread_group; + auto task_counters_snapshot = task_thread_group->performance_counters.getPartiallyAtomicSnapshot(); + + auto & query_counters = query_thread_group->performance_counters; + for (ProfileEvents::Event i = ProfileEvents::Event(0); i < ProfileEvents::end(); ++i) + query_counters.incrementNoTrace(i, task_counters_snapshot[i]); + } + }; + merge_task = storage.merger_mutator.mergePartsToTemporaryPart( future_part, metadata_snapshot, @@ -133,6 +148,7 @@ void MergePlainMergeTreeTask::finish() write_part_log({}); storage.incrementMergedPartsProfileEvent(new_part->getType()); + transfer_profile_counters_to_initial_query(); } ContextMutablePtr MergePlainMergeTreeTask::createTaskContext() const diff --git a/src/Storages/MergeTree/MergePlainMergeTreeTask.h b/src/Storages/MergeTree/MergePlainMergeTreeTask.h index 478ec36630c..369b4390da7 100644 --- a/src/Storages/MergeTree/MergePlainMergeTreeTask.h +++ b/src/Storages/MergeTree/MergePlainMergeTreeTask.h @@ -80,6 +80,7 @@ private: UInt64 priority{0}; std::function write_part_log; + std::function transfer_profile_counters_to_initial_query; IExecutableTask::TaskResultCallback task_result_callback; MergeTaskPtr merge_task{nullptr};