mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 17:41:59 +00:00
Merge pull request #58402 from zhangyifan27/add_max_estimated_execution_time
Seperate max_execution_time and max_estimated_execution_time
This commit is contained in:
commit
6f3124acdb
@ -172,7 +172,7 @@ If you set `timeout_before_checking_execution_speed `to 0, ClickHouse will use c
|
||||
|
||||
## timeout_overflow_mode {#timeout-overflow-mode}
|
||||
|
||||
What to do if the query is run longer than `max_execution_time`: `throw` or `break`. By default, `throw`.
|
||||
What to do if the query is run longer than `max_execution_time` or the estimated running time is longer than `max_estimated_execution_time`: `throw` or `break`. By default, `throw`.
|
||||
|
||||
# max_execution_time_leaf
|
||||
|
||||
@ -214,6 +214,10 @@ A maximum number of execution bytes per second. Checked on every data block when
|
||||
|
||||
Checks that execution speed is not too slow (no less than ‘min_execution_speed’), after the specified time in seconds has expired.
|
||||
|
||||
## max_estimated_execution_time {#max_estimated_execution_time}
|
||||
|
||||
Maximum query estimate execution time in seconds. Checked on every data block when ‘timeout_before_checking_execution_speed’ expires.
|
||||
|
||||
## max_columns_to_read {#max-columns-to-read}
|
||||
|
||||
A maximum number of columns that can be read from a table in a single query. If a query requires reading a greater number of columns, it throws an exception.
|
||||
|
@ -407,6 +407,7 @@ class IColumn;
|
||||
M(UInt64, min_execution_speed_bytes, 0, "Minimum number of execution bytes per second.", 0) \
|
||||
M(UInt64, max_execution_speed_bytes, 0, "Maximum number of execution bytes per second.", 0) \
|
||||
M(Seconds, timeout_before_checking_execution_speed, 10, "Check that the speed is not too low after the specified time has elapsed.", 0) \
|
||||
M(Seconds, max_estimated_execution_time, 0, "Maximum query estimate execution time in seconds.", 0) \
|
||||
\
|
||||
M(UInt64, max_columns_to_read, 0, "If a query requires reading more than specified number of columns, exception is thrown. Zero value means unlimited. This setting is useful to prevent too complex queries.", 0) \
|
||||
M(UInt64, max_temporary_columns, 0, "If a query generates more than the specified number of temporary columns in memory as a result of intermediate calculation, exception is thrown. Zero value means unlimited. This setting is useful to prevent too complex queries.", 0) \
|
||||
|
@ -54,6 +54,7 @@ static StreamLocalLimits getLimitsForStorage(const Settings & settings, const Se
|
||||
limits.speed_limits.max_execution_rps = settings.max_execution_speed;
|
||||
limits.speed_limits.max_execution_bps = settings.max_execution_speed_bytes;
|
||||
limits.speed_limits.timeout_before_checking_execution_speed = settings.timeout_before_checking_execution_speed;
|
||||
limits.speed_limits.max_estimated_execution_time = settings.max_estimated_execution_time;
|
||||
|
||||
return limits;
|
||||
}
|
||||
|
@ -179,6 +179,7 @@ StreamLocalLimits getLimitsForStorage(const Settings & settings, const SelectQue
|
||||
limits.speed_limits.max_execution_rps = settings.max_execution_speed;
|
||||
limits.speed_limits.max_execution_bps = settings.max_execution_speed_bytes;
|
||||
limits.speed_limits.timeout_before_checking_execution_speed = settings.timeout_before_checking_execution_speed;
|
||||
limits.speed_limits.max_estimated_execution_time = settings.max_estimated_execution_time;
|
||||
|
||||
return limits;
|
||||
}
|
||||
|
@ -78,17 +78,17 @@ void ExecutionSpeedLimits::throttle(
|
||||
read_bytes / elapsed_seconds,
|
||||
min_execution_bps);
|
||||
|
||||
/// If the predicted execution time is longer than `max_execution_time`.
|
||||
if (max_execution_time != 0 && total_rows_to_read && read_rows)
|
||||
/// If the predicted execution time is longer than `max_estimated_execution_time`.
|
||||
if (max_estimated_execution_time != 0 && total_rows_to_read && read_rows)
|
||||
{
|
||||
double estimated_execution_time_seconds = elapsed_seconds * (static_cast<double>(total_rows_to_read) / read_rows);
|
||||
|
||||
if (timeout_overflow_mode == OverflowMode::THROW && estimated_execution_time_seconds > max_execution_time.totalSeconds())
|
||||
if (timeout_overflow_mode == OverflowMode::THROW && estimated_execution_time_seconds > max_estimated_execution_time.totalSeconds())
|
||||
throw Exception(
|
||||
ErrorCodes::TOO_SLOW,
|
||||
"Estimated query execution time ({} seconds) is too long. Maximum: {}. Estimated rows to process: {}",
|
||||
estimated_execution_time_seconds,
|
||||
max_execution_time.totalSeconds(),
|
||||
max_estimated_execution_time.totalSeconds(),
|
||||
total_rows_to_read);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ public:
|
||||
size_t max_execution_bps = 0;
|
||||
|
||||
Poco::Timespan max_execution_time = 0;
|
||||
Poco::Timespan max_estimated_execution_time = 0;
|
||||
/// Verify that the speed is not too low after the specified time has elapsed.
|
||||
Poco::Timespan timeout_before_checking_execution_speed = 0;
|
||||
|
||||
|
@ -716,6 +716,7 @@ void RemoteQueryExecutor::sendExternalTables()
|
||||
limits.mode = LimitsMode::LIMITS_TOTAL;
|
||||
limits.speed_limits.max_execution_time = settings.max_execution_time;
|
||||
limits.timeout_overflow_mode = settings.timeout_overflow_mode;
|
||||
limits.speed_limits.max_estimated_execution_time = settings.max_estimated_execution_time;
|
||||
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
|
@ -1,10 +1,10 @@
|
||||
-- Tags: no-fasttest
|
||||
|
||||
-- Query stops after timeout without an error
|
||||
SELECT * FROM numbers(100000000) SETTINGS max_block_size=1, max_execution_time=13, timeout_overflow_mode='break' FORMAT Null;
|
||||
SELECT * FROM numbers(100000000) SETTINGS max_block_size=1, max_execution_time=2, timeout_overflow_mode='break' FORMAT Null;
|
||||
|
||||
-- Query returns an error when runtime is estimated after 10 sec of execution
|
||||
SELECT * FROM numbers(100000000) SETTINGS max_block_size=1, max_execution_time=13, timeout_overflow_mode='throw' FORMAT Null; -- { serverError TOO_SLOW }
|
||||
-- Query returns an error when runtime is estimated after timeout_before_checking_execution_speed passed
|
||||
SELECT * FROM numbers(100000000) SETTINGS max_block_size=1, timeout_before_checking_execution_speed=1, max_estimated_execution_time=2, timeout_overflow_mode='throw' FORMAT Null; -- { serverError TOO_SLOW }
|
||||
|
||||
-- Query returns timeout error before its full execution time is estimated
|
||||
SELECT * FROM numbers(100000000) SETTINGS max_block_size=1, max_execution_time=2, timeout_overflow_mode='throw' FORMAT Null; -- { serverError TIMEOUT_EXCEEDED }
|
||||
SELECT * FROM numbers(100000000) SETTINGS max_block_size=1, timeout_before_checking_execution_speed=1, max_execution_time=2, timeout_overflow_mode='throw' FORMAT Null; -- { serverError TIMEOUT_EXCEEDED }
|
||||
|
Loading…
Reference in New Issue
Block a user