From 852d35615c1581e8867cf73a70ae20f34c7f5664 Mon Sep 17 00:00:00 2001 From: Michael Kolupaev Date: Thu, 27 Mar 2014 23:47:51 +0400 Subject: [PATCH] dbms: Fixed a bug. [#METR-10615] --- dbms/include/DB/Parsers/ASTSelectQuery.h | 11 ++++++++++- dbms/src/Interpreters/InterpreterSelectQuery.cpp | 8 ++++---- .../0_stateless/00023_agg_select_agg_subquery.sql | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dbms/include/DB/Parsers/ASTSelectQuery.h b/dbms/include/DB/Parsers/ASTSelectQuery.h index 9b1bc0bed99..e9e65e3d714 100644 --- a/dbms/include/DB/Parsers/ASTSelectQuery.h +++ b/dbms/include/DB/Parsers/ASTSelectQuery.h @@ -60,7 +60,16 @@ public: DB::ErrorCodes::UNKNOWN_IDENTIFIER); } - select_expression_list.swap(result); + + for (auto & child : children) + { + if (child == select_expression_list) + { + child = result; + break; + } + } + select_expression_list = result; } ASTPtr clone() const diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index dbf8c7c2829..53bdb5308d7 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -104,13 +104,13 @@ InterpreterSelectQuery::InterpreterSelectQuery(ASTPtr query_ptr_, const Context context(context_), settings(context.getSettings()), to_stage(to_stage_), subquery_depth(subquery_depth_), log(&Logger::get("InterpreterSelectQuery")) { - init(input_); - /** Оставляем в запросе в секции SELECT только нужные столбцы. * Но если используется DISTINCT, то все столбцы считаются нужными, так как иначе DISTINCT работал бы по-другому. */ if (!query.distinct) query.rewriteSelectExpressionList(required_column_names_); + + init(input_); } InterpreterSelectQuery::InterpreterSelectQuery(ASTPtr query_ptr_, const Context & context_, const Names & required_column_names_, @@ -119,13 +119,13 @@ InterpreterSelectQuery::InterpreterSelectQuery(ASTPtr query_ptr_, const Context context(context_), settings(context.getSettings()), to_stage(to_stage_), subquery_depth(subquery_depth_), log(&Logger::get("InterpreterSelectQuery")) { - init(input_, table_column_names); - /** Оставляем в запросе в секции SELECT только нужные столбцы. * Но если используется DISTINCT, то все столбцы считаются нужными, так как иначе DISTINCT работал бы по-другому. */ if (!query.distinct) query.rewriteSelectExpressionList(required_column_names_); + + init(input_, table_column_names); } void InterpreterSelectQuery::getDatabaseAndTableNames(String & database_name, String & table_name) diff --git a/dbms/tests/queries/0_stateless/00023_agg_select_agg_subquery.sql b/dbms/tests/queries/0_stateless/00023_agg_select_agg_subquery.sql index 398b4ff8b89..bb63f3b9d71 100644 --- a/dbms/tests/queries/0_stateless/00023_agg_select_agg_subquery.sql +++ b/dbms/tests/queries/0_stateless/00023_agg_select_agg_subquery.sql @@ -1 +1 @@ -SELECT count() FROM (SELECT sum(1), sum(2)) +SELECT count() FROM (SELECT sum(materialize(1)), sum(materialize(2)))