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

```

}
                if (elem.read_rows != 0)
                {
                    LOG_INFO(&Poco::Logger::get("executeQuery"), "Read {} rows, {} in {} sec., {} rows/sec., {}/sec.",
                        elem.read_rows, ReadableSize(elem.read_bytes), elapsed_seconds,
                        static_cast<size_t>(elem.read_rows / elapsed_seconds),
                        ReadableSize(elem.read_bytes / elapsed_seconds));
                }
                elem.thread_ids = std::move(info.thread_ids);
                elem.profile_counters = std::move(info.profile_counters);
                const auto & factories_info = context.getQueryFactoriesInfo();
                elem.used_aggregate_functions = factories_info.aggregate_functions;
                elem.used_aggregate_function_combinators = factories_info.aggregate_function_combinators;
                elem.used_database_engines = factories_info.database_engines;
                elem.used_data_type_families = factories_info.data_type_families;
                elem.used_dictionaries = factories_info.dictionaries;
                elem.used_formats = factories_info.formats;
                elem.used_functions = factories_info.functions;
                elem.used_storages = factories_info.storages;
                elem.used_table_functions = factories_info.table_functions;
                if (log_queries && elem.type >= log_queries_min_type && Int64(elem.query_duration_ms) >= log_queries_min_query_duration_ms)
                {
                    if (auto query_log = context.getQueryLog())
                        query_log->add(elem);
                }
                if (auto opentelemetry_span_log = context.getOpenTelemetrySpanLog();
                    context.query_trace_context.trace_id
                        && opentelemetry_span_log)
                {
                    OpenTelemetrySpanLogElement span;