```
CREATE TABLE a
(
    `number` UInt64,
    `x` MATERIALIZED x
)
ENGINE = MergeTree
ORDER BY number;
-- that should fail!

insert into a values (1);
Received exception from server (version 21.7.1):
Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Missing columns: 'x' while processing query: 'CAST(x, 'UInt8') AS x', required columns: 'x' 'x'. 
```
{
    ASTs & elements = select_query->select()->children;
    std::set<String> all_column_names;
    std::set<String> assigned_column_names;
    for (auto & expr : elements)
        all_column_names.insert(expr->getAliasOrColumnName());
    for (auto & expr : elements)
    {
        auto name = expr->getAliasOrColumnName();
        if (!assigned_column_names.insert(name).second)
        {
            size_t i = 1;
            while (all_column_names.end() != all_column_names.find(name + "_" + toString(i)))
                ++i;
            name = name + "_" + toString(i);
            expr = expr->clone();   
            expr->setAlias(name);
            all_column_names.insert(name);
            assigned_column_names.insert(name);
        }
    }
}
void removeUnneededColumnsFromSelectClause(const ASTSelectQuery * select_query, const Names & required_result_columns, bool remove_dups)