Reproducer: 
``` sql
SELECT count() FROM (SELECT queryID() AS t FROM remote('127.0.0.{1..3}', numbers(10)) WITH TOTALS HAVING t = initialQueryID())

Code: 49. DB::Exception: Received from localhost:9000. DB::Exception: Chunk info was not set for chunk in GroupingAggregatedTransform.. (LOGICAL_ERROR)
``` 
auto finalize_chain = [&](ExpressionActionsChain & chain)
    {
        if (prewhere_step_num >= 0)
        {
            ExpressionActionsChain::Step & step = *chain.steps.at(prewhere_step_num);
            auto required_columns = prewhere_info->prewhere_actions->getRequiredColumnsNames();
            NameSet required_source_columns(required_columns.begin(), required_columns.end());
            
            
            for (const auto & column : additional_required_columns_after_prewhere)
            {
                if (required_source_columns.contains(column))
                    step.addRequiredOutput(column);
            }
        }
        chain.finalize();
        finalize(chain, prewhere_step_num, where_step_num, having_step_num, query);
        chain.clear();
    };
    {
        ExpressionActionsChain chain(context);
        if (storage && (query.sampleSize() || settings.parallel_replicas_count > 1))
        {
            
            if (storage->getName() == "Merge")
            {
                const auto columns = metadata_snapshot->getColumns().getAll();
                for (const auto & column : columns)
                {
                    additional_required_columns_after_prewhere.push_back(column.name);