**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 (!order_by)
        return;
    std::unordered_set<String> group_by_hashes;
    if (auto group_by = select_query->groupBy())
    {
        for (auto & elem : group_by->children)
        {
            auto hash = elem->getTreeHash();
            String key = toString(hash.first) + '_' + toString(hash.second);
            group_by_hashes.insert(key);
        }
    }
    for (auto & child : order_by->children)
    {
        auto * order_by_element = child->as<ASTOrderByElement>();
        auto & ast_func = order_by_element->children[0];
        if (!ast_func->as<ASTFunction>())
            continue;
        MonotonicityCheckVisitor::Data data{tables_with_columns, context, group_by_hashes};
        MonotonicityCheckVisitor(data).visit(ast_func);
        if (!data.isRejected())
        {
            ast_func = data.identifier->clone();
            ast_func->setAlias("");
            if (!data.monotonicity.is_positive)
                order_by_element->direction *= -1;
        }
    }
}
void optimizeRedundantFunctionsInOrderBy(const ASTSelectQuery * select_query, const Context & context)