**How to reproduce**
```sql
SET allow_suspicious_low_cardinality_types = 1;

DROP TABLE IF EXISTS summing_merge_tree__fuzz_0;

CREATE TABLE default.summing_merge_tree__fuzz_0
(
    `key` UInt32,
    `val` LowCardinality(UInt32),
    `date` DateTime
)
ENGINE = SummingMergeTree(val)
PARTITION BY date
ORDER BY key;

INSERT INTO summing_merge_tree__fuzz_0 VALUES (1, 1, '2020-01-01'), (2, 1, '2020-01-02'), (1, 5, '2020-01-01'), (2, 5, '2020-01-02');
```

```
2022.08.11 14:45:43.130492 [ 2965426 ] {71ffd7c4-6514-400f-93cb-39048903e53a} <Fatal> : Logical error: 'Bad cast from type DB::ColumnLowCardinality to DB::ColumnVector<unsigned int>'.
2022.08.11 14:45:43.131505 [ 2965743 ] {} <Fatal> BaseDaemon: ########################################
2022.08.11 14:45:43.131795 [ 2965743 ] {} <Fatal> BaseDaemon: (version 22.8.1.1 (official build), build id: B7F0FF29F1059780) (from thread 2965426) (query_id: 71ffd7c4-6514-400f-93cb-39048903e53a) (query: INSERT INTO summing_merge_tree__fuzz_0 VALUES ) Received signal Aborted (6)
2022.08.11 14:45:43.132018 [ 2965743 ] {} <Fatal> BaseDaemon:
2022.08.11 14:45:43.132253 [ 2965743 ] {} <Fatal> BaseDaemon: Stack trace: 0x7fe0765ce03b 0x7fe0765ad859 0x17168fb6 0x17169075 0x17169125 0x174385eb 0x1938d048 0x1938f6d5 0x28f25c0e 0x28f2550b 0x28f292ba 0x28585271 0x2858669e 0x286e975d 0x28e82d82 0x28d45fa4 0x28d45f35 0x28d45efd 0x28d45ed5 0x28d45e9d 0x171cc426 0x171c8955 0x28d45676 0x28d45191 0x28976c03 0x289768c3 0x28956161 0x28955cce 0x28985e5e 0x288dab10 0x288d907e 0x288d1e0c 0x288e1c25 0x2cefbe79 0x2cefc6dc 0x2d14a214 0x2d146cda 0x2d145a7e 0x7fe076785609 0x7fe0766aa163
2022.08.11 14:45:43.132473 [ 2965743 ] {} <Fatal> BaseDaemon: 4. gsignal in ?
2022.08.11 14:45:43.132576 [ 2965743 ] {} <Fatal> BaseDaemon: 5. abort in ?
2022.08.11 14:45:43.225789 [ 2965743 ] {} <Fatal> BaseDaemon: 6. /build/build_docker/../src/Common/Exception.cpp:40: DB::abortOnFailedAssertion(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in /usr/bin/clickhouse
2022.08.11 14:45:43.318711 [ 2965743 ] {} <Fatal> BaseDaemon: 7. /build/build_docker/../src/Common/Exception.cpp:63: 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&) in /usr/bin/clickhouse
2022.08.11 14:45:43.397159 [ 2965743 ] {} <Fatal> BaseDaemon: 8. /build/build_docker/../src/Common/Exception.cpp:70: DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) in /usr/bin/clickhouse
2022.08.11 14:45:43.620226 [ 2965743 ] {} <Fatal> BaseDaemon: 9. /build/build_docker/../src/Common/assert_cast.h:47: DB::ColumnVector<unsigned int> const& assert_cast<DB::ColumnVector<unsigned int> const&, DB::IColumn const&>(DB::IColumn const&) in /usr/bin/clickhouse
2022.08.11 14:45:44.034368 [ 2965743 ] {} <Fatal> BaseDaemon: 10. /build/build_docker/../src/AggregateFunctions/AggregateFunctionSum.h:438: DB::AggregateFunctionSum<unsigned int, unsigned int, DB::AggregateFunctionSumData<unsigned int>, (DB::AggregateFunctionSumType)1>::add(char*, DB::IColumn const**, unsigned long, DB::Arena*) const in /usr/bin/clickhouse
2022.08.11 14:45:44.450361 [ 2965743 ] {} <Fatal> BaseDaemon: 11. /build/build_docker/../src/AggregateFunctions/IAggregateFunction.h:382: DB::IAggregateFunctionHelper<DB::AggregateFunctionSum<unsigned int, unsigned int, DB::AggregateFunctionSumData<unsigned int>, (DB::AggregateFunctionSumType)1> >::addFree(DB::IAggregateFunction const*, char*, DB::IColumn const**, unsigned long, DB::Arena*) in /usr/bin/clickhouse
2022.08.11 14:45:44.682410 [ 2965743 ] {} <Fatal> BaseDaemon: 12. /build/build_docker/../src/Processors/Merges/Algorithms/SummingSortedAlgorithm.cpp:656: DB::SummingSortedAlgorithm::SummingMergedData::addRowImpl(std::__1::vector<DB::IColumn const*, std::__1::allocator<DB::IColumn const*> >&, unsigned long) in /usr/bin/clickhouse
2022.08.11 14:45:44.906316 [ 2965743 ] {} <Fatal> BaseDaemon: 13. /build/build_docker/../src/Processors/Merges/Algorithms/SummingSortedAlgorithm.cpp:551: DB::SummingSortedAlgorithm::SummingMergedData::startGroup(std::__1::vector<DB::IColumn const*, std::__1::allocator<DB::IColumn const*> >&, unsigned long) in /usr/bin/clickhouse
2022.08.11 14:45:45.131251 [ 2965743 ] {} <Fatal> BaseDaemon: 14. /build/build_docker/../src/Processors/Merges/Algorithms/SummingSortedAlgorithm.cpp:759: DB::SummingSortedAlgorithm::merge() in /usr/bin/clickhouse
2022.08.11 14:45:45.416678 [ 2965743 ] {} <Fatal> BaseDaemon: 15. /build/build_docker/../src/Storages/MergeTree/MergeTreeDataWriter.cpp:264: DB::MergeTreeDataWriter::mergeBlock(DB::Block const&, DB::SortDescription, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, DB::PODArray<unsigned long, 4096ul, Allocator<false, false>, 15ul, 16ul>*&, DB::MergeTreeData::MergingParams const&) in /usr/bin/clickhouse
2022.08.11 14:45:45.662493 [ 2965743 ] {} <Fatal> BaseDaemon: 16. /build/build_docker/../src/Storages/MergeTree/MergeTreeDataWriter.cpp:354: DB::MergeTreeDataWriter::writeTempPart(DB::BlockWithPartition&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, std::__1::shared_ptr<DB::Context const>) in /usr/bin/clickhouse
2022.08.11 14:45:45.797574 [ 2965743 ] {} <Fatal> BaseDaemon: 17. /build/build_docker/../src/Storages/MergeTree/MergeTreeSink.cpp:74: DB::MergeTreeSink::consume(DB::Chunk) in /usr/bin/clickhouse
2022.08.11 14:45:45.893615 [ 2965743 ] {} <Fatal> BaseDaemon: 18. /build/build_docker/../src/Processors/Sinks/SinkToStorage.cpp:18: DB::SinkToStorage::onConsume(DB::Chunk) in /usr/bin/clickhouse
2022.08.11 14:45:46.033050 [ 2965743 ] {} <Fatal> BaseDaemon: 19. /build/build_docker/../src/Processors/Transforms/ExceptionKeepingTransform.cpp:151: DB::ExceptionKeepingTransform::work()::$_1::operator()() const in /usr/bin/clickhouse
2022.08.11 14:45:46.172845 [ 2965743 ] {} <Fatal> BaseDaemon: 20. /build/build_docker/../contrib/libcxx/include/type_traits:3640: decltype(static_cast<DB::ExceptionKeepingTransform::work()::$_1&>(fp)()) std::__1::__invoke<DB::ExceptionKeepingTransform::work()::$_1&>(DB::ExceptionKeepingTransform::work()::$_1&) in /usr/bin/clickhouse
2022.08.11 14:45:46.311557 [ 2965743 ] {} <Fatal> BaseDaemon: 21. /build/build_docker/../contrib/libcxx/include/__functional/invoke.h:62: void std::__1::__invoke_void_return_wrapper<void, true>::__call<DB::ExceptionKeepingTransform::work()::$_1&>(DB::ExceptionKeepingTransform::work()::$_1&) in /usr/bin/clickhouse
2022.08.11 14:45:46.450113 [ 2965743 ] {} <Fatal> BaseDaemon: 22. /build/build_docker/../contrib/libcxx/include/__functional/function.h:230: std::__1::__function::__default_alloc_func<DB::ExceptionKeepingTransform::work()::$_1, void ()>::operator()() in /usr/bin/clickhouse
2022.08.11 14:45:46.587960 [ 2965743 ] {} <Fatal> BaseDaemon: 23. /build/build_docker/../contrib/libcxx/include/__functional/function.h:711: void std::__1::__function::__policy_invoker<void ()>::__call_impl<std::__1::__function::__default_alloc_func<DB::ExceptionKeepingTransform::work()::$_1, void ()> >(std::__1::__function::__policy_storage const*) in /usr/bin/clickhouse
2022.08.11 14:45:46.648082 [ 2965743 ] {} <Fatal> BaseDaemon: 24. /build/build_docker/../contrib/libcxx/include/__functional/function.h:843: std::__1::__function::__policy_func<void ()>::operator()() const in /usr/bin/clickhouse
2022.08.11 14:45:46.701744 [ 2965743 ] {} <Fatal> BaseDaemon: 25. /build/build_docker/../contrib/libcxx/include/__functional/function.h:1184: std::__1::function<void ()>::operator()() const in /usr/bin/clickhouse
2022.08.11 14:45:46.841071 [ 2965743 ] {} <Fatal> BaseDaemon: 26. /build/build_docker/../src/Processors/Transforms/ExceptionKeepingTransform.cpp:115: DB::runStep(std::__1::function<void ()>, DB::ThreadStatus*, std::__1::atomic<unsigned long>*) in /usr/bin/clickhouse
2022.08.11 14:45:46.956803 [ 2965743 ] {} <Fatal> BaseDaemon: 27. /build/build_docker/../src/Processors/Transforms/ExceptionKeepingTransform.cpp:151: DB::ExceptionKeepingTransform::work() in /usr/bin/clickhouse
2022.08.11 14:45:47.048971 [ 2965743 ] {} <Fatal> BaseDaemon: 28. /build/build_docker/../src/Processors/Executors/ExecutionThreadContext.cpp:47: DB::executeJob(DB::ExecutingGraph::Node*, DB::ReadProgressCallback*) in /usr/bin/clickhouse
2022.08.11 14:45:47.136426 [ 2965743 ] {} <Fatal> BaseDaemon: 29. /build/build_docker/../src/Processors/Executors/ExecutionThreadContext.cpp:92: DB::ExecutionThreadContext::executeTask() in /usr/bin/clickhouse
2022.08.11 14:45:47.296475 [ 2965743 ] {} <Fatal> BaseDaemon: 30. /build/build_docker/../src/Processors/Executors/PipelineExecutor.cpp:228: DB::PipelineExecutor::executeStepImpl(unsigned long, std::__1::atomic<bool>*) in /usr/bin/clickhouse
2022.08.11 14:45:47.455741 [ 2965743 ] {} <Fatal> BaseDaemon: 31. /build/build_docker/../src/Processors/Executors/PipelineExecutor.cpp:125: DB::PipelineExecutor::executeStep(std::__1::atomic<bool>*) in /usr/bin/clickhouse
2022.08.11 14:45:47.564046 [ 2965743 ] {} <Fatal> BaseDaemon: 32. /build/build_docker/../src/Processors/Executors/PushingPipelineExecutor.cpp:121: DB::PushingPipelineExecutor::finish() in /usr/bin/clickhouse
2022.08.11 14:45:47.909741 [ 2965743 ] {} <Fatal> BaseDaemon: 33. /build/build_docker/../src/Server/TCPHandler.cpp:668: auto DB::TCPHandler::processInsertQuery()::$_0::operator()<DB::PushingPipelineExecutor>(DB::PushingPipelineExecutor&) const in /usr/bin/clickhouse
2022.08.11 14:45:48.252835 [ 2965743 ] {} <Fatal> BaseDaemon: 34. /build/build_docker/../src/Server/TCPHandler.cpp:678: DB::TCPHandler::processInsertQuery() in /usr/bin/clickhouse
2022.08.11 14:45:48.569654 [ 2965743 ] {} <Fatal> BaseDaemon: 35. /build/build_docker/../src/Server/TCPHandler.cpp:347: DB::TCPHandler::runImpl() in /usr/bin/clickhouse
2022.08.11 14:45:48.916918 [ 2965743 ] {} <Fatal> BaseDaemon: 36. /build/build_docker/../src/Server/TCPHandler.cpp:1838: DB::TCPHandler::run() in /usr/bin/clickhouse
2022.08.11 14:45:48.988501 [ 2965743 ] {} <Fatal> BaseDaemon: 37. /build/build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:43: Poco::Net::TCPServerConnection::start() in /usr/bin/clickhouse
2022.08.11 14:45:49.076190 [ 2965743 ] {} <Fatal> BaseDaemon: 38. /build/build_docker/../contrib/poco/Net/src/TCPServerDispatcher.cpp:115: Poco::Net::TCPServerDispatcher::run() in /usr/bin/clickhouse
2022.08.11 14:45:49.168898 [ 2965743 ] {} <Fatal> BaseDaemon: 39. /build/build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:199: Poco::PooledThread::run() in /usr/bin/clickhouse
2022.08.11 14:45:49.260316 [ 2965743 ] {} <Fatal> BaseDaemon: 40. /build/build_docker/../contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() in /usr/bin/clickhouse
2022.08.11 14:45:49.350788 [ 2965743 ] {} <Fatal> BaseDaemon: 41. /build/build_docker/../contrib/poco/Foundation/src/Thread_POSIX.cpp:345: Poco::ThreadImpl::runnableEntry(void*) in /usr/bin/clickhouse
2022.08.11 14:45:49.350948 [ 2965743 ] {} <Fatal> BaseDaemon: 42. ? in ?
2022.08.11 14:45:49.351141 [ 2965743 ] {} <Fatal> BaseDaemon: 43. __clone in ?
```

else if (desc.is_simple_agg_func_type)
        {
            const auto & type = desc.nested_type ? desc.nested_type
                                                 : desc.real_type;
            columns.emplace_back(type->createColumn());
        }
        else
            columns.emplace_back(header.safeGetByPosition(desc.column_numbers[0]).column->cloneEmpty());
    }
    for (const auto & column_number : def.column_numbers_not_to_aggregate)
        columns.emplace_back(header.safeGetByPosition(column_number).type->createColumn());
    return columns;
}
static void preprocessChunk(Chunk & chunk, const SummingSortedAlgorithm::ColumnsDefinition & def)
{
    auto num_rows = chunk.getNumRows();
    auto columns = chunk.detachColumns();
    for (auto & column : columns)
        column = column->convertToFullColumnIfConst();
    for (const auto & desc : def.columns_to_aggregate)
    {
        if (desc.is_simple_agg_func_type && desc.nested_type)
        {
            auto & col = columns[desc.column_numbers[0]];
            col = recursiveRemoveLowCardinality(col);
        }
    }
    chunk.setColumns(std::move(columns), num_rows);
}
static void postprocessChunk(