Some aggregate functions are commutative with some arithmetic expressions.

```
avg(x + const) = avg(x) + const
```

This is applicable for aggregate functions: `sum`, `avg`, `min`, `max` and operations: `+`, `-`, `*`, `/` (but not for `intDiv` and `modulo`).

In case of integer overflow it either works correctly (for `sum`) or we may assume that integer overflow is implementation specific behaviour and apply optimization under this assumption.

**Possible implementation**

AST rewrite with InDepthNodeVisitor.
Should not rewrite if expression has alias.
optimized_ast = exchangeExtractSecondArgument(new_name, *child_func);
    }
    return optimized_ast;
}
}
void ArithmeticOperationsInAgrFuncMatcher::visit(const ASTFunction & func, ASTPtr & ast, Data & data)
{
    if (auto exchanged_funcs = tryExchangeFunctions(func))
    {
        ast = exchanged_funcs;
        
        
        
        auto & expression_list = ast->children[0];
        visit(expression_list->children[0], data);
    }
}
void ArithmeticOperationsInAgrFuncMatcher::visit(ASTPtr & ast, Data & data)
{
    if (const auto * function_node = ast->as<ASTFunction>())
        visit(*function_node, ast, data);
}
bool ArithmeticOperationsInAgrFuncMatcher::needChildVisit(const ASTPtr & node, const ASTPtr &)
{
    return !node->as<ASTSubquery>() &&
        !node->as<ASTTableExpression>() &&
        !node->as<ASTArrayJoin>();
}
}