```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
```
upper_bound = getColumnIntValueOrDefault(max_range_column, key_index, is_date, DATE_LUT_MAX_DAY_NUM + 1);
            }
            else
            {
                lower_bound = getColumnIntValueOrDefault(min_range_column, key_index, is_date, RANGE_MIN_NULL_VALUE);
                upper_bound = getColumnIntValueOrDefault(max_range_column, key_index, is_date, RANGE_MAX_NULL_VALUE);
            }
            if constexpr (std::is_same_v<KeyType, StringRef>)
                key = copyStringInArena(string_arena, key);
            setAttributeValue(attribute, key, Range{lower_bound, upper_bound}, attribute_column[key_index]);
            keys_extractor.rollbackCurrentKey();
        }
        keys_extractor.reset();
    }
}
template <DictionaryKeyType dictionary_key_type>
template <typename T>
void RangeHashedDictionary<dictionary_key_type>::setAttributeValueImpl(Attribute & attribute, KeyType key, const Range & range, const Field & value)
{
    using ValueType = std::conditional_t<std::is_same_v<T, String>, StringRef, T>;
    auto & collection = std::get<CollectionType<ValueType>>(attribute.maps);
    Value<ValueType> value_to_insert;
    if (attribute.is_nullable && value.isNull())
    {
        value_to_insert = { range, {} };
    }
    else
    {
        if constexpr (std::is_same_v<T, String>)
        {