```sql
version 21.5.1

drop dictionary if exists curs_dict;
drop table if exists curs;

CREATE TABLE curs
(
    `a` UInt64,
    `b` UInt64,
    `e` UInt64,
    `rate` UInt16
)
ENGINE = MergeTree
ORDER BY a

insert into curs 
   select 1, 
   toYYYYMMDDhhmmss(toDateTime('2020-01-01 00:00:00')+number*2) , 
   toYYYYMMDDhhmmss(toDateTime('2020-01-01 00:00:00')+number*2+1), 1 
from numbers(1000000);

CREATE DICTIONARY curs_dict
(
    `a` Unt64,
    `b` UInt64,
    `e` UInt64,
    `rate` UInt16
)
PRIMARY KEY a
SOURCE(CLICKHOUSE(TABLE curs DB 'default' USER 'default'))
LIFETIME(MIN 0 MAX 10)
LAYOUT(RANGE_HASHED)
RANGE(MIN b MAX e);

0 rows in set. Elapsed: 115.715 sec.


SELECT sum(dictGetUInt16('curs_dict', 'rate', toUInt64(1), toYYYYMMDDhhmmss((toDateTime('2020-01-01 00:00:00') + (number * 2)) + 1))) AS s
FROM numbers(10000);

Elapsed: 0.023 sec.


SELECT sum(dictGetUInt16('curs_dict', 'rate', toUInt64(1), toYYYYMMDDhhmmss((toDateTime('2020-01-01 00:00:00') + (number * 2)) + 1))) AS s
FROM numbers(100000)

Elapsed: 2.264 sec.   / Expected  0.023*10 ~ 0.230

SELECT sum(dictGetUInt16('curs_dict', 'rate', toUInt64(1), toYYYYMMDDhhmmss((toDateTime('2020-01-01 00:00:00') + (rand())) + 1))) AS s
FROM numbers(100000)

Hangs forever
```
{
    if (dictionary_key_type == DictionaryKeyType::Complex)
    {
        auto key_types_copy = key_types;
        key_types_copy.pop_back();
        dict_struct.validateKeyTypes(key_types_copy);
    }
    auto range_column_storage_type = std::make_shared<DataTypeInt64>();
    auto range_storage_column = key_columns.back();
    ColumnWithTypeAndName column_to_cast = {range_storage_column->convertToFullColumnIfConst(), key_types.back(), ""};
    auto range_column_updated = castColumnAccurate(column_to_cast, range_column_storage_type);
    PaddedPODArray<RangeStorageType> range_backup_storage;
    const PaddedPODArray<RangeStorageType> & dates = getColumnVectorData(this, range_column_updated, range_backup_storage);
    auto key_columns_copy = key_columns;
    key_columns_copy.pop_back();
    DictionaryKeysArenaHolder<dictionary_key_type> arena_holder;
    DictionaryKeysExtractor<dictionary_key_type> keys_extractor(key_columns_copy, arena_holder.getComplexKeyArena());
    const size_t keys_size = keys_extractor.getKeysSize();
    const auto & attribute = attributes.front();
    auto result = ColumnUInt8::create(keys_size);
    auto & out = result->getData();
    size_t keys_found = 0;
    auto type_call = [&](const auto & dictionary_attribute_type)
    {
        using Type = std::decay_t<decltype(dictionary_attribute_type)>;
        using AttributeType = typename Type::AttributeType;
        using ValueType = DictionaryValueType<AttributeType>;
        const auto & collection = std::get<CollectionType<ValueType>>(attribute.maps);
        for (size_t key_index = 0; key_index < keys_size; ++key_index)
        {