diff --git a/dbms/src/DataStreams/IBlockInputStream.cpp b/dbms/src/DataStreams/IBlockInputStream.cpp index 406a660879c..a2c3fb2247c 100644 --- a/dbms/src/DataStreams/IBlockInputStream.cpp +++ b/dbms/src/DataStreams/IBlockInputStream.cpp @@ -255,6 +255,10 @@ static void limitProgressingSpeed(size_t total_progress_size, size_t max_speed_i if (desired_microseconds > total_elapsed_microseconds) { UInt64 sleep_microseconds = desired_microseconds - total_elapsed_microseconds; + + /// Never sleep more than one second (it should be enough to limit speed for a reasonable amount, and otherwise it's too easy to make query hang). + sleep_microseconds = std::min(UInt64(1000000), sleep_microseconds); + sleepForMicroseconds(sleep_microseconds); ProfileEvents::increment(ProfileEvents::ThrottlerSleepMicroseconds, sleep_microseconds); @@ -349,7 +353,7 @@ void IBlockInputStream::progressImpl(const Progress & value) ErrorCodes::TOO_SLOW); /// If the predicted execution time is longer than `max_execution_time`. - if (limits.max_execution_time != 0 && total_rows) + if (limits.max_execution_time != 0 && total_rows && progress.read_rows) { double estimated_execution_time_seconds = elapsed_seconds * (static_cast(total_rows) / progress.read_rows); diff --git a/dbms/tests/queries/0_stateless/00976_max_execution_speed.reference b/dbms/tests/queries/0_stateless/00976_max_execution_speed.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dbms/tests/queries/0_stateless/00976_max_execution_speed.sql b/dbms/tests/queries/0_stateless/00976_max_execution_speed.sql new file mode 100644 index 00000000000..06386d77413 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00976_max_execution_speed.sql @@ -0,0 +1,2 @@ +SET max_execution_speed = 1, max_execution_time = 3; +SELECT count() FROM system.numbers; -- { serverError 159 }