How to reproduce:

```sql
EXPLAIN SYNTAX
SELECT x
FROM 
(
    SELECT 1 AS x
    UNION DISTINCT
    SELECT 1
)

Query id: e777bc02-5d1b-4d49-ba89-4ebe31172387


Exception on client:
Code: 32. DB::Exception: Attempt to read after eof: while receiving packet from localhost:9000

```

}
                distinct_list->union_mode = ASTSelectWithUnionQuery::Mode::DISTINCT;
                distinct_list->is_normalized = true;
                selects.push_back(std::move(distinct_list));
                break;
            }
        }
        
        if (i == -1)
        {
            if (auto * inner_union = select_list[0]->as<ASTSelectWithUnionQuery>())
            {
                
                for (auto child = inner_union->list_of_selects->children.rbegin(); child != inner_union->list_of_selects->children.rend();
                     ++child)
                    selects.push_back(std::move(*child));
            }
            else
                selects.push_back(std::move(select_list[0]));
        }
        
        std::reverse(selects.begin(), selects.end());
        ast.is_normalized = true;
        ast.union_mode = ASTSelectWithUnionQuery::Mode::ALL;
        ast.list_of_selects->children = std::move(selects);
    }
};
using CustomizeASTSelectWithUnionQueryNormalizeVisitor
    = InDepthNodeVisitor<OneTypeMatcher<CustomizeASTSelectWithUnionQueryNormalize>, false>;
InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(