```
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?
#include <Functions/IFunctionImpl.h>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionHelpers.h>
#include <DataTypes/DataTypeAggregateFunction.h>
#include <Columns/ColumnAggregateFunction.h>
#include <Common/typeid_cast.h>
namespace DB
{
namespace ErrorCodes
{
    extern const int ILLEGAL_COLUMN;
    extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
namespace
{
/** finalizeAggregation(agg_state) - get the result from the aggregation state.
  * Takes state of aggregate function. Returns result of aggregation (finalized state).
  */
class FunctionFinalizeAggregation : public IFunction