From 3e3738bd49f8028c756c6eb218f0f447ac71a0f5 Mon Sep 17 00:00:00 2001 From: Nikita Taranov Date: Sat, 10 Dec 2022 13:28:21 +0100 Subject: [PATCH] impl (#44051) --- src/Interpreters/ExpressionAnalyzer.cpp | 4 ++-- ...02497_having_without_actual_aggregation_bug.reference | 3 +++ .../02497_having_without_actual_aggregation_bug.sql | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/02497_having_without_actual_aggregation_bug.reference create mode 100644 tests/queries/0_stateless/02497_having_without_actual_aggregation_bug.sql diff --git a/src/Interpreters/ExpressionAnalyzer.cpp b/src/Interpreters/ExpressionAnalyzer.cpp index 84d1c3d9e8a..22229c0d6c2 100644 --- a/src/Interpreters/ExpressionAnalyzer.cpp +++ b/src/Interpreters/ExpressionAnalyzer.cpp @@ -254,7 +254,7 @@ void ExpressionAnalyzer::analyzeAggregation(ActionsDAGPtr & temp_actions) auto * select_query = query->as(); makeAggregateDescriptions(temp_actions, aggregate_descriptions); - has_aggregation = !aggregate_descriptions.empty() || (select_query && (select_query->groupBy() || select_query->having())); + has_aggregation = !aggregate_descriptions.empty() || (select_query && select_query->groupBy()); if (!has_aggregation) { @@ -411,7 +411,7 @@ void ExpressionAnalyzer::analyzeAggregation(ActionsDAGPtr & temp_actions) if (group_asts.empty()) { select_query->setExpression(ASTSelectQuery::Expression::GROUP_BY, {}); - has_aggregation = select_query->having() || !aggregate_descriptions.empty(); + has_aggregation = !aggregate_descriptions.empty(); } } diff --git a/tests/queries/0_stateless/02497_having_without_actual_aggregation_bug.reference b/tests/queries/0_stateless/02497_having_without_actual_aggregation_bug.reference new file mode 100644 index 00000000000..3a52d32f5de --- /dev/null +++ b/tests/queries/0_stateless/02497_having_without_actual_aggregation_bug.reference @@ -0,0 +1,3 @@ +9 +100 +10 diff --git a/tests/queries/0_stateless/02497_having_without_actual_aggregation_bug.sql b/tests/queries/0_stateless/02497_having_without_actual_aggregation_bug.sql new file mode 100644 index 00000000000..5ddd6119bbe --- /dev/null +++ b/tests/queries/0_stateless/02497_having_without_actual_aggregation_bug.sql @@ -0,0 +1,9 @@ +select number from numbers_mt(10) having number >= 9; + +select count() from numbers_mt(100) having count() > 1; + +select queryID() as t from numbers(10) with totals having t = initialQueryID(); -- { serverError 48 } + +-- this query works despite 'with total' doesn't make any sense due to this logic: +-- https://github.com/ClickHouse/ClickHouse/blob/master/src/Interpreters/InterpreterSelectQuery.cpp#L608-L610 +select count() from (select queryID() as t from remote('127.0.0.{1..3}', numbers(10)) with totals having t = initialQueryID()) settings prefer_localhost_replica = 1;