mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
ISSUES-12513 try fix difference expressions with same alias
This commit is contained in:
parent
9808d0be81
commit
d79d0127ad
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user