See https://github.com/ClickHouse/ClickHouse/pull/13193
{
    if (!merge_sorter)
    {
        merge_sorter = std::make_unique<MergeSorter>(std::move(chunks), description, max_merged_block_size, limit);
        generated_prefix = true;
    }
    generated_chunk = merge_sorter->read();
    if (!generated_chunk)
    {
        merge_sorter.reset();
        if (tail_chunk)
            chunks.push_back(std::move(tail_chunk));
        stage = Stage::Consume;
    }
    else
        enrichChunkWithConstants(generated_chunk);
}
}