ISSUES-12513 try fix difference expressions with same alias

This commit is contained in:
zhang2014 2020-10-13 13:30:56 +08:00
parent 9808d0be81
commit d79d0127ad
2 changed files with 5 additions and 6 deletions

View File

@ -10,6 +10,7 @@
#include <Parsers/ASTTablesInSelectQuery.h>
#include <Parsers/IAST.h>
#include <Common/typeid_cast.h>
#include <Parsers/ASTSubquery.h>
namespace DB
{
@ -86,7 +87,7 @@ public:
static bool needChildVisit(const ASTPtr & node, const ASTPtr &)
{
return !(node->as<ASTFunction>());
return !node->as<ASTSubquery>() && !(node->as<ASTFunction>());
}
static void visit(ASTPtr & ast, Data & data)

View File

@ -269,7 +269,7 @@ void optimizeGroupByFunctionKeys(ASTSelectQuery * select_query)
}
/// Eliminates min/max/any-aggregators of functions of GROUP BY keys
void optimizeAggregateFunctionsOfGroupByKeys(ASTSelectQuery * select_query)
void optimizeAggregateFunctionsOfGroupByKeys(ASTSelectQuery * select_query, ASTPtr & node)
{
if (!select_query->groupBy())
return;
@ -279,10 +279,8 @@ void optimizeAggregateFunctionsOfGroupByKeys(ASTSelectQuery * select_query)
GroupByKeysInfo group_by_keys_data = getGroupByKeysInfo(group_keys);
auto select = select_query->select();
SelectAggregateFunctionOfGroupByKeysVisitor::Data visitor_data{group_by_keys_data.key_names};
SelectAggregateFunctionOfGroupByKeysVisitor(visitor_data).visit(select);
SelectAggregateFunctionOfGroupByKeysVisitor(visitor_data).visit(node);
}
/// Remove duplicate items from ORDER BY.
@ -647,7 +645,7 @@ void TreeOptimizer::apply(ASTPtr & query, Aliases & aliases, const NameSet & sou
/// Eliminate min/max/any aggregators of functions of GROUP BY keys
if (settings.optimize_aggregators_of_group_by_keys)
optimizeAggregateFunctionsOfGroupByKeys(select_query);
optimizeAggregateFunctionsOfGroupByKeys(select_query, query);
/// Remove duplicate items from ORDER BY.
optimizeDuplicatesInOrderBy(select_query);