https://s3.amazonaws.com/clickhouse-test-reports/42284/ad91b625f76e61f745a516beac2b36da20eeaf97/fuzzer_astfuzzerubsan//report.html

```
2022.10.28 17:39:08.091815 [ 148 ] {b0b50a64-b11a-45fb-a2d4-f5d741b2159d} <Debug> executeQuery: (from [::ffff:127.0.0.1]:56246) CREATE TABLE test__fuzz_45 (`dim1` Nullable(UInt128), `dim2` Nullable(Int128), PROJECTION p1 (SELECT dim1, dim2, count() GROUP BY dim1, dim2)) ENGINE = MergeTree ORDER BY dim1 (stage: Complete)

2022.10.28 17:39:13.340377 [ 148 ] {313dc0da-e756-47b4-a7e1-687359468549} <Debug> executeQuery: (from [::ffff:127.0.0.1]:56246) SELECT dim2, count() FROM test__fuzz_45 GROUP BY dim1, dim2 WITH CUBE WITH TOTALS ORDER BY dim1 ASC NULLS FIRST, dim2 DESC NULLS LAST, [[NULL], [65537], []] ASC NULLS FIRST, count() ASC NULLS FIRST (stage: Complete)
2022.10.28 17:39:13.340891 [ 148 ] {313dc0da-e756-47b4-a7e1-687359468549} <Trace> ContextAccess (default): Access granted: SELECT(dim1, dim2) ON default.test__fuzz_45
2022.10.28 17:39:13.341253 [ 148 ] {313dc0da-e756-47b4-a7e1-687359468549} <Debug> default.test__fuzz_45 (0aaef0e6-4f8c-4889-8f6d-b9f47047db0e) (SelectExecutor): Key condition: unknown
2022.10.28 17:39:13.341293 [ 148 ] {313dc0da-e756-47b4-a7e1-687359468549} <Debug> default.test__fuzz_45 (0aaef0e6-4f8c-4889-8f6d-b9f47047db0e) (SelectExecutor): Selected 1/1 parts by partition key, 1 parts by primary key, 1/1 marks by primary key, 1 marks to read from 1 ranges
2022.10.28 17:39:13.341328 [ 148 ] {313dc0da-e756-47b4-a7e1-687359468549} <Trace> MergeTreeInOrderSelectProcessor: Reading 1 ranges in order from part all_1_1_0, approx. 4 rows starting from 0

2022.10.28 17:39:13.341614 [ 148 ] {313dc0da-e756-47b4-a7e1-687359468549} <Fatal> : Logical error: 'Bad cast from type DB::DataTypeNumber<unsigned long> to DB::DataTypeAggregateFunction'.
2022.10.28 17:39:54.796281 [ 421 ] {} <Fatal> BaseDaemon: ########################################
2022.10.28 17:39:54.796365 [ 421 ] {} <Fatal> BaseDaemon: (version 22.11.1.1, build id: F2154E0BD6706D583BCA00CB6DD4294DBEC39A4B) (from thread 148) (query_id: 313dc0da-e756-47b4-a7e1-687359468549) (query: SELECT dim2, count() FROM test__fuzz_45 GROUP BY dim1, dim2 WITH CUBE WITH TOTALS ORDER BY dim1 ASC NULLS FIRST, dim2 DESC NULLS LAST, [[NULL], [65537], []] ASC NULLS FIRST, count() ASC NULLS FIRST) Received signal Aborted (6)
2022.10.28 17:39:54.796427 [ 421 ] {} <Fatal> BaseDaemon: 
2022.10.28 17:39:54.796525 [ 421 ] {} <Fatal> BaseDaemon: Stack trace: 0x7fcbf91d100b 0x7fcbf91b0859 0x20491623 0x204918af 0x2ab01004 0x2d9c4451 0x2d9c4a96 0x2dc1f5c2 0x2dc1f11c 0x2dc1ef4c 0x2dc1ecb8 0x2dc1ea21 0x2dc1cea2 0x2db706f6 0x2db99cfc 0x2be21027 0x2c2d79ba 0x2c2d334c 0x2d48d4b0 0x2d4adfba 0x2e4865cc 0x2e486aba 0x2e5fe487 0x2e5fbf6f 0x7fcbf9388609 0x7fcbf92ad133
2022.10.28 17:39:54.796613 [ 421 ] {} <Fatal> BaseDaemon: 3. raise @ 0x7fcbf91d100b in ?
2022.10.28 17:39:54.796669 [ 421 ] {} <Fatal> BaseDaemon: 4. abort @ 0x7fcbf91b0859 in ?
2022.10.28 17:39:54.838825 [ 421 ] {} <Fatal> BaseDaemon: 5. ./build_docker/../src/Common/Exception.cpp:47: DB::abortOnFailedAssertion(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) @ 0x20491623 in /workspace/clickhouse
2022.10.28 17:39:54.879592 [ 421 ] {} <Fatal> BaseDaemon: 6. ./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) @ 0x204918af in /workspace/clickhouse
2022.10.28 17:39:54.898209 [ 421 ] {} <Fatal> BaseDaemon: 7. ./build_docker/../src/Common/typeid_cast.h:0: DB::DataTypeAggregateFunction const& typeid_cast<DB::DataTypeAggregateFunction const&, DB::IDataType const>(DB::IDataType const&) @ 0x2ab01004 in /workspace/clickhouse
2022.10.28 17:39:54.920816 [ 421 ] {} <Fatal> BaseDaemon: 8. ./build_docker/../src/Processors/Transforms/TotalsHavingTransform.cpp:28: DB::finalizeBlock(DB::Block&, std::__1::vector<bool, std::__1::allocator<bool>> const&) @ 0x2d9c4451 in /workspace/clickhouse
2022.10.28 17:39:54.939292 [ 421 ] {} <Fatal> BaseDaemon: 9. ./build_docker/../src/Processors/Transforms/TotalsHavingTransform.cpp:84: DB::TotalsHavingTransform::TotalsHavingTransform(DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>> const&, bool, std::__1::shared_ptr<DB::ExpressionActions> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, bool, DB::TotalsMode, double, bool) @ 0x2d9c4a96 in /workspace/clickhouse
2022.10.28 17:39:54.968170 [ 421 ] {} <Fatal> BaseDaemon: 10. ./build_docker/../contrib/libcxx/include/__memory/construct_at.h:35: DB::TotalsHavingTransform* std::__1::construct_at[abi:v15003]<DB::TotalsHavingTransform, DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&, DB::TotalsHavingTransform*>(DB::TotalsHavingTransform*, DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>&&, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&) @ 0x2dc1f5c2 in /workspace/clickhouse
2022.10.28 17:39:54.995791 [ 421 ] {} <Fatal> BaseDaemon: 11. ./build_docker/../contrib/libcxx/include/__memory/allocator_traits.h:302: void std::__1::allocator_traits<std::__1::allocator<DB::TotalsHavingTransform>>::construct[abi:v15003]<DB::TotalsHavingTransform, DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&, void, void>(std::__1::allocator<DB::TotalsHavingTransform>&, DB::TotalsHavingTransform*, DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>&&, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&) @ 0x2dc1f11c in /workspace/clickhouse
2022.10.28 17:39:55.023356 [ 421 ] {} <Fatal> BaseDaemon: 12. ./build_docker/../contrib/libcxx/include/__memory/shared_ptr.h:292: std::__1::__shared_ptr_emplace<DB::TotalsHavingTransform, std::__1::allocator<DB::TotalsHavingTransform>>::__shared_ptr_emplace[abi:v15003]<DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&>(std::__1::allocator<DB::TotalsHavingTransform>, DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>&&, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&) @ 0x2dc1ef4c in /workspace/clickhouse
2022.10.28 17:39:55.050038 [ 421 ] {} <Fatal> BaseDaemon: 13. ./build_docker/../contrib/libcxx/include/__memory/shared_ptr.h:953: std::__1::shared_ptr<DB::TotalsHavingTransform> std::__1::allocate_shared[abi:v15003]<DB::TotalsHavingTransform, std::__1::allocator<DB::TotalsHavingTransform>, DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&, void>(std::__1::allocator<DB::TotalsHavingTransform> const&, DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>&&, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&) @ 0x2dc1ecb8 in /workspace/clickhouse
2022.10.28 17:39:55.076478 [ 421 ] {} <Fatal> BaseDaemon: 14. ./build_docker/../contrib/libcxx/include/__memory/shared_ptr.h:962: std::__1::shared_ptr<DB::TotalsHavingTransform> std::__1::make_shared[abi:v15003]<DB::TotalsHavingTransform, DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&, void>(DB::Block const&, std::__1::vector<bool, std::__1::allocator<bool>>&&, bool&, std::__1::shared_ptr<DB::ExpressionActions>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, bool&, DB::TotalsMode&, double&, bool&) @ 0x2dc1ea21 in /workspace/clickhouse
2022.10.28 17:39:55.099871 [ 421 ] {} <Fatal> BaseDaemon: 15. ./build_docker/../src/Processors/QueryPlan/TotalsHavingStep.cpp:63: DB::TotalsHavingStep::transformPipeline(DB::QueryPipelineBuilder&, DB::BuildQueryPipelineSettings const&) @ 0x2dc1cea2 in /workspace/clickhouse
2022.10.28 17:39:55.117100 [ 421 ] {} <Fatal> BaseDaemon: 16. ./build_docker/../src/Processors/QueryPlan/ITransformingStep.cpp:0: DB::ITransformingStep::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&) @ 0x2db706f6 in /workspace/clickhouse
2022.10.28 17:39:55.145188 [ 421 ] {} <Fatal> BaseDaemon: 17.1. inlined from ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:296: std::__1::unique_ptr<DB::QueryPipelineBuilder, std::__1::default_delete<DB::QueryPipelineBuilder>>::release[abi:v15003]()
2022.10.28 17:39:55.145216 [ 421 ] {} <Fatal> BaseDaemon: 17.2. inlined from ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:225: std::__1::unique_ptr<DB::QueryPipelineBuilder, std::__1::default_delete<DB::QueryPipelineBuilder>>::operator=[abi:v15003](std::__1::unique_ptr<DB::QueryPipelineBuilder, std::__1::default_delete<DB::QueryPipelineBuilder>>&&)
2022.10.28 17:39:55.145251 [ 421 ] {} <Fatal> BaseDaemon: 17. ./build_docker/../src/Processors/QueryPlan/QueryPlan.cpp:187: DB::QueryPlan::buildQueryPipeline(DB::QueryPlanOptimizationSettings const&, DB::BuildQueryPipelineSettings const&) @ 0x2db99cfc in /workspace/clickhouse
2022.10.28 17:39:55.159638 [ 421 ] {} <Fatal> BaseDaemon: 18. ./build_docker/../src/Interpreters/InterpreterSelectQueryAnalyzer.cpp:98: DB::InterpreterSelectQueryAnalyzer::execute() @ 0x2be21027 in /workspace/clickhouse
2022.10.28 17:39:55.216894 [ 421 ] {} <Fatal> BaseDaemon: 19. ./build_docker/../src/Interpreters/executeQuery.cpp:0: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x2c2d79ba in /workspace/clickhouse
2022.10.28 17:39:55.277338 [ 421 ] {} <Fatal> BaseDaemon: 20. ./build_docker/../src/Interpreters/executeQuery.cpp:1106: 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) @ 0x2c2d334c in /workspace/clickhouse
2022.10.28 17:39:55.330142 [ 421 ] {} <Fatal> BaseDaemon: 21. ./build_docker/../src/Server/TCPHandler.cpp:374: DB::TCPHandler::runImpl() @ 0x2d48d4b0 in /workspace/clickhouse
2022.10.28 17:39:55.394293 [ 421 ] {} <Fatal> BaseDaemon: 22. ./build_docker/../src/Server/TCPHandler.cpp:1904: DB::TCPHandler::run() @ 0x2d4adfba in /workspace/clickhouse
2022.10.28 17:39:55.399589 [ 421 ] {} <Fatal> BaseDaemon: 23. ./build_docker/../contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x2e4865cc in /workspace/clickhouse
2022.10.28 17:39:55.406800 [ 421 ] {} <Fatal> BaseDaemon: 24.1. inlined from ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:48: std::__1::default_delete<Poco::Net::TCPServerConnection>::operator()[abi:v15003](Poco::Net::TCPServerConnection*) const
2022.10.28 17:39:55.406827 [ 421 ] {} <Fatal> BaseDaemon: 24.2. inlined from ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:305: std::__1::unique_ptr<Poco::Net::TCPServerConnection, std::__1::default_delete<Poco::Net::TCPServerConnection>>::reset[abi:v15003](Poco::Net::TCPServerConnection*)
2022.10.28 17:39:55.406859 [ 421 ] {} <Fatal> BaseDaemon: 24.3. inlined from ./build_docker/../contrib/libcxx/include/__memory/unique_ptr.h:259: ~unique_ptr
2022.10.28 17:39:55.406894 [ 421 ] {} <Fatal> BaseDaemon: 24. ./build_docker/../contrib/poco/Net/src/TCPServerDispatcher.cpp:116: Poco::Net::TCPServerDispatcher::run() @ 0x2e486aba in /workspace/clickhouse
2022.10.28 17:39:55.415076 [ 421 ] {} <Fatal> BaseDaemon: 25. ./build_docker/../contrib/poco/Foundation/src/ThreadPool.cpp:213: Poco::PooledThread::run() @ 0x2e5fe487 in /workspace/clickhouse
2022.10.28 17:39:55.422338 [ 421 ] {} <Fatal> BaseDaemon: 26.1. inlined from ./build_docker/../contrib/poco/Foundation/include/Poco/SharedPtr.h:156: Poco::SharedPtr<Poco::Runnable, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::Runnable>>::assign(Poco::Runnable*)
2022.10.28 17:39:55.422363 [ 421 ] {} <Fatal> BaseDaemon: 26.2. inlined from ./build_docker/../contrib/poco/Foundation/include/Poco/SharedPtr.h:208: Poco::SharedPtr<Poco::Runnable, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::Runnable>>::operator=(Poco::Runnable*)
2022.10.28 17:39:55.422393 [ 421 ] {} <Fatal> BaseDaemon: 26. ./build_docker/../contrib/poco/Foundation/src/Thread_POSIX.cpp:360: Poco::ThreadImpl::runnableEntry(void*) @ 0x2e5fbf6f in /workspace/clickhouse
2022.10.28 17:39:55.422432 [ 421 ] {} <Fatal> BaseDaemon: 27. ? @ 0x7fcbf9388609 in ?
2022.10.28 17:39:55.422472 [ 421 ] {} <Fatal> BaseDaemon: 28. clone @ 0x7fcbf92ad133 in ?
2022.10.28 17:39:55.738272 [ 421 ] {} <Fatal> BaseDaemon: Integrity check of the executable skipped because the reference checksum could not be read. (calculated checksum: 314BA9D8A8888FFF22EF417DE3033F72)
```
if (query_node.isLimitWithTies())
        {
            
            if (!query_node.hasOrderBy())
                throw Exception(ErrorCodes::LOGICAL_ERROR, "LIMIT WITH TIES without ORDER BY");
            limit_with_ties_sort_description = sort_description;
        }
        auto limit = std::make_unique<LimitStep>(query_plan.getCurrentDataStream(),
            limit_length,
            limit_offset,
            always_read_till_end,
            limit_with_ties,
            limit_with_ties_sort_description);
        if (limit_with_ties)
            limit->setStepDescription("LIMIT WITH TIES");
        query_plan.addStep(std::move(limit));
    }
    else if (query_node.hasOffset())
    {
        auto offsets_step = std::make_unique<OffsetStep>(query_plan.getCurrentDataStream(), limit_offset);
        query_plan.addStep(std::move(offsets_step));
    }
    auto projection_step = std::make_unique<ExpressionStep>(query_plan.getCurrentDataStream(), projection_analysis_result.project_names_actions);
    projection_step->setStepDescription("Project names");
    query_plan.addStep(std::move(projection_step));
    addBuildSubqueriesForSetsStepIfNeeded(query_plan, select_query_options, planner_context);
    extendQueryContextAndStoragesLifetime(query_plan, planner_context);
}
}