From 5271a45625e84df0bae03c4b02a36d707fd4a9fa Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 1 Feb 2015 10:20:33 +0300 Subject: [PATCH] dbms: fixed error with JOINs [#METR-14847]. --- dbms/include/DB/Interpreters/ExpressionAnalyzer.h | 7 ------- dbms/src/Interpreters/ExpressionAnalyzer.cpp | 6 +++--- .../00122_join_with_subquery_with_subquery.reference | 1 + .../0_stateless/00122_join_with_subquery_with_subquery.sql | 1 + 4 files changed, 5 insertions(+), 10 deletions(-) create mode 100644 dbms/tests/queries/0_stateless/00122_join_with_subquery_with_subquery.reference create mode 100644 dbms/tests/queries/0_stateless/00122_join_with_subquery_with_subquery.sql diff --git a/dbms/include/DB/Interpreters/ExpressionAnalyzer.h b/dbms/include/DB/Interpreters/ExpressionAnalyzer.h index aaca96438a5..c4b01ffe0ba 100644 --- a/dbms/include/DB/Interpreters/ExpressionAnalyzer.h +++ b/dbms/include/DB/Interpreters/ExpressionAnalyzer.h @@ -45,13 +45,6 @@ typedef std::unordered_map SubqueriesForSets; class ExpressionAnalyzer : private boost::noncopyable { public: - ExpressionAnalyzer(const ASTPtr & ast_, const Context & context_, size_t subquery_depth_ = 0, bool do_global_ = false) - : ast(ast_), context(context_), settings(context.getSettings()), - subquery_depth(subquery_depth_), columns(context.getColumns()), storage(getTable()), do_global(do_global_) - { - init(); - } - ExpressionAnalyzer(const ASTPtr & ast_, const Context & context_, StoragePtr storage_, size_t subquery_depth_ = 0, bool do_global_ = false) : ast(ast_), context(context_), settings(context.getSettings()), subquery_depth(subquery_depth_), columns(context.getColumns()), storage(storage_ ? storage_ : getTable()), do_global(do_global_) diff --git a/dbms/src/Interpreters/ExpressionAnalyzer.cpp b/dbms/src/Interpreters/ExpressionAnalyzer.cpp index 9ebb555f976..5c51269dfcc 100644 --- a/dbms/src/Interpreters/ExpressionAnalyzer.cpp +++ b/dbms/src/Interpreters/ExpressionAnalyzer.cpp @@ -634,7 +634,7 @@ void ExpressionAnalyzer::addExternalStorage(ASTPtr & subquery_or_table_name) } } - SharedPtr interpreter = interpretSubquery(subquery_or_table_name, context, subquery_depth); + SharedPtr interpreter = interpretSubquery(subquery_or_table_name, context, subquery_depth + 1); Block sample = interpreter->getSampleBlock(); NamesAndTypesListPtr columns = new NamesAndTypesList(sample.getColumnsList()); @@ -1837,8 +1837,8 @@ void ExpressionAnalyzer::collectJoinedColumns(NameSet & joined_columns, NamesAnd } else if (typeid_cast(node.table.get())) { - const auto & table = node.table->children.at(0); - nested_result_sample = ExpressionAnalyzer(table, context, subquery_depth + 1).getSelectSampleBlock(); + const auto & subquery = node.table->children.at(0); + nested_result_sample = InterpreterSelectQuery(subquery, context, QueryProcessingStage::Complete, subquery_depth + 1).getSampleBlock(); } auto & keys = typeid_cast(*node.using_expr_list); diff --git a/dbms/tests/queries/0_stateless/00122_join_with_subquery_with_subquery.reference b/dbms/tests/queries/0_stateless/00122_join_with_subquery_with_subquery.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00122_join_with_subquery_with_subquery.reference @@ -0,0 +1 @@ +1 diff --git a/dbms/tests/queries/0_stateless/00122_join_with_subquery_with_subquery.sql b/dbms/tests/queries/0_stateless/00122_join_with_subquery_with_subquery.sql new file mode 100644 index 00000000000..ef16a8ac58b --- /dev/null +++ b/dbms/tests/queries/0_stateless/00122_join_with_subquery_with_subquery.sql @@ -0,0 +1 @@ +SELECT 1 AS k ANY LEFT JOIN (SELECT k FROM (SELECT 1 AS k, 2 AS x)) USING k;