Fix logging in MergeTreeDataSelectExecutor for multiple threads (attach to thread group)

This commit is contained in:
Azat Khuzhin 2020-08-01 02:55:08 +03:00
parent 101217470e
commit e37c42c56c

View File

@ -1,4 +1,5 @@
#include <boost/rational.hpp> /// For calculations related to sampling coefficients.
#include <ext/scope_guard.h>
#include <optional>
#include <Poco/File.h>
@ -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();
}