https://clickhouse-test-reports.s3.yandex.net/0/69404b759ab98128f50516a272ca31dc13fa8368/stress_test_(debug).html#fail1

```
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:06.152906 [ 8263 ] {788dc4a3-5ab9-4bd5-8693-4438dbd91e11} <Fatal> : Logical error: 'Chunk should have AggregatedChunkInfo in GroupingAggregatedTransform.'.
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:36.767383 [ 15974 ] {} <Fatal> BaseDaemon: ########################################
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:36.932802 [ 15974 ] {} <Fatal> BaseDaemon: (version 21.11.1.8562 (official build), build id: 0D50AE9688A7F71300689F198C2521D90CA836AE) (from thread 8263) (query_id: 788dc4a3-5ab9-4bd5-8693-4438dbd91e11) Received signal Aborted (6)
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:37.067901 [ 15974 ] {} <Fatal> BaseDaemon: 
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:37.102423 [ 15974 ] {} <Fatal> BaseDaemon: Stack trace: 0x7fb7a7bcf18b 0x7fb7a7bae859 0x14fa1518 0x14fa1622 0x22f43668 0x22f43454 0x22f44d2d 0x151d04be 0x22be085a 0x22be06ef 0x22be0c7a 0x22be3bad 0x22be4385 0x22be62bf 0x22be621d 0x22be61c1 0x22be60d2 0x22be5f9b 0x22be5e5d 0x22be5e1d 0x22be5df5 0x22be5dc0 0x14fee1a6 0x14fed235 0x1501928f 0x15020444 0x150203bd 0x150202e5 0x1501fc22 0x7fb7a7db1609 0x7fb7a7cab293
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:37.161248 [ 15974 ] {} <Fatal> BaseDaemon: 4. raise @ 0x4618b in /usr/lib/x86_64-linux-gnu/libc-2.31.so
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:37.174029 [ 15974 ] {} <Fatal> BaseDaemon: 5. abort @ 0x25859 in /usr/lib/x86_64-linux-gnu/libc-2.31.so
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:37.573910 [ 15974 ] {} <Fatal> BaseDaemon: 6. ./obj-x86_64-linux-gnu/../src/Common/Exception.cpp:53: DB::handle_error_code(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool, std::__1::vector<void*, std::__1::allocator<void*> > const&) @ 0x14fa1518 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:38.255961 [ 15974 ] {} <Fatal> BaseDaemon: 7. ./obj-x86_64-linux-gnu/../src/Common/Exception.cpp:60: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0x14fa1622 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:38.744746 [ 15974 ] {} <Fatal> BaseDaemon: 8. ./obj-x86_64-linux-gnu/../src/Processors/Transforms/MergingAggregatedMemoryEfficientTransform.cpp:255: DB::GroupingAggregatedTransform::addChunk(DB::Chunk, unsigned long) @ 0x22f43668 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:39.387636 [ 15974 ] {} <Fatal> BaseDaemon: 9. ./obj-x86_64-linux-gnu/../src/Processors/Transforms/MergingAggregatedMemoryEfficientTransform.cpp:48: DB::GroupingAggregatedTransform::readFromAllInputs() @ 0x22f43454 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:39.999449 [ 15974 ] {} <Fatal> BaseDaemon: 10. ./obj-x86_64-linux-gnu/../src/Processors/Transforms/MergingAggregatedMemoryEfficientTransform.cpp:138: DB::GroupingAggregatedTransform::prepare() @ 0x22f44d2d in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:41.543533 [ 15974 ] {} <Fatal> BaseDaemon: 11. ./obj-x86_64-linux-gnu/../src/Processors/IProcessor.h:186: DB::IProcessor::prepare(std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&) @ 0x151d04be in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:42.129600 [ 15974 ] {} <Fatal> BaseDaemon: 12. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:224: DB::PipelineExecutor::prepareProcessor(unsigned long, unsigned long, std::__1::queue<DB::ExecutingGraph::Node*, std::__1::deque<DB::ExecutingGraph::Node*, std::__1::allocator<DB::ExecutingGraph::Node*> > >&, std::__1::queue<DB::ExecutingGraph::Node*, std::__1::deque<DB::ExecutingGraph::Node*, std::__1::allocator<DB::ExecutingGraph::Node*> > >&, std::__1::unique_lock<std::__1::mutex>) @ 0x22be085a in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:42.822981 [ 15974 ] {} <Fatal> BaseDaemon: 13. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:197: DB::PipelineExecutor::tryAddProcessorToStackIfUpdated(DB::ExecutingGraph::Edge&, std::__1::queue<DB::ExecutingGraph::Node*, std::__1::deque<DB::ExecutingGraph::Node*, std::__1::allocator<DB::ExecutingGraph::Node*> > >&, std::__1::queue<DB::ExecutingGraph::Node*, std::__1::deque<DB::ExecutingGraph::Node*, std::__1::allocator<DB::ExecutingGraph::Node*> > >&, unsigned long) @ 0x22be06ef in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:43.508775 [ 15974 ] {} <Fatal> BaseDaemon: 14. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:294: DB::PipelineExecutor::prepareProcessor(unsigned long, unsigned long, std::__1::queue<DB::ExecutingGraph::Node*, std::__1::deque<DB::ExecutingGraph::Node*, std::__1::allocator<DB::ExecutingGraph::Node*> > >&, std::__1::queue<DB::ExecutingGraph::Node*, std::__1::deque<DB::ExecutingGraph::Node*, std::__1::allocator<DB::ExecutingGraph::Node*> > >&, std::__1::unique_lock<std::__1::mutex>) @ 0x22be0c7a in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:44.017858 [ 15974 ] {} <Fatal> BaseDaemon: 15. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:628: DB::PipelineExecutor::executeStepImpl(unsigned long, unsigned long, std::__1::atomic<bool>*) @ 0x22be3bad in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:44.356823 [ 15974 ] {} <Fatal> BaseDaemon: 16. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:487: DB::PipelineExecutor::executeSingleThread(unsigned long, unsigned long) @ 0x22be4385 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:44.871012 [ 15974 ] {} <Fatal> BaseDaemon: 17. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:790: DB::PipelineExecutor::executeImpl(unsigned long)::$_4::operator()() const @ 0x22be62bf in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:45.432703 [ 15974 ] {} <Fatal> BaseDaemon: 18. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/type_traits:3682: decltype(std::__1::forward<DB::PipelineExecutor::executeImpl(unsigned long)::$_4&>(fp)()) std::__1::__invoke_constexpr<DB::PipelineExecutor::executeImpl(unsigned long)::$_4&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&) @ 0x22be621d in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:46.021546 [ 15974 ] {} <Fatal> BaseDaemon: 19. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/tuple:1415: decltype(auto) std::__1::__apply_tuple_impl<DB::PipelineExecutor::executeImpl(unsigned long)::$_4&, std::__1::tuple<>&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&, std::__1::tuple<>&, std::__1::__tuple_indices<>) @ 0x22be61c1 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:49.085516 [ 15974 ] {} <Fatal> BaseDaemon: 20. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/tuple:1424: decltype(auto) std::__1::apply<DB::PipelineExecutor::executeImpl(unsigned long)::$_4&, std::__1::tuple<>&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&, std::__1::tuple<>&) @ 0x22be60d2 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:49.610809 [ 15974 ] {} <Fatal> BaseDaemon: 21. ./obj-x86_64-linux-gnu/../src/Common/ThreadPool.h:188: ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_4>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&&)::'lambda'()::operator()() @ 0x22be5f9b in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:50.310218 [ 15974 ] {} <Fatal> BaseDaemon: 22. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/type_traits:3676: decltype(std::__1::forward<DB::PipelineExecutor::executeImpl(unsigned long)::$_4>(fp)()) std::__1::__invoke<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_4>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&&)::'lambda'()&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&&) @ 0x22be5e5d in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:51.035590 [ 15974 ] {} <Fatal> BaseDaemon: 23. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/__functional_base:349: void std::__1::__invoke_void_return_wrapper<void>::__call<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_4>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&&)::'lambda'()&>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&&...) @ 0x22be5e1d in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:51.615419 [ 15974 ] {} <Fatal> BaseDaemon: 24. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:1608: std::__1::__function::__default_alloc_func<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_4>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&&)::'lambda'(), void ()>::operator()() @ 0x22be5df5 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:52.290903 [ 15974 ] {} <Fatal> BaseDaemon: 25. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:2089: void std::__1::__function::__policy_invoker<void ()>::__call_impl<std::__1::__function::__default_alloc_func<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PipelineExecutor::executeImpl(unsigned long)::$_4>(DB::PipelineExecutor::executeImpl(unsigned long)::$_4&&)::'lambda'(), void ()> >(std::__1::__function::__policy_storage const*) @ 0x22be5dc0 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:52.506679 [ 15974 ] {} <Fatal> BaseDaemon: 26. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:2221: std::__1::__function::__policy_func<void ()>::operator()() const @ 0x14fee1a6 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:52.655182 [ 15974 ] {} <Fatal> BaseDaemon: 27. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:2560: std::__1::function<void ()>::operator()() const @ 0x14fed235 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:52.839203 [ 15974 ] {} <Fatal> BaseDaemon: 28. ./obj-x86_64-linux-gnu/../src/Common/ThreadPool.cpp:274: ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0x1501928f in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:52.988693 [ 15974 ] {} <Fatal> BaseDaemon: 29. ./obj-x86_64-linux-gnu/../src/Common/ThreadPool.cpp:139: void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda0'()::operator()() const @ 0x15020444 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:53.143210 [ 15974 ] {} <Fatal> BaseDaemon: 30. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/type_traits:3676: decltype(std::__1::forward<void>(fp)(std::__1::forward<void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda0'()>(fp0)...)) std::__1::__invoke<void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda0'()>(void&&, void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda0'()&&...) @ 0x150203bd in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:53.391058 [ 15974 ] {} <Fatal> BaseDaemon: 31. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/thread:281: void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda0'()>(std::__1::tuple<void, void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda0'()>&, std::__1::__tuple_indices<>) @ 0x150202e5 in /usr/bin/clickhouse
/var/log/clickhouse-server/clickhouse-server.log.2:2021.10.26 16:55:55.255281 [ 510 ] {} <Fatal> Application: Child process was terminated by signal 6.
```
{
    auto & output = outputs.front();
    auto info = std::make_shared<ChunksToMerge>();
    info->bucket_num = bucket;
    info->is_overflows = is_overflows;
    info->chunks = std::make_unique<Chunks>(std::move(chunks));
    Chunk chunk;
    chunk.setChunkInfo(std::move(info));
    output.push(std::move(chunk));
}
bool GroupingAggregatedTransform::tryPushTwoLevelData()
{
    auto try_push_by_iter = [&](auto batch_it)
    {
        if (batch_it == chunks_map.end())
            return false;
        Chunks & cur_chunks = batch_it->second;
        if (cur_chunks.empty())
        {
            chunks_map.erase(batch_it);
            return false;
        }
        pushData(std::move(cur_chunks), batch_it->first, false);
        chunks_map.erase(batch_it);
        return true;
    };