```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
```
{
    auto type = dict_struct.range_min->type;
    ColumnsWithTypeAndName key_columns;
    ColumnWithTypeAndName range_min_column;
    ColumnWithTypeAndName range_max_column;
    auto type_call = [&](const auto & types) mutable -> bool
    {
        using Types = std::decay_t<decltype(types)>;
        using LeftDataType = typename Types::LeftType;
        if constexpr (IsDataTypeNumber<LeftDataType> ||
            std::is_same_v<LeftDataType, DataTypeDate> ||
            std::is_same_v<LeftDataType, DataTypeDate32> ||
            std::is_same_v<LeftDataType, DataTypeDateTime>)
        {
            using RangeType = typename LeftDataType::FieldType;
            PaddedPODArray<KeyType> keys;
            PaddedPODArray<RangeType> start_dates;
            PaddedPODArray<RangeType> end_dates;
            getKeysAndDates(keys, start_dates, end_dates);
            range_min_column = ColumnWithTypeAndName{getColumnFromPODArray(start_dates), dict_struct.range_min->type, dict_struct.range_min->name};
            range_max_column = ColumnWithTypeAndName{getColumnFromPODArray(end_dates), dict_struct.range_max->type, dict_struct.range_max->name};
            if constexpr (dictionary_key_type == DictionaryKeyType::Simple)
                key_columns = {ColumnWithTypeAndName(getColumnFromPODArray(keys), std::make_shared<DataTypeUInt64>(), dict_struct.id->name)};
            else
                key_columns = deserializeColumnsWithTypeAndNameFromKeys(dict_struct, keys, 0, keys.size());
            auto date_column = getColumnFromPODArray(makeDateKeys(start_dates, end_dates));
            key_columns.emplace_back(ColumnWithTypeAndName{std::move(date_column), std::make_shared<DataTypeInt64>(), ""});