Merge pull request #13201 from azat/fix-logging-in-MergeTreeDataSelectExecutor

Fix logging in MergeTreeDataSelectExecutor for multiple threads (attach to thread group)
This commit is contained in:
Nikolai Kochetov 2020-08-03 10:08:58 +03:00 committed by GitHub
commit cf49a83980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -1,4 +1,5 @@
#include <boost/rational.hpp> /// For calculations related to sampling coefficients. #include <boost/rational.hpp> /// For calculations related to sampling coefficients.
#include <ext/scope_guard.h>
#include <optional> #include <optional>
#include <Poco/File.h> #include <Poco/File.h>
@ -613,7 +614,16 @@ Pipes MergeTreeDataSelectExecutor::readFromParts(
ThreadPool pool(num_threads); ThreadPool pool(num_threads);
for (size_t part_index = 0; part_index < parts.size(); ++part_index) 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(); pool.wait();
} }
@ -1343,7 +1353,7 @@ MarkRanges MergeTreeDataSelectExecutor::markRangesFromPKRange(
/// If index is not used. /// If index is not used.
if (key_condition.alwaysUnknownOrTrue()) if (key_condition.alwaysUnknownOrTrue())
{ {
LOG_TRACE(log, "Not using index on part {}", part->name); LOG_TRACE(log, "Not using primary index on part {}", part->name);
if (has_final_mark) if (has_final_mark)
res.push_back(MarkRange(0, marks_count - 1)); res.push_back(MarkRange(0, marks_count - 1));

View File

@ -9,11 +9,11 @@ set log_queries = 1;
select x from table_01323_many_parts limit 10 format Null; select x from table_01323_many_parts limit 10 format Null;
system flush logs; system flush logs;
select length(thread_ids) <= 4 from system.query_log where event_date >= today() - 1 and lower(query) like '%select x from table_01323_many_parts%' and type = 'QueryFinish' order by query_start_time desc limit 1; select arrayUniq(thread_ids) <= 4 from system.query_log where event_date >= today() - 1 and query ilike '%select x from table_01323_many_parts%' and query not like '%system.query_log%' and type = 'QueryFinish' order by query_start_time desc limit 1;
select x from table_01323_many_parts order by x limit 10 format Null; select x from table_01323_many_parts order by x limit 10 format Null;
system flush logs; system flush logs;
select length(thread_ids) <= 20 from system.query_log where event_date >= today() - 1 and lower(query) like '%select x from table_01323_many_parts order by x%' and type = 'QueryFinish' order by query_start_time desc limit 1; select arrayUniq(thread_ids) <= 36 from system.query_log where event_date >= today() - 1 and query ilike '%select x from table_01323_many_parts order by x%' and query not like '%system.query_log%' and type = 'QueryFinish' order by query_start_time desc limit 1;
drop table if exists table_01323_many_parts; drop table if exists table_01323_many_parts;