```
DROP TABLE IF EXISTS test_push_down;

CREATE TABLE test_push_down
ENGINE = AggregatingMergeTree
ORDER BY n AS
SELECT 
    intDiv(number, 25) AS n, 
    avgState(number) AS s
FROM numbers(2500)
GROUP BY n;

SET enable_debug_queries = 1;

ANALYZE SELECT *
FROM 
(
    SELECT 
        n, 
        finalizeAggregation(s)
    FROM test_push_down
)
WHERE (n >= 2) AND (n <= 5)
```

Result is 
```
SELECT 
    n, 
    `finalizeAggregation(s)`
FROM 
(
    SELECT 
        n, 
        finalizeAggregation(s)
    FROM test_push_down
)
WHERE (n >= 2) AND (n <= 5)
```

W/o `finalizeAggregation` - it was pushed down:
```
ANALYZE SELECT *
FROM 
(
    SELECT 
        n, 
        s
    FROM test_push_down
)
WHERE (n >= 2) AND (n <= 5)
```

```
SELECT 
    n, 
    s
FROM 
(
    SELECT 
        n, 
        s
    FROM test_push_down
    WHERE (n <= 5) AND (n >= 2)
)
WHERE (n >= 2) AND (n <= 5)
```

It looks like the reason is finalizeAggregation is marked as 'stateful' and for stateful functions

https://github.com/ClickHouse/ClickHouse/blob/89e967333662c8ec4c46dfa1ba12bd10781538b9/src/Interpreters/PredicateExpressionsOptimizer.cpp#L93-L94

https://github.com/ClickHouse/ClickHouse/blob/e4689ce302524e73477bff25370a2da67034b4ef/src/Functions/finalizeAggregation.cpp#L36-L39

Introduced in https://github.com/ClickHouse/ClickHouse/pull/3890

@zhang2014 is there some good reason why `finalizeAggregation` is marked as statefull?
{
public:
    static constexpr auto name = "finalizeAggregation";
    static FunctionPtr create(const Context &)
    {
        return std::make_shared<FunctionFinalizeAggregation>();
    }
    String getName() const override
    {
        return name;
    }
    bool isStateful() const override
    {
        return true;
    }
    size_t getNumberOfArguments() const override
    {
        return 1;
    }
    bool useDefaultImplementationForConstants() const override { return true; }
    DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override