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.
#include <unordered_set>
#include <Common/typeid_cast.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTSubquery.h>
#include <Parsers/ASTTablesInSelectQuery.h>
#include <Interpreters/ArithmeticOperationsInAgrFuncOptimize.h>
namespace DB
{
namespace ErrorCodes
{
    extern const int BAD_TYPE_OF_FIELD;
}
namespace
{
const ASTFunction * getInternalFunction(const ASTFunction & func)