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;