https://s3.amazonaws.com/clickhouse-test-reports/0/092f87a60df8a4324bb0fbe53f7bc845d32c1e8d/fuzzer_astfuzzermsan//report.html

**Describe the bug**
```
[ip-172-31-12-205] 2022.12.12 14:06:20.281976 [ 1195 ] <Fatal> BaseDaemon: ########################################
[ip-172-31-12-205] 2022.12.12 14:06:20.282360 [ 1195 ] <Fatal> BaseDaemon: (version 22.12.1.1 (official build), build id: 876E6F97EFDC98B1A82E31AEAA1B236CABA2CCBA) (from thread 157) (query_id: ae6509d5-4686-4570-bee0-ec9955c22f79) (query: SELECT * FROM test_view ORDER BY f1 ASC, f2 ASC) Received signal Segmentation fault (11)
[ip-172-31-12-205] 2022.12.12 14:06:20.282559 [ 1195 ] <Fatal> BaseDaemon: Address: 0x50 Access: read. Address not mapped to object.
[ip-172-31-12-205] 2022.12.12 14:06:20.282741 [ 1195 ] <Fatal> BaseDaemon: Stack trace: 0x457e91e5 0x457e2485 0x4af5ea71 0x4af5d642 0x4af6df54 0x4af6ea18 0x4ae8a621 0x4aefb77f 0x4577d8ca 0x465a43b8 0x465978be 0x49e4c4b6 0x49e8d3be 0x55cde55e 0x55cdf8ef 0x5643fe4c 0x5643b3e2 0x564371a9 0x7fa0c8e0b609 0x7fa0c8d30133
[ip-172-31-12-205] 2022.12.12 14:06:20.439687 [ 1195 ] <Fatal> BaseDaemon: 4.1. inlined from ./build_docker/../contrib/llvm-project/libcxx/include/__hash_table:768: std::__1::__bucket_list_deallocator<std::__1::allocator<std::__1::__hash_node_base<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>, void*>*>*>>::size[abi:v15000]() const
[ip-172-31-12-205] 2022.12.12 14:06:20.439947 [ 1195 ] <Fatal> BaseDaemon: 4.2. inlined from ./build_docker/../contrib/llvm-project/libcxx/include/__hash_table:1164: std::__1::__hash_table<std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>, std::__1::__unordered_map_hasher<std::__1::shared_ptr<DB::IQueryTreeNode>, std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>, std::__1::hash<std::__1::shared_ptr<DB::IQueryTreeNode>>, std::__1::equal_to<std::__1::shared_ptr<DB::IQueryTreeNode>>, true>, std::__1::__unordered_map_equal<std::__1::shared_ptr<DB::IQueryTreeNode>, std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>, std::__1::equal_to<std::__1::shared_ptr<DB::IQueryTreeNode>>, std::__1::hash<std::__1::shared_ptr<DB::IQueryTreeNode>>, true>, std::__1::allocator<std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>>>::bucket_count[abi:v15000]() const
[ip-172-31-12-205] 2022.12.12 14:06:20.440061 [ 1195 ] <Fatal> BaseDaemon: 4. ./build_docker/../contrib/llvm-project/libcxx/include/__hash_table:2307: std::__1::__hash_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>, void*>*> std::__1::__hash_table<std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>, std::__1::__unordered_map_hasher<std::__1::shared_ptr<DB::IQueryTreeNode>, std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>, std::__1::hash<std::__1::shared_ptr<DB::IQueryTreeNode>>, std::__1::equal_to<std::__1::shared_ptr<DB::IQueryTreeNode>>, true>, std::__1::__unordered_map_equal<std::__1::shared_ptr<DB::IQueryTreeNode>, std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>, std::__1::equal_to<std::__1::shared_ptr<DB::IQueryTreeNode>>, std::__1::hash<std::__1::shared_ptr<DB::IQueryTreeNode>>, true>, std::__1::allocator<std::__1::__hash_value_type<std::__1::shared_ptr<DB::IQueryTreeNode>, DB::TableExpressionData>>>::find<std::__1::shared_ptr<DB::IQueryTreeNode>>(std::__1::shared_ptr<DB::IQueryTreeNode> const&) @ 0x457e91e5 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:20.592677 [ 1195 ] <Fatal> BaseDaemon: 5. ./build_docker/../src/Planner/PlannerContext.cpp:0: DB::PlannerContext::getTableExpressionDataOrThrow(std::__1::shared_ptr<DB::IQueryTreeNode> const&) @ 0x457e2485 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:21.626461 [ 1195 ] <Fatal> BaseDaemon: 6. ./build_docker/../src/Processors/QueryPlan/ReadFromMergeTree.cpp:0: DB::ReadFromMergeTree::selectRangesToRead(std::__1::vector<std::__1::shared_ptr<DB::IMergeTreeDataPart const>, std::__1::allocator<std::__1::shared_ptr<DB::IMergeTreeDataPart const>>>, std::__1::shared_ptr<DB::PrewhereInfo> const&, DB::ActionDAGNodes const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::SelectQueryInfo const&, std::__1::shared_ptr<DB::Context const>, unsigned long, std::__1::shared_ptr<std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, long, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const, long>>>>, DB::MergeTreeData const&, 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&, bool, Poco::Logger*) @ 0x4af5ea71 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:22.646370 [ 1195 ] <Fatal> BaseDaemon: 7. ./build_docker/../src/Processors/QueryPlan/ReadFromMergeTree.cpp:0: DB::ReadFromMergeTree::selectRangesToRead(std::__1::vector<std::__1::shared_ptr<DB::IMergeTreeDataPart const>, std::__1::allocator<std::__1::shared_ptr<DB::IMergeTreeDataPart const>>>) const @ 0x4af5d642 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:23.727306 [ 1195 ] <Fatal> BaseDaemon: 8. ./build_docker/../src/Processors/QueryPlan/ReadFromMergeTree.cpp:1206: DB::ReadFromMergeTree::getAnalysisResult() const @ 0x4af6df54 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:24.600106 [ 1195 ] <Fatal> BaseDaemon: 9. ./build_docker/../src/Processors/QueryPlan/ReadFromMergeTree.cpp:0: DB::ReadFromMergeTree::initializePipeline(DB::QueryPipelineBuilder&, DB::BuildQueryPipelineSettings const&) @ 0x4af6ea18 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:24.708944 [ 1195 ] <Fatal> BaseDaemon: 10. ./build_docker/../src/Processors/QueryPlan/ISourceStep.cpp:0: DB::ISourceStep::updatePipeline(std::__1::vector<std::__1::unique_ptr<DB::QueryPipelineBuilder, std::__1::default_delete<DB::QueryPipelineBuilder>>, std::__1::allocator<std::__1::unique_ptr<DB::QueryPipelineBuilder, std::__1::default_delete<DB::QueryPipelineBuilder>>>>, DB::BuildQueryPipelineSettings const&) @ 0x4ae8a621 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:24.939660 [ 1195 ] <Fatal> BaseDaemon: 11. ./build_docker/../src/Processors/QueryPlan/QueryPlan.cpp:0: DB::QueryPlan::buildQueryPipeline(DB::QueryPlanOptimizationSettings const&, DB::BuildQueryPipelineSettings const&) @ 0x4aefb77f in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:25.063400 [ 1195 ] <Fatal> BaseDaemon: 12. ./build_docker/../src/Interpreters/InterpreterSelectQueryAnalyzer.cpp:0: DB::InterpreterSelectQueryAnalyzer::execute() @ 0x4577d8ca in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:25.725276 [ 1195 ] <Fatal> BaseDaemon: 13. ./build_docker/../src/Interpreters/executeQuery.cpp:686: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x465a43b8 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:26.446840 [ 1195 ] <Fatal> BaseDaemon: 14. ./build_docker/../src/Interpreters/executeQuery.cpp:1083: DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum) @ 0x465978be in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:26.914939 [ 1195 ] <Fatal> BaseDaemon: 15. ./build_docker/../src/Server/TCPHandler.cpp:374: DB::TCPHandler::runImpl() @ 0x49e4c4b6 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:27.621919 [ 1195 ] <Fatal> BaseDaemon: 16. ./build_docker/../src/Server/TCPHandler.cpp:1902: DB::TCPHandler::run() @ 0x49e8d3be in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:27.642455 [ 1195 ] <Fatal> BaseDaemon: 17. ./build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x55cde55e in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:27.679776 [ 1195 ] <Fatal> BaseDaemon: 18.1. inlined from ./build_docker/../contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:302: std::__1::unique_ptr<Poco::Net::TCPServerConnection, std::__1::default_delete<Poco::Net::TCPServerConnection>>::reset[abi:v15000](Poco::Net::TCPServerConnection*)
[ip-172-31-12-205] 2022.12.12 14:06:27.679913 [ 1195 ] <Fatal> BaseDaemon: 18.2. inlined from ./build_docker/../contrib/llvm-project/libcxx/include/__memory/unique_ptr.h:259: ~unique_ptr
[ip-172-31-12-205] 2022.12.12 14:06:27.679995 [ 1195 ] <Fatal> BaseDaemon: 18. ./build_docker/../contrib/poco/Net/src/TCPServerDispatcher.cpp:116: Poco::Net::TCPServerDispatcher::run() @ 0x55cdf8ef in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:27.723980 [ 1195 ] <Fatal> BaseDaemon: 19. ./build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:0: Poco::PooledThread::run() @ 0x5643fe4c in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:27.768210 [ 1195 ] <Fatal> BaseDaemon: 20. ./build_docker/../contrib/poco/Foundation/src/Thread.cpp:56: Poco::(anonymous namespace)::RunnableHolder::run() @ 0x5643b3e2 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:27.804457 [ 1195 ] <Fatal> BaseDaemon: 21. ./build_docker/../contrib/poco/Foundation/src/Thread_POSIX.cpp:360: Poco::ThreadImpl::runnableEntry(void*) @ 0x564371a9 in /workspace/clickhouse
[ip-172-31-12-205] 2022.12.12 14:06:27.804578 [ 1195 ] <Fatal> BaseDaemon: 22. ? @ 0x7fa0c8e0b609 in ?
[ip-172-31-12-205] 2022.12.12 14:06:27.804669 [ 1195 ] <Fatal> BaseDaemon: 23. __clone @ 0x7fa0c8d30133 in ?
[ip-172-31-12-205] 2022.12.12 14:06:30.648294 [ 1195 ] <Fatal> BaseDaemon: Integrity check of the executable successfully passed (checksum: 3663193C8A04B8593463680CB8385041)
```
bool aggregate_overflow_row =
            query_node.isGroupByWithTotals() &&
            settings.max_rows_to_group_by &&
            settings.group_by_overflow_mode == OverflowMode::ANY &&
            settings.totals_mode != TotalsMode::AFTER_HAVING_EXCLUSIVE;
        Aggregator::Params aggregator_params = Aggregator::Params(
            aggregation_analysis_result.aggregation_keys,
            aggregation_analysis_result.aggregate_descriptions,
            aggregate_overflow_row,
            settings.max_rows_to_group_by,
            settings.group_by_overflow_mode,
            settings.group_by_two_level_threshold,
            settings.group_by_two_level_threshold_bytes,
            settings.max_bytes_before_external_group_by,
            settings.empty_result_for_aggregation_by_empty_set
                || (settings.empty_result_for_aggregation_by_constant_keys_on_empty_set && aggregation_analysis_result.aggregation_keys.empty()
                    && aggregation_analysis_result.group_by_with_constant_keys),
            planner_context->getQueryContext()->getTempDataOnDisk(),
            settings.max_threads,
            settings.min_free_disk_space_for_temporary_data,
            settings.compile_aggregate_expressions,
            settings.min_count_to_compile_aggregate_expression,
            settings.max_block_size,
            settings.enable_software_prefetch_in_aggregation,
             false,
            stats_collecting_params
        );
        SortDescription group_by_sort_description;
        SortDescription sort_description_for_merging;
        auto merge_threads = settings.max_threads;