diff --git a/dbms/include/DB/Interpreters/InterpreterSelectQuery.h b/dbms/include/DB/Interpreters/InterpreterSelectQuery.h index b501043f1a7..e0707951674 100644 --- a/dbms/include/DB/Interpreters/InterpreterSelectQuery.h +++ b/dbms/include/DB/Interpreters/InterpreterSelectQuery.h @@ -123,6 +123,8 @@ private: void executeDistinct( BlockInputStreams & streams, bool before_order, Names columns); void executeSubqueriesInSetsAndJoins(BlockInputStreams & streams, SubqueriesForSets & subqueries_for_sets); + void ignoreWithTotals() { query.group_by_with_totals = false; } + ASTPtr query_ptr; ASTSelectQuery & query; Context context; diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index 8bd7ab4fa10..59db50b0853 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -610,6 +610,8 @@ QueryProcessingStage::Enum InterpreterSelectQuery::executeFetchColumns(BlockInpu interpreter_subquery = new InterpreterSelectQuery( query.table, subquery_context, required_columns, QueryProcessingStage::Complete, subquery_depth + 1); + if (query_analyzer->hasAggregation()) + interpreter_subquery->ignoreWithTotals(); } /// если в настройках установлен default_sample != 1, то все запросы выполняем с сэмплингом diff --git a/dbms/tests/queries/0_stateless/00152_totals_in_subquery.reference b/dbms/tests/queries/0_stateless/00152_totals_in_subquery.reference new file mode 100644 index 00000000000..c2c31d6422c --- /dev/null +++ b/dbms/tests/queries/0_stateless/00152_totals_in_subquery.reference @@ -0,0 +1,4 @@ +1 +0 0 + +0 0 diff --git a/dbms/tests/queries/0_stateless/00152_totals_in_subquery.sql b/dbms/tests/queries/0_stateless/00152_totals_in_subquery.sql new file mode 100644 index 00000000000..0dbb589d059 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00152_totals_in_subquery.sql @@ -0,0 +1,2 @@ +SELECT count() FROM (SELECT dummy, sum(dummy) GROUP BY dummy WITH TOTALS); +SELECT * FROM (SELECT dummy, sum(dummy) GROUP BY dummy WITH TOTALS);