Skip to content

Commit e3c164f

Browse files
committed
Fix zero streams after max_streams_to_max_threads_ratio applied
Set at least one stream for reading in case there are zero planned streams after applying `max_streams_to_max_threads_ratio` setting.
1 parent 6dc235f commit e3c164f

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

src/Interpreters/InterpreterSelectQuery.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,8 +2652,6 @@ void InterpreterSelectQuery::executeFetchColumns(QueryProcessingStage::Enum proc
26522652
else if (storage)
26532653
{
26542654
/// Table.
2655-
if (max_streams == 0)
2656-
max_streams = 1;
26572655

26582656
/// If necessary, we request more sources than the number of threads - to distribute the work evenly over the threads.
26592657
if (max_streams > 1 && !is_sync_remote)
@@ -2668,6 +2666,9 @@ void InterpreterSelectQuery::executeFetchColumns(QueryProcessingStage::Enum proc
26682666
streams_with_ratio);
26692667
}
26702668

2669+
if (max_streams == 0)
2670+
max_streams = 1;
2671+
26712672
auto & prewhere_info = analysis_result.prewhere_info;
26722673

26732674
if (prewhere_info)

src/Planner/PlannerJoinTree.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,6 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expres
771771
"Setting 'max_block_size' cannot be zero");
772772
}
773773

774-
if (max_streams == 0)
775-
max_streams = 1;
776-
777774
/// If necessary, we request more sources than the number of threads - to distribute the work evenly over the threads
778775
if (max_streams > 1 && !is_sync_remote)
779776
{
@@ -787,6 +784,9 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expres
787784
streams_with_ratio);
788785
}
789786

787+
if (max_streams == 0)
788+
max_streams = 1;
789+
790790
if (table_node)
791791
table_expression_query_info.table_expression_modifiers = table_node->getTableExpressionModifiers();
792792
else
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
49.5
2+
49.5
3+
49.5
4+
5+
0
6+
0
7+
0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
DROP TABLE IF EXISTS 03402_data;
2+
3+
CREATE TABLE 03402_data (id UInt32) ENGINE = MergeTree ORDER BY id;
4+
INSERT INTO 03402_data SELECT * FROM numbers(100);
5+
6+
SELECT avg(id) FROM 03402_data SETTINGS max_threads = 4, max_streams_to_max_threads_ratio = 0;
7+
SELECT avg(id) FROM 03402_data SETTINGS max_threads = 0, max_streams_to_max_threads_ratio = 0;
8+
SELECT avg(id) FROM 03402_data SETTINGS max_threads = 2, max_streams_to_max_threads_ratio = 0.2;
9+
10+
SELECT '';
11+
12+
SELECT id FROM 03402_data ORDER BY id LIMIT 1 SETTINGS max_threads = 4, max_streams_to_max_threads_ratio = 0;
13+
SELECT id FROM 03402_data ORDER BY id LIMIT 1 SETTINGS max_threads = 0, max_streams_to_max_threads_ratio = 0;
14+
SELECT id FROM 03402_data ORDER BY id LIMIT 1 SETTINGS max_threads = 2, max_streams_to_max_threads_ratio = 0.2;
15+
16+
DROP TABLE 03402_data;

0 commit comments

Comments
 (0)