Merge pull request #12085 from ClickHouse/fix-11937

Fix limiting the number of threads for VIEW.
This commit is contained in:
Nikolai Kochetov 2020-07-03 10:35:04 +03:00 committed by GitHub
commit 17c89f3fe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 3 deletions

View File

@ -167,6 +167,13 @@ public:
/// Set upper limit for the recommend number of threads
void setMaxThreads(size_t max_threads_) { max_threads = max_threads_; }
/// Update upper limit for the recommend number of threads
void limitMaxThreads(size_t max_threads_)
{
if (max_threads == 0 || max_threads_ < max_threads)
max_threads = max_threads_;
}
/// Convert query pipeline to single or several pipes.
Pipe getPipe() &&;
Pipes getPipes() &&;

View File

@ -153,8 +153,8 @@ QueryPipelinePtr QueryPlan::buildQueryPipeline()
bool limit_max_threads = frame.pipelines.empty();
last_pipeline = frame.node->step->updatePipeline(std::move(frame.pipelines));
if (limit_max_threads)
last_pipeline->setMaxThreads(max_threads);
if (limit_max_threads && max_threads)
last_pipeline->limitMaxThreads(max_threads);
stack.pop();
}

View File

@ -113,7 +113,7 @@ ReadFromStorageStep::ReadFromStorageStep(
}
}
if (pipes.size() == 1)
if (pipes.size() == 1 && !storage->isView())
pipeline->setMaxThreads(1);
for (auto & pipe : pipes)

View File

@ -0,0 +1,3 @@
0 249999500000
1 250000000000
1

View File

@ -0,0 +1,12 @@
drop table if exists table_01356_view_threads;
create view table_01356_view_threads as select number % 10 as g, sum(number) as s from numbers_mt(1000000) group by g;
set log_queries = 1;
set max_threads = 16;
select g % 2 as gg, sum(s) from table_01356_view_threads group by gg order by gg;
system flush logs;
select length(thread_ids) >= 16 from system.query_log where event_date >= today() - 1 and lower(query) like '%select g % 2 as gg, sum(s) from table_01356_view_threads group by gg order by gg%' and type = 'QueryFinish' order by query_start_time desc limit 1;
drop table if exists table_01356_view_threads;