From e37c42c56cba01de045b30035d02871a21bcee0f Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 1 Aug 2020 02:55:08 +0300 Subject: [PATCH] Fix logging in MergeTreeDataSelectExecutor for multiple threads (attach to thread group) --- .../MergeTree/MergeTreeDataSelectExecutor.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp index dc32e225697..7ac8ca6143b 100644 --- a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp +++ b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp @@ -1,4 +1,5 @@ #include /// For calculations related to sampling coefficients. +#include #include #include @@ -613,7 +614,16 @@ Pipes MergeTreeDataSelectExecutor::readFromParts( ThreadPool pool(num_threads); for (size_t part_index = 0; part_index < parts.size(); ++part_index) - pool.scheduleOrThrowOnError([&, part_index] { process_part(part_index); }); + pool.scheduleOrThrowOnError([&, part_index, thread_group = CurrentThread::getGroup()] { + SCOPE_EXIT( + if (thread_group) + CurrentThread::detachQueryIfNotDetached(); + ); + if (thread_group) + CurrentThread::attachTo(thread_group); + + process_part(part_index); + }); pool.wait(); }