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)
``` 
Block before_where_sample;
                if (chain.steps.size() > 1)
                    before_where_sample = Block(chain.steps[chain.steps.size() - 2]->getResultColumns());
                else
                    before_where_sample = source_header;
                if (sanitizeBlock(before_where_sample))
                {
                    ExpressionActions(
                        before_where,
                        ExpressionActionsSettings::fromSettings(context->getSettingsRef())).execute(before_where_sample);
                    auto & column_elem = before_where_sample.getByName(query.where()->getColumnName());
                    
                    if (column_elem.column)
                        where_constant_filter_description = ConstantFilterDescription(*column_elem.column);
                }
            }
            chain.addStep();
        }
        if (need_aggregate)
        {
            
            optimize_aggregation_in_order =
                    context->getSettingsRef().optimize_aggregation_in_order
                    && (!context->getSettingsRef().query_plan_aggregation_in_order)
                    && storage && query.groupBy();
            query_analyzer.appendGroupBy(chain, only_types || !first_stage, optimize_aggregation_in_order, group_by_elements_actions);
            query_analyzer.appendAggregateFunctionsArguments(chain, only_types || !first_stage);
            before_aggregation = chain.getLastActions();
            if (settings.group_by_use_nulls)
                query_analyzer.appendGroupByModifiers(before_aggregation, chain, only_types);