mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 04:12:19 +00:00
Allow optimize_arithmetic_operations_in_aggregate_functions when alias is used.
This commit is contained in:
parent
f2d97e3225
commit
f4269ce417
@ -107,10 +107,7 @@ ASTPtr tryExchangeFunctions(const ASTFunction & func)
|
|||||||
|| !supported.find(lower_name)->second.count(child_func->name))
|
|| !supported.find(lower_name)->second.count(child_func->name))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
/// Cannot rewrite function with alias cause alias could become undefined
|
auto original_alias = func.tryGetAlias();
|
||||||
if (!func.tryGetAlias().empty() || !child_func->tryGetAlias().empty())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
const auto & child_func_args = child_func->arguments->children;
|
const auto & child_func_args = child_func->arguments->children;
|
||||||
const auto * first_literal = child_func_args[0]->as<ASTLiteral>();
|
const auto * first_literal = child_func_args[0]->as<ASTLiteral>();
|
||||||
const auto * second_literal = child_func_args[1]->as<ASTLiteral>();
|
const auto * second_literal = child_func_args[1]->as<ASTLiteral>();
|
||||||
@ -132,7 +129,12 @@ ASTPtr tryExchangeFunctions(const ASTFunction & func)
|
|||||||
optimized_ast = exchangeExtractSecondArgument(new_name, *child_func);
|
optimized_ast = exchangeExtractSecondArgument(new_name, *child_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
return optimized_ast;
|
if (optimized_ast)
|
||||||
|
{
|
||||||
|
optimized_ast->setAlias(original_alias);
|
||||||
|
return optimized_ast;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
SELECT min(n AS a) + (1 AS b) AS c
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT number AS n
|
||||||
|
FROM numbers(10)
|
||||||
|
WHERE (1 > 0) AND (n > 0)
|
||||||
|
)
|
||||||
|
WHERE (a > 0) AND (b > 0)
|
||||||
|
HAVING c > 0
|
||||||
|
2
|
@ -0,0 +1,4 @@
|
|||||||
|
set optimize_arithmetic_operations_in_aggregate_functions = 1;
|
||||||
|
|
||||||
|
explain syntax select min((n as a) + (1 as b)) c from (select number n from numbers(10)) where a > 0 and b > 0 having c > 0;
|
||||||
|
select min((n as a) + (1 as b)) c from (select number n from numbers(10)) where a > 0 and b > 0 having c > 0;
|
@ -54,8 +54,8 @@ SELECT
|
|||||||
sum(k)
|
sum(k)
|
||||||
FROM columns_transformers
|
FROM columns_transformers
|
||||||
SELECT
|
SELECT
|
||||||
avg(i + 1 AS i),
|
avg(i) + 1,
|
||||||
avg(j + 2 AS j),
|
avg(j) + 2,
|
||||||
avg(k)
|
avg(k)
|
||||||
FROM columns_transformers
|
FROM columns_transformers
|
||||||
SELECT
|
SELECT
|
||||||
|
Loading…
Reference in New Issue
Block a user