Analyzer setting max_streams_to_max_threads_ratio overflow fix

This commit is contained in:
Maksim Kita 2024-05-07 17:21:25 +03:00
parent 977783ea94
commit cad9c97725
4 changed files with 25 additions and 3 deletions

View File

@ -253,9 +253,9 @@ private:
else
{
Y scaled;
bool has_overfllow = common::mulOverflow<Y>(y, levels_num, scaled);
bool has_overflow = common::mulOverflow<Y>(y, levels_num, scaled);
if (has_overfllow)
if (has_overflow)
y = y / (y_max / levels_num) + 1;
else
y = scaled / y_max + 1;

View File

@ -708,7 +708,15 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expres
/// If necessary, we request more sources than the number of threads - to distribute the work evenly over the threads
if (max_streams > 1 && !is_sync_remote)
max_streams = static_cast<size_t>(max_streams * settings.max_streams_to_max_threads_ratio);
{
if (auto streams_with_ratio = max_streams * settings.max_streams_to_max_threads_ratio; canConvertTo<size_t>(streams_with_ratio))
max_streams = static_cast<size_t>(streams_with_ratio);
else
throw Exception(ErrorCodes::PARAMETER_OUT_OF_BOUND,
"Exceeded limit for `max_streams` with `max_streams_to_max_threads_ratio`. "
"Make sure that `max_streams * max_streams_to_max_threads_ratio` is in some reasonable boundaries, current value: {}",
streams_with_ratio);
}
if (table_node)
table_expression_query_info.table_expression_modifiers = table_node->getTableExpressionModifiers();

View File

@ -0,0 +1,14 @@
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table
(
id UInt64,
value String
) ENGINE = MergeTree ORDER BY id;
INSERT INTO test_table VALUES (0, 'Value_0');
SELECT * FROM test_table SETTINGS max_threads = 1025, max_streams_to_max_threads_ratio = -9223372036854775808, allow_experimental_analyzer = 1; -- { serverError PARAMETER_OUT_OF_BOUND }
SELECT * FROM test_table SETTINGS max_threads = 1025, max_streams_to_max_threads_ratio = -9223372036854775808, allow_experimental_analyzer = 0; -- { serverError PARAMETER_OUT_OF_BOUND }
DROP TABLE test_table;