```
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'. 
```
{
    CheckASTDepth scope1(data);
    RestoreAliasOnExitScope scope2(data.current_alias);
    auto & finished_asts = data.finished_asts;
    auto & current_asts = data.current_asts;
    if (finished_asts.count(ast))
    {
        ast = finished_asts[ast];
        return;
    }
    ASTPtr initial_ast = ast;
    current_asts.insert(initial_ast.get());
    {
        String my_alias = ast->tryGetAlias();
        if (!my_alias.empty())
            data.current_alias = my_alias;
    }
    if (auto * node_id = ast->as<ASTIdentifier>())
        visit(*node_id, ast, data);
    else if (auto * node_tables = ast->as<ASTTablesInSelectQueryElement>())
        visit(*node_tables, ast, data);