**Describe the bug**
Clickhouse seems to be unable to find the source for a column for the aggregation function for a column where the name is ambigious but specified with alias.

**How to reproduce**
* Which ClickHouse server version to use: 20.5.2.7
* Which interface to use, if matters: HTTP (but should not matter)
* Non-default settings, if any: None that I am aware of

```sql
CREATE TABLE `source` (
	`key` FixedString(15),
	`name` Int8,
	`value` Int8
) ENGINE = Log();

CREATE TABLE `target` (
	`key` FixedString(15),
	`name` Int8,
	`flower` Int8
) ENGINE = Log();

-- Query 1: Exception
SELECT 
	`source`.`key`,
	max(dummy.`key`)
FROM `source`
INNER JOIN (
	SELECT `key`, name, flower FROM `target`
) AS dummy ON `source`.name = dummy.name
GROUP BY `source`.`key`;

-- Query 2: Working
SELECT 
	`source`.`key`,
	max(dummy.`key2`)
FROM `source`
INNER JOIN (
	SELECT `key` as `key2`, name, flower FROM `target`
) AS dummy ON `source`.name = dummy.name
GROUP BY `source`.`key`
```

**Expected behavior**
Clickhouse should be able to distinguish between the the column `source.key` that is used in the `GROUP BY` statement and the column `dummy.key` (or `target.key`).

**Error message and/or stacktrace**
When running the first query, the following exception is returned from the database:
```
ClickHouse exception, code: 10, host: my.clickhouse.host, port: 8080; Code: 10, e.displayText() = DB::Exception: Not found column dummy.key in block. There are only columns: key (version 20.5.2.7 (official build))
```

**Additional context**
As you can see in the second query, if you remove any ambigious columns from the `SELECT` part, the problem seems to be gone.
This may be related to https://github.com/ClickHouse/ClickHouse/issues/12601

auto hash = elem->getTreeHash();
            String key = toString(hash.first) + '_' + toString(hash.second);
            group_by_hashes.insert(key);
        }
    }
    bool is_sorting_key_prefix = true;
    for (size_t i = 0; i < order_by->children.size(); ++i)
    {
        auto * order_by_element = order_by->children[i]->as<ASTOrderByElement>();
        auto & ast_func = order_by_element->children[0];
        if (!ast_func->as<ASTFunction>())
            continue;
        if (i >= sorting_key_columns.size() || ast_func->getColumnName() != sorting_key_columns[i])
            is_sorting_key_prefix = false;
        
        
        if (is_sorting_key_prefix)
            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)