diff --git a/dbms/src/Parsers/ASTSubquery.cpp b/dbms/src/Parsers/ASTSubquery.cpp index 2db425a8c59..7b90b8a931b 100644 --- a/dbms/src/Parsers/ASTSubquery.cpp +++ b/dbms/src/Parsers/ASTSubquery.cpp @@ -6,6 +6,10 @@ namespace DB String ASTSubquery::getColumnNameImpl() const { + /// This is a hack. We use alias, if available, because otherwise tree could change during analysis. + if (!alias.empty()) + return alias; + Hash hash = getTreeHash(); return "__subquery_" + toString(hash.first) + "_" + toString(hash.second); }