**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`.
const std::vector<TableWithColumnNamesAndTypes> & tables_with_columns,
                          const Context & context, bool & rewrite_subqueries)
{
    const auto & settings = context.getSettingsRef();
    auto * select_query = query->as<ASTSelectQuery>();
    if (!select_query)
        throw Exception("Select analyze for not select asts.", ErrorCodes::LOGICAL_ERROR);
    optimizeIf(query, aliases, settings.optimize_if_chain_to_multiif);
    
    if (settings.optimize_arithmetic_operations_in_aggregate_functions)
        optimizeAggregationFunctions(query);
    
    rewrite_subqueries = PredicateExpressionsOptimizer(context, tables_with_columns, settings).optimize(*select_query);
    
    optimizeGroupBy(select_query, source_columns_set, context);
    
    if (settings.optimize_group_by_function_keys)
        optimizeGroupByFunctionKeys(select_query);
    
    if (settings.optimize_move_functions_out_of_any)
        optimizeAnyFunctions(query);
    
    if (settings.optimize_injective_functions_inside_uniq)
        optimizeInjectiveFunctionsInsideUniq(query, context);