Skip to content

Commit 17c89f3

Browse files
Merge pull request #12085 from ClickHouse/fix-11937
Fix limiting the number of threads for VIEW.
2 parents 457f56b + aca1d8a commit 17c89f3

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

src/Processors/QueryPipeline.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ class QueryPipeline
167167
/// Set upper limit for the recommend number of threads
168168
void setMaxThreads(size_t max_threads_) { max_threads = max_threads_; }
169169

170+
/// Update upper limit for the recommend number of threads
171+
void limitMaxThreads(size_t max_threads_)
172+
{
173+
if (max_threads == 0 || max_threads_ < max_threads)
174+
max_threads = max_threads_;
175+
}
176+
170177
/// Convert query pipeline to single or several pipes.
171178
Pipe getPipe() &&;
172179
Pipes getPipes() &&;

src/Processors/QueryPlan/QueryPlan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ QueryPipelinePtr QueryPlan::buildQueryPipeline()
153153
bool limit_max_threads = frame.pipelines.empty();
154154
last_pipeline = frame.node->step->updatePipeline(std::move(frame.pipelines));
155155

156-
if (limit_max_threads)
157-
last_pipeline->setMaxThreads(max_threads);
156+
if (limit_max_threads && max_threads)
157+
last_pipeline->limitMaxThreads(max_threads);
158158

159159
stack.pop();
160160
}

src/Processors/QueryPlan/ReadFromStorageStep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ ReadFromStorageStep::ReadFromStorageStep(
113113
}
114114
}
115115

116-
if (pipes.size() == 1)
116+
if (pipes.size() == 1 && !storage->isView())
117117
pipeline->setMaxThreads(1);
118118

119119
for (auto & pipe : pipes)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
0 249999500000
2+
1 250000000000
3+
1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
drop table if exists table_01356_view_threads;
2+
3+
create view table_01356_view_threads as select number % 10 as g, sum(number) as s from numbers_mt(1000000) group by g;
4+
5+
set log_queries = 1;
6+
set max_threads = 16;
7+
select g % 2 as gg, sum(s) from table_01356_view_threads group by gg order by gg;
8+
9+
system flush logs;
10+
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;
11+
12+
drop table if exists table_01356_view_threads;

0 commit comments

Comments
 (0)