**How to reproduce**

CH version: `20.5.2 revision 54435` (latest on `apt` at the moment). Cannot reproduce on `20.4.5`, so it's a regression.

Table:

```sql
create table repro_hits (
    date Date,
    metric Float64
) engine=MergeTree() order by date
```

Query:

```sql
SELECT
    date as period,
    1 as having_check,
    min(date) as period_start,
    addDays(max(date), 1) as period_end,
    dateDiff('second', period_start, period_end) as total_duration,
    sum(metric) as metric_
FROM repro_hits
GROUP BY period
having having_check != -1
```

**Error message and/or stacktrace**
```
Received exception from server (version 20.5.2):
Code: 179. DB::Exception: Received from localhost:9000. DB::Exception: Different expressions with the same alias period_start:
min(date) AS period_start
and
date AS period_start
.
```

The error goes away if I opt out of optimization with `SETTINGS enable_optimize_predicate_expression = 0`.
{
    if (!select_query->join())
        return;
    const auto * table_join = select_query->join()->table_join->as<ASTTableJoin>();
    if (!(table_join && table_join->using_expression_list))
        return;
    ASTs & expression_list = table_join->using_expression_list->children;
    ASTs uniq_expressions_list;
    std::set<String> expressions_names;
    for (const auto & expression : expression_list)
    {
        auto expression_name = expression->getAliasOrColumnName();
        if (expressions_names.find(expression_name) == expressions_names.end())
        {
            uniq_expressions_list.push_back(expression);
            expressions_names.insert(expression_name);
        }
    }
    if (uniq_expressions_list.size() < expression_list.size())
        expression_list = uniq_expressions_list;
}
void optimizeAggregationFunctions(ASTPtr & query)
{
    
    ArithmeticOperationsInAgrFuncVisitor::Data data;
    ArithmeticOperationsInAgrFuncVisitor(data).visit(query);
}
void optimizeAnyFunctions(ASTPtr & query)