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

```

String query_table;
    try
    {
#if !defined(ARCADIA_BUILD)
        if (settings.use_antlr_parser)
        {
            ast = parseQuery(begin, end, max_query_size, settings.max_parser_depth, context.getCurrentDatabase());
        }
        else
        {
            ParserQuery parser(end);
            
            ast = parseQuery(parser, begin, end, "", max_query_size, settings.max_parser_depth);
        }
#else
        ParserQuery parser(end);
        
        ast = parseQuery(parser, begin, end, "", max_query_size, settings.max_parser_depth);
#endif
        
        
        if (const auto * select_query = ast->as<ASTSelectQuery>())
        {
            if (auto new_settings = select_query->settings())
                InterpreterSetQuery(new_settings, context).executeForCurrentContext();
        }
        else if (const auto * select_with_union_query = ast->as<ASTSelectWithUnionQuery>())
        {
            if (!select_with_union_query->list_of_selects->children.empty())
            {