From d9a64d1f8675e81304b881eeae3ca2957e8d4cb0 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 14 Jan 2022 15:47:26 +0300 Subject: [PATCH] Fix optimize_aggregation_in_order in case of empty result set Note, that this is not complete fix, see the next two patches. Signed-off-by: Azat Khuzhin --- .../Transforms/MergingAggregatedTransform.cpp | 6 +++++- ...6_optimize_aggregation_in_order_empty.reference | 8 ++++++++ .../02176_optimize_aggregation_in_order_empty.sql | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/02176_optimize_aggregation_in_order_empty.reference create mode 100644 tests/queries/0_stateless/02176_optimize_aggregation_in_order_empty.sql diff --git a/src/Processors/Transforms/MergingAggregatedTransform.cpp b/src/Processors/Transforms/MergingAggregatedTransform.cpp index ddc58d830da..37419f55aae 100644 --- a/src/Processors/Transforms/MergingAggregatedTransform.cpp +++ b/src/Processors/Transforms/MergingAggregatedTransform.cpp @@ -23,7 +23,11 @@ void MergingAggregatedTransform::consume(Chunk chunk) LOG_TRACE(log, "Reading blocks of partially aggregated data."); } - total_input_rows += chunk.getNumRows(); + size_t input_rows = chunk.getNumRows(); + if (!input_rows) + return; + + total_input_rows += input_rows; ++total_input_blocks; const auto & info = chunk.getChunkInfo(); diff --git a/tests/queries/0_stateless/02176_optimize_aggregation_in_order_empty.reference b/tests/queries/0_stateless/02176_optimize_aggregation_in_order_empty.reference new file mode 100644 index 00000000000..645cec31b47 --- /dev/null +++ b/tests/queries/0_stateless/02176_optimize_aggregation_in_order_empty.reference @@ -0,0 +1,8 @@ +-- { echoOn } + +-- regression for optimize_aggregation_in_order with empty result set +-- that cause at first +-- "Chunk should have AggregatedChunkInfo in GroupingAggregatedTransform" +-- at first and after +-- "Chunk should have AggregatedChunkInfo in GroupingAggregatedTransform" +select count() from remote('127.{1,2}', currentDatabase(), data_02176) where key = 0 group by key settings optimize_aggregation_in_order=1; diff --git a/tests/queries/0_stateless/02176_optimize_aggregation_in_order_empty.sql b/tests/queries/0_stateless/02176_optimize_aggregation_in_order_empty.sql new file mode 100644 index 00000000000..a86fd4357c8 --- /dev/null +++ b/tests/queries/0_stateless/02176_optimize_aggregation_in_order_empty.sql @@ -0,0 +1,14 @@ +drop table if exists data_02176; +create table data_02176 (key Int) Engine=MergeTree() order by key; + +-- { echoOn } + +-- regression for optimize_aggregation_in_order with empty result set +-- that cause at first +-- "Chunk should have AggregatedChunkInfo in GroupingAggregatedTransform" +-- at first and after +-- "Chunk should have AggregatedChunkInfo in GroupingAggregatedTransform" +select count() from remote('127.{1,2}', currentDatabase(), data_02176) where key = 0 group by key settings optimize_aggregation_in_order=1; + +-- { echoOff } +drop table data_02176;