diff --git a/src/Processors/IProcessor.h b/src/Processors/IProcessor.h index 1ef2269e8df..9d885002cfe 100644 --- a/src/Processors/IProcessor.h +++ b/src/Processors/IProcessor.h @@ -320,7 +320,7 @@ public: const StorageLimitsList & limits; }; - /// Set limits fro current storage. + /// Set limits for current storage. /// Different limits may be applied to different storages, we need to keep it per processor. /// This method is need to be override only for sources. virtual void setStorageLimits(const std::shared_ptr & /*storage_limits*/) {} diff --git a/src/Processors/ISource.cpp b/src/Processors/ISource.cpp index 03300923a6f..8c3c0d3fd34 100644 --- a/src/Processors/ISource.cpp +++ b/src/Processors/ISource.cpp @@ -21,7 +21,7 @@ ISource::ISource(Block header, bool enable_auto_progress) ISource::Status ISource::prepare() { - if (finished || isCancelled()) + if (finished) { output.finish(); return Status::Finished; @@ -40,6 +40,12 @@ ISource::Status ISource::prepare() output.pushData(std::move(current_chunk)); has_input = false; + if (isCancelled()) + { + output.finish(); + return Status::Finished; + } + if (got_exception) { finished = true; diff --git a/src/QueryPipeline/SizeLimits.cpp b/src/QueryPipeline/SizeLimits.cpp index 3514d0a5e28..2fa11936547 100644 --- a/src/QueryPipeline/SizeLimits.cpp +++ b/src/QueryPipeline/SizeLimits.cpp @@ -35,9 +35,9 @@ bool SizeLimits::check(UInt64 rows, UInt64 bytes, const char * what, int too_man bool SizeLimits::softCheck(UInt64 rows, UInt64 bytes) const { - if (max_rows && rows > max_rows) + if (max_rows && rows >= max_rows) return false; - if (max_bytes && bytes > max_bytes) + if (max_bytes && bytes >= max_bytes) return false; return true; } diff --git a/tests/queries/0_stateless/02313_multiple_limits.reference b/tests/queries/0_stateless/02313_multiple_limits.reference index bcd839ee04a..878f1eacebe 100644 --- a/tests/queries/0_stateless/02313_multiple_limits.reference +++ b/tests/queries/0_stateless/02313_multiple_limits.reference @@ -1,2 +1,6 @@ 45 45 +20 +1 +20 +1 diff --git a/tests/queries/0_stateless/02313_multiple_limits.sql b/tests/queries/0_stateless/02313_multiple_limits.sql index 27a2ea4eacc..75850b64879 100644 --- a/tests/queries/0_stateless/02313_multiple_limits.sql +++ b/tests/queries/0_stateless/02313_multiple_limits.sql @@ -23,3 +23,84 @@ FROM ) SETTINGS max_rows_to_read = 10, read_overflow_mode = 'break', max_block_size = 2 ); + + +SELECT count() +FROM +( + SELECT x + FROM + ( + SELECT zero AS x + FROM system.zeros + SETTINGS max_block_size = 2, max_rows_to_read = 10, read_overflow_mode = 'break' + ) + UNION ALL + SELECT x + FROM + ( + SELECT zero + 1 AS x + FROM system.zeros + SETTINGS max_block_size = 2, max_rows_to_read = 20, read_overflow_mode = 'break' + ) +); + +SELECT sum(x) >= 10 +FROM +( + SELECT x + FROM + ( + SELECT zero AS x + FROM system.zeros + SETTINGS max_block_size = 2, max_rows_to_read = 10, read_overflow_mode = 'break' + ) + UNION ALL + SELECT x + FROM + ( + SELECT zero + 1 AS x + FROM system.zeros + SETTINGS max_block_size = 2, max_rows_to_read = 20, read_overflow_mode = 'break' + ) +); + +SELECT count() +FROM +( + SELECT x + FROM + ( + SELECT zero AS x + FROM system.zeros + SETTINGS max_block_size = 2, max_rows_to_read = 20, read_overflow_mode = 'break' + ) + UNION ALL + SELECT x + FROM + ( + SELECT zero + 1 AS x + FROM system.zeros + SETTINGS max_block_size = 2, max_rows_to_read = 10, read_overflow_mode = 'break' + ) +); + +SELECT sum(x) <= 10 +FROM +( + SELECT x + FROM + ( + SELECT zero AS x + FROM system.zeros + SETTINGS max_block_size = 2, max_rows_to_read = 20, read_overflow_mode = 'break' + ) + UNION ALL + SELECT x + FROM + ( + SELECT zero + 1 AS x + FROM system.zeros + SETTINGS max_block_size = 2, max_rows_to_read = 10, read_overflow_mode = 'break' + ) +);