https://s3.amazonaws.com/clickhouse-test-reports/41976/ea5b06023a79dceccae70ad5e3954129050af5a2/fuzzer_astfuzzermsan//report.html

```
2022.12.14 18:56:32.134997 [ 453 ] {} <Fatal> BaseDaemon: ########################################
2022.12.14 18:56:32.135719 [ 453 ] {} <Fatal> BaseDaemon: (version 22.12.1.1, build id: 149BE79908CE55572FF948EECD3EC781AA69F91A) (from thread 165) (query_id: 73895d08-bd51-4b0f-8a03-4af3a551cc0d) (query: SELECT * FROM (SELECT * FROM test_fetch ORDER BY a ASC, b ASC LIMIT 1, 3) ORDER BY a ASC, b ASC) Received signal sanitizer trap (-3)
2022.12.14 18:56:32.135994 [ 453 ] {} <Fatal> BaseDaemon: Sanitizer trap.
2022.12.14 18:56:32.136328 [ 453 ] {} <Fatal> BaseDaemon: Stack trace: 0x28c42259 0x294e3a9a 0xc272056 0xc286bf3 0x447aca9e 0x447a9bc3 0x447a909b 0x445e29ea 0x458016ce 0x447f2d4c 0x466262c4 0x4661d0de 0x49ee6bb6 0x49f2837e 0x55faef9e 0x55fb032f 0x5671088c 0x5670be22 0x56707be9 0x7f29ec00e609 0x7f29ebf33133
2022.12.14 18:56:32.268904 [ 453 ] {} <Fatal> BaseDaemon: 0.1. inlined from ./build_docker/../src/Common/StackTrace.cpp:334: StackTrace::tryCapture()
2022.12.14 18:56:32.269152 [ 453 ] {} <Fatal> BaseDaemon: 0. ./build_docker/../src/Common/StackTrace.cpp:295: StackTrace::StackTrace() @ 0x28c42259 in /workspace/clickhouse
2022.12.14 18:56:32.530003 [ 453 ] {} <Fatal> BaseDaemon: 1. ./build_docker/../src/Daemon/BaseDaemon.cpp:431: sanitizerDeathCallback() @ 0x294e3a9a in /workspace/clickhouse
2022.12.14 18:56:38.174160 [ 453 ] {} <Fatal> BaseDaemon: 2. __sanitizer::Die() @ 0xc272056 in /workspace/clickhouse
2022.12.14 18:56:43.596037 [ 453 ] {} <Fatal> BaseDaemon: 3. ? @ 0xc286bf3 in /workspace/clickhouse
2022.12.14 18:56:43.653110 [ 453 ] {} <Fatal> BaseDaemon: 4.1. inlined from ./build_docker/../contrib/llvm-project/libcxx/include/__hash_table:1822: std::__1::__hash_table<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>, std::__1::hash<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>>, std::__1::equal_to<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>>, std::__1::allocator<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>>>::__node_insert_unique_perform[abi:v15000](std::__1::__hash_node<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>, void*>*)
2022.12.14 18:56:43.653293 [ 453 ] {} <Fatal> BaseDaemon: 4.2. inlined from ./build_docker/../contrib/llvm-project/libcxx/include/__hash_table:1852: std::__1::__hash_table<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>, std::__1::hash<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>>, std::__1::equal_to<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>>, std::__1::allocator<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>>>::__node_insert_unique(std::__1::__hash_node<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>, void*>*)
2022.12.14 18:56:43.653360 [ 453 ] {} <Fatal> BaseDaemon: 4. ./build_docker/../contrib/llvm-project/libcxx/include/__hash_table:2054: std::__1::pair<std::__1::__hash_iterator<std::__1::__hash_node<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>, void*>*>, bool> std::__1::__hash_table<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>, std::__1::hash<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>>, std::__1::equal_to<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>>, std::__1::allocator<DB::QueryTreeNodeWithHash<DB::IQueryTreeNode const*>>>::__emplace_unique_impl<DB::IQueryTreeNode*>(DB::IQueryTreeNode*&&) @ 0x447aca9e in /workspace/clickhouse
2022.12.14 18:56:43.702494 [ 453 ] {} <Fatal> BaseDaemon: 5.1. inlined from ./build_docker/../src/Analyzer/Passes/OrderByLimitByDuplicateEliminationPass.cpp:0: DB::(anonymous namespace)::OrderByLimitByDuplicateEliminationVisitor::visitImpl(std::__1::shared_ptr<DB::IQueryTreeNode>&)
2022.12.14 18:56:43.702618 [ 453 ] {} <Fatal> BaseDaemon: 5. ./build_docker/../src/Analyzer/InDepthQueryTreeVisitor.h:52: DB::InDepthQueryTreeVisitor<DB::(anonymous namespace)::OrderByLimitByDuplicateEliminationVisitor, false>::visit(std::__1::shared_ptr<DB::IQueryTreeNode>&) @ 0x447a9bc3 in /workspace/clickhouse
2022.12.14 18:56:43.748406 [ 453 ] {} <Fatal> BaseDaemon: 6.1. inlined from ./build_docker/../contrib/llvm-project/libcxx/include/__hash_table:1473: ~__hash_table
2022.12.14 18:56:43.748522 [ 453 ] {} <Fatal> BaseDaemon: 6.2. inlined from ./build_docker/../contrib/llvm-project/libcxx/include/unordered_set:615: ~unordered_set
2022.12.14 18:56:43.748593 [ 453 ] {} <Fatal> BaseDaemon: 6.3. inlined from ./build_docker/../src/Analyzer/Passes/OrderByLimitByDuplicateEliminationPass.cpp:14: ~OrderByLimitByDuplicateEliminationVisitor
2022.12.14 18:56:43.748656 [ 453 ] {} <Fatal> BaseDaemon: 6. ./build_docker/../src/Analyzer/Passes/OrderByLimitByDuplicateEliminationPass.cpp:77: DB::OrderByLimitByDuplicateEliminationPass::run(std::__1::shared_ptr<DB::IQueryTreeNode>, std::__1::shared_ptr<DB::Context const>) @ 0x447a909b in /workspace/clickhouse
2022.12.14 18:56:43.820936 [ 453 ] {} <Fatal> BaseDaemon: 7. ./build_docker/../src/Analyzer/QueryTreePassManager.cpp:97: DB::QueryTreePassManager::run(std::__1::shared_ptr<DB::IQueryTreeNode>) @ 0x445e29ea in /workspace/clickhouse
2022.12.14 18:56:43.939236 [ 453 ] {} <Fatal> BaseDaemon: 8.1. inlined from ./build_docker/../src/Analyzer/QueryTreePassManager.h:13: ~QueryTreePassManager
2022.12.14 18:56:43.939399 [ 453 ] {} <Fatal> BaseDaemon: 8.2. inlined from ./build_docker/../src/Interpreters/InterpreterSelectQueryAnalyzer.cpp:57: DB::(anonymous namespace)::buildQueryTreeAndRunPasses(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::Context const> const&)
2022.12.14 18:56:43.939482 [ 453 ] {} <Fatal> BaseDaemon: 8. ./build_docker/../src/Interpreters/InterpreterSelectQueryAnalyzer.cpp:66: DB::InterpreterSelectQueryAnalyzer::InterpreterSelectQueryAnalyzer(std::__1::shared_ptr<DB::IAST> const&, DB::SelectQueryOptions const&, std::__1::shared_ptr<DB::Context const>) @ 0x458016ce in /workspace/clickhouse
2022.12.14 18:56:44.063399 [ 453 ] {} <Fatal> BaseDaemon: 9. ./build_docker/../src/Interpreters/InterpreterFactory.cpp:0: DB::InterpreterFactory::get(std::__1::shared_ptr<DB::IAST>&, std::__1::shared_ptr<DB::Context>, DB::SelectQueryOptions const&) @ 0x447f2d4c in /workspace/clickhouse
2022.12.14 18:56:44.722138 [ 453 ] {} <Fatal> BaseDaemon: 10. ./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*) @ 0x466262c4 in /workspace/clickhouse
2022.12.14 18:56:45.438761 [ 453 ] {} <Fatal> BaseDaemon: 11. ./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) @ 0x4661d0de in /workspace/clickhouse
```
#include <Analyzer/SortNode.h>
#include <Common/SipHash.h>
#include <IO/WriteBufferFromString.h>
#include <IO/Operators.h>
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTOrderByElement.h>
#include <Parsers/ASTLiteral.h>
namespace DB
{
const char * toString(SortDirection sort_direction)