mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Followup to 57853
This commit is contained in:
parent
4d6ef8ed86
commit
3d0e915088
@ -10,14 +10,6 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
/** Rewrites `sum(column +/- literal)` into two individual functions
|
||||
* `sum(column)` and `literal * count(column)`.
|
||||
* sum(column + literal) -> sum(column) + literal * count(column)
|
||||
* sum(literal + column) -> literal * count(column) + sum(column)
|
||||
* sum(column - literal) -> sum(column) - literal * count(column)
|
||||
* sum(literal - column) -> literal * count(column) - sum(column)
|
||||
*/
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@ -29,6 +21,9 @@ public:
|
||||
|
||||
void enterImpl(QueryTreeNodePtr & node)
|
||||
{
|
||||
if (!getSettings().optimize_arithmetic_operations_in_aggregate_functions)
|
||||
return;
|
||||
|
||||
static const std::unordered_set<String> func_supported = {
|
||||
"plus",
|
||||
"minus"
|
||||
|
@ -5,6 +5,14 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
/**
|
||||
* Rewrites `sum(column +/- literal)` into two individual functions
|
||||
* `sum(column)` and `literal * count(column)`.
|
||||
* sum(column + literal) -> sum(column) + literal * count(column)
|
||||
* sum(literal + column) -> literal * count(column) + sum(column)
|
||||
* sum(column - literal) -> sum(column) - literal * count(column)
|
||||
* sum(literal - column) -> literal * count(column) - sum(column)
|
||||
*/
|
||||
class RewriteSumFunctionWithSumAndCountPass final : public IQueryTreePass
|
||||
{
|
||||
public:
|
||||
|
@ -752,7 +752,8 @@ void TreeOptimizer::apply(ASTPtr & query, TreeRewriterResult & result,
|
||||
}
|
||||
|
||||
/// Rewrite sum(column +/- literal) function with sum(column) +/- literal * count(column).
|
||||
rewriteSumFunctionWithSumAndCount(query, tables_with_columns);
|
||||
if (settings.optimize_arithmetic_operations_in_aggregate_functions)
|
||||
rewriteSumFunctionWithSumAndCount(query, tables_with_columns);
|
||||
|
||||
/// Rewrite date filters to avoid the calls of converters such as toYear, toYYYYMM, etc.
|
||||
optimizeDateFilters(select_query, tables_with_columns, context);
|
||||
|
Loading…
Reference in New Issue
Block a user