https://clickhouse-test-reports.s3.yandex.net/0/a4dfbba3c75720ba2acc2f2efb003fe78c81fb4c/fuzzer_asan/report.html#fail1

```
2021.10.26 15:58:05.922440 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Debug> executeQuery: (from [::1]:43918) SELECT * FROM m INNER JOIN b USING (key)
2021.10.26 15:58:05.925129 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Trace> ContextAccess (default): Access granted: SELECT(key, ID) ON default.b
2021.10.26 15:58:05.925416 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Trace> InterpreterSelectQuery: FetchColumns -> Complete
2021.10.26 15:58:05.925844 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Debug> HashJoin: Right sample block: b.key UInt32 UInt32(size = 0), ID UInt32 UInt32(size = 0)
2021.10.26 15:58:05.925946 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Trace> HashJoin: Columns to add: [ID UInt32 UInt32(size = 0)], required right []
2021.10.26 15:58:05.926022 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Trace> HashJoin: Joining on: Left keys: [key] Right keys [b.key] Condition columns: '', ''
2021.10.26 15:58:05.926410 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Trace> ContextAccess (default): Access granted: SELECT(key) ON default.m
2021.10.26 15:58:05.927591 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Debug> default.a (73d9aa1b-ebfb-48d6-b3d9-aa1bebfb28d6) (SelectExecutor): Key condition: unknown
2021.10.26 15:58:05.927781 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Debug> default.a (73d9aa1b-ebfb-48d6-b3d9-aa1bebfb28d6) (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
2021.10.26 15:58:05.927978 [ 115 ] {b6c50478-f842-464f-85fc-35716c7fa5e3} <Debug> MergeTreeInOrderSelectProcessor: Reading 1 ranges in order from part all_1_1_0, approx. 1 rows starting from 0

2021.10.26 15:58:15.426690 [ 359 ] {} <Fatal> BaseDaemon: ########################################
2021.10.26 15:58:15.427645 [ 359 ] {} <Fatal> BaseDaemon: (version 21.11.1.8561 (official build), build id: FA0B4348A617C88500D87DC49DDD600AD33613FD) (from thread 115) (query_id: b6c50478-f842-464f-85fc-35716c7fa5e3) Received signal Segmentation fault (11)
2021.10.26 15:58:15.427759 [ 359 ] {} <Fatal> BaseDaemon: Address: NULL pointer. Access: read. Unknown si_code.
2021.10.26 15:58:15.427881 [ 359 ] {} <Fatal> BaseDaemon: Stack trace: 0x1efb945b 0x1f096178 0x1f0aecab 0x269f569a 0x26c253f6 0x26c20260 0x26995f8a 0x2567f77d 0x25671568 0x2567061b 0x25e119de 0x25e13cb8 0x263c57ee 0x263c09d1 0x27d2be96 0x27d59e40 0x2f2c9fef 0x2f2cace1 0x2f5c11c6 0x2f5ba6da 0x7f7d3f49b609 0x7f7d3f3c2293
2021.10.26 15:58:15.496413 [ 359 ] {} <Fatal> BaseDaemon: 3.1. inlined from ./obj-x86_64-linux-gnu/../contrib/libcxx/include/string:1444: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__is_long() const
2021.10.26 15:58:15.496540 [ 359 ] {} <Fatal> BaseDaemon: 3.2. inlined from ../contrib/libcxx/include/string:966: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::size() const
2021.10.26 15:58:15.496637 [ 359 ] {} <Fatal> BaseDaemon: 3.3. inlined from ../contrib/libcxx/include/string:4031: bool std::__1::operator==<std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
2021.10.26 15:58:15.496720 [ 359 ] {} <Fatal> BaseDaemon: 3. ../src/Dictionaries/DictionarySource.cpp:64: DB::DictionarySourceCoordinator::initialize(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&) @ 0x1efb945b in /workspace/clickhouse
2021.10.26 15:58:20.031992 [ 359 ] {} <Fatal> BaseDaemon: 4. DB::DictionarySourceCoordinator::DictionarySourceCoordinator(std::__1::shared_ptr<DB::IDictionary 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&, std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> >&&, unsigned long) @ 0x1f096178 in /workspace/clickhouse
2021.10.26 15:58:24.554289 [ 359 ] {} <Fatal> BaseDaemon: 5. DB::HashedDictionary<(DB::DictionaryKeyType)0, false>::read(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&, unsigned long, unsigned long) const @ 0x1f0aecab in /workspace/clickhouse
2021.10.26 15:58:24.702993 [ 359 ] {} <Fatal> BaseDaemon: 6.1. inlined from ./obj-x86_64-linux-gnu/../contrib/libcxx/include/memory:3211: ~shared_ptr
2021.10.26 15:58:24.703117 [ 359 ] {} <Fatal> BaseDaemon: 6. ../src/Storages/StorageDictionary.cpp:172: DB::StorageDictionary::read(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&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::SelectQueryInfo&, std::__1::shared_ptr<DB::Context const>, DB::QueryProcessingStage::Enum, unsigned long, unsigned int) @ 0x269f569a in /workspace/clickhouse
2021.10.26 15:58:24.924542 [ 359 ] {} <Fatal> BaseDaemon: 7. ./obj-x86_64-linux-gnu/../src/Storages/StorageMerge.cpp:408: DB::StorageMerge::createSources(std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::SelectQueryInfo&, DB::QueryProcessingStage::Enum const&, unsigned long, DB::Block const&, std::__1::vector<DB::StorageMerge::AliasData, std::__1::allocator<DB::StorageMerge::AliasData> > const&, std::__1::tuple<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<DB::IStorage>, std::__1::shared_ptr<DB::RWLockImpl::LockHolderImpl>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > 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> > > >&, std::__1::shared_ptr<DB::Context>, unsigned long, bool, bool, bool) @ 0x26c253f6 in /workspace/clickhouse
2021.10.26 15:58:25.210734 [ 359 ] {} <Fatal> BaseDaemon: 8. ./obj-x86_64-linux-gnu/../src/Storages/StorageMerge.cpp:323: DB::StorageMerge::read(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&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::SelectQueryInfo&, std::__1::shared_ptr<DB::Context const>, DB::QueryProcessingStage::Enum, unsigned long, unsigned int) @ 0x26c20260 in /workspace/clickhouse
2021.10.26 15:58:25.299191 [ 359 ] {} <Fatal> BaseDaemon: 9. ./obj-x86_64-linux-gnu/../src/Storages/IStorage.cpp:109: DB::IStorage::read(DB::QueryPlan&, 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&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::SelectQueryInfo&, std::__1::shared_ptr<DB::Context const>, DB::QueryProcessingStage::Enum, unsigned long, unsigned int) @ 0x26995f8a in /workspace/clickhouse
2021.10.26 15:58:25.749075 [ 359 ] {} <Fatal> BaseDaemon: 10. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:1958: DB::InterpreterSelectQuery::executeFetchColumns(DB::QueryProcessingStage::Enum, DB::QueryPlan&) @ 0x2567f77d in /workspace/clickhouse
2021.10.26 15:58:26.297662 [ 359 ] {} <Fatal> BaseDaemon: 11. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:0: DB::InterpreterSelectQuery::executeImpl(DB::QueryPlan&, std::__1::optional<DB::Pipe>) @ 0x25671568 in /workspace/clickhouse
2021.10.26 15:58:26.819932 [ 359 ] {} <Fatal> BaseDaemon: 12.1. inlined from ./obj-x86_64-linux-gnu/../contrib/libcxx/include/optional:225: ~__optional_destruct_base
2021.10.26 15:58:26.820052 [ 359 ] {} <Fatal> BaseDaemon: 12. ../src/Interpreters/InterpreterSelectQuery.cpp:560: DB::InterpreterSelectQuery::buildQueryPlan(DB::QueryPlan&) @ 0x2567061b in /workspace/clickhouse
2021.10.26 15:58:26.948028 [ 359 ] {} <Fatal> BaseDaemon: 13. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:0: DB::InterpreterSelectWithUnionQuery::buildQueryPlan(DB::QueryPlan&) @ 0x25e119de in /workspace/clickhouse
2021.10.26 15:58:27.079863 [ 359 ] {} <Fatal> BaseDaemon: 14. ./obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:331: DB::InterpreterSelectWithUnionQuery::execute() @ 0x25e13cb8 in /workspace/clickhouse
2021.10.26 15:58:27.265364 [ 359 ] {} <Fatal> BaseDaemon: 15. ./obj-x86_64-linux-gnu/../src/Interpreters/executeQuery.cpp:0: DB::executeQueryImpl(char const*, char const*, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x263c57ee in /workspace/clickhouse
2021.10.26 15:58:27.482450 [ 359 ] {} <Fatal> BaseDaemon: 16. ./obj-x86_64-linux-gnu/../src/Interpreters/executeQuery.cpp:947: 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) @ 0x263c09d1 in /workspace/clickhouse
2021.10.26 15:58:27.610099 [ 359 ] {} <Fatal> BaseDaemon: 17. ./obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:0: DB::TCPHandler::runImpl() @ 0x27d2be96 in /workspace/clickhouse
2021.10.26 15:58:27.839703 [ 359 ] {} <Fatal> BaseDaemon: 18. ./obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:1839: DB::TCPHandler::run() @ 0x27d59e40 in /workspace/clickhouse
2021.10.26 15:58:27.843755 [ 359 ] {} <Fatal> BaseDaemon: 19. ./obj-x86_64-linux-gnu/../contrib/poco/Net/src/TCPServerConnection.cpp:57: Poco::Net::TCPServerConnection::start() @ 0x2f2c9fef in /workspace/clickhouse
2021.10.26 15:58:27.857045 [ 359 ] {} <Fatal> BaseDaemon: 20.1. inlined from ./obj-x86_64-linux-gnu/../contrib/libcxx/include/memory:1397: std::__1::default_delete<Poco::Net::TCPServerConnection>::operator()(Poco::Net::TCPServerConnection*) const
2021.10.26 15:58:27.857248 [ 359 ] {} <Fatal> BaseDaemon: 20.2. inlined from ../contrib/libcxx/include/memory:1658: std::__1::unique_ptr<Poco::Net::TCPServerConnection, std::__1::default_delete<Poco::Net::TCPServerConnection> >::reset(Poco::Net::TCPServerConnection*)
2021.10.26 15:58:27.857339 [ 359 ] {} <Fatal> BaseDaemon: 20.3. inlined from ../contrib/libcxx/include/memory:1612: ~unique_ptr
2021.10.26 15:58:27.857409 [ 359 ] {} <Fatal> BaseDaemon: 20. ../contrib/poco/Net/src/TCPServerDispatcher.cpp:116: Poco::Net::TCPServerDispatcher::run() @ 0x2f2cace1 in /workspace/clickhouse
2021.10.26 15:58:27.872142 [ 359 ] {} <Fatal> BaseDaemon: 21. ./obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/ThreadPool.cpp:0: Poco::PooledThread::run() @ 0x2f5c11c6 in /workspace/clickhouse
2021.10.26 15:58:27.886209 [ 359 ] {} <Fatal> BaseDaemon: 22. ./obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/Thread_POSIX.cpp:0: Poco::ThreadImpl::runnableEntry(void*) @ 0x2f5ba6da in /workspace/clickhouse
2021.10.26 15:58:27.886327 [ 359 ] {} <Fatal> BaseDaemon: 23. start_thread @ 0x9609 in /usr/lib/x86_64-linux-gnu/libpthread-2.31.so
2021.10.26 15:58:27.886427 [ 359 ] {} <Fatal> BaseDaemon: 24. __clone @ 0x122293 in /usr/lib/x86_64-linux-gnu/libc-2.31.so
2021.10.26 15:58:28.956936 [ 359 ] {} <Fatal> BaseDaemon: Checksum of the binary: 406B90D4F087127B1A12664BE642E87C, integrity check passed.
```

cc: @kitaisreal 
{
    ColumnsWithTypeAndName columns_with_type;
    const auto & dictionary_structure = dictionary->getStructure();
    for (const auto & column_name : column_names)
    {
        ColumnWithTypeAndName column_with_type;
        column_with_type.name = column_name;
        auto it = dictionary_structure.attribute_name_to_index.find(column_name);
        if (it == dictionary_structure.attribute_name_to_index.end())
        {
            if (dictionary_structure.id.has_value() && column_name == dictionary_structure.id->name)
            {
                column_with_type.type = std::make_shared<DataTypeUInt64>();
            }
            else if (dictionary_structure.range_min.has_value() && column_name == dictionary_structure.range_min->name)
            {
                column_with_type.type = dictionary_structure.range_min->type;
            }
            else if (dictionary_structure.range_max.has_value() && column_name == dictionary_structure.range_max->name)
            {
                column_with_type.type = dictionary_structure.range_max->type;
            }
            else if (dictionary_structure.key.has_value())
            {
                const auto & dictionary_key_attributes = *dictionary_structure.key;