Coverage Report

Created: 2026-05-31 14:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/common/join_utils.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <algorithm>
21
#include <variant>
22
23
#include "exec/common/hash_table/hash_crc32_return32.h"
24
#include "exec/common/hash_table/hash_key_type.h"
25
#include "exec/common/hash_table/hash_map_context.h"
26
#include "exec/common/hash_table/join_hash_table.h"
27
28
namespace doris {
29
30
// Devirtualize compare_at for ASOF JOIN supported column types.
31
// ASOF JOIN only supports DateV2, DateTimeV2, and TimestampTZ.
32
// Dispatches to the concrete ColumnVector<T> once so that all compare_at
33
// calls inside `func` are direct (non-virtual) calls.
34
// `func` receives a single argument: a const pointer to the concrete column
35
// (or const IColumn* as fallback for unexpected types).
36
template <typename Func>
37
251
decltype(auto) asof_column_dispatch(const IColumn* col, Func&& func) {
38
251
    if (const auto* c_dv2 = check_and_get_column<ColumnDateV2>(col)) {
39
0
        return std::forward<Func>(func)(c_dv2);
40
251
    } else if (const auto* c_dtv2 = check_and_get_column<ColumnDateTimeV2>(col)) {
41
250
        return std::forward<Func>(func)(c_dtv2);
42
250
    } else if (const auto* c_tstz = check_and_get_column<ColumnTimeStampTz>(col)) {
43
1
        return std::forward<Func>(func)(c_tstz);
44
1
    } else {
45
0
        return std::forward<Func>(func)(col);
46
0
    }
47
251
}
48
using JoinOpVariants =
49
        std::variant<std::integral_constant<TJoinOp::type, TJoinOp::INNER_JOIN>,
50
                     std::integral_constant<TJoinOp::type, TJoinOp::LEFT_SEMI_JOIN>,
51
                     std::integral_constant<TJoinOp::type, TJoinOp::LEFT_ANTI_JOIN>,
52
                     std::integral_constant<TJoinOp::type, TJoinOp::LEFT_OUTER_JOIN>,
53
                     std::integral_constant<TJoinOp::type, TJoinOp::FULL_OUTER_JOIN>,
54
                     std::integral_constant<TJoinOp::type, TJoinOp::RIGHT_OUTER_JOIN>,
55
                     std::integral_constant<TJoinOp::type, TJoinOp::CROSS_JOIN>,
56
                     std::integral_constant<TJoinOp::type, TJoinOp::RIGHT_SEMI_JOIN>,
57
                     std::integral_constant<TJoinOp::type, TJoinOp::RIGHT_ANTI_JOIN>,
58
                     std::integral_constant<TJoinOp::type, TJoinOp::NULL_AWARE_LEFT_ANTI_JOIN>,
59
                     std::integral_constant<TJoinOp::type, TJoinOp::NULL_AWARE_LEFT_SEMI_JOIN>,
60
                     std::integral_constant<TJoinOp::type, TJoinOp::ASOF_LEFT_INNER_JOIN>,
61
                     std::integral_constant<TJoinOp::type, TJoinOp::ASOF_LEFT_OUTER_JOIN>>;
62
63
395k
inline bool is_asof_join(TJoinOp::type join_op) {
64
395k
    return join_op == TJoinOp::ASOF_LEFT_INNER_JOIN || join_op == TJoinOp::ASOF_LEFT_OUTER_JOIN;
65
395k
}
66
67
template <int JoinOpType>
68
inline constexpr bool is_asof_join_op_v =
69
        JoinOpType == TJoinOp::ASOF_LEFT_INNER_JOIN || JoinOpType == TJoinOp::ASOF_LEFT_OUTER_JOIN;
70
71
template <int JoinOpType>
72
inline constexpr bool is_asof_outer_join_op_v = JoinOpType == TJoinOp::ASOF_LEFT_OUTER_JOIN;
73
74
template <class T>
75
using PrimaryTypeHashTableContext = MethodOneNumber<T, JoinHashMap<T, HashCRC32Return32<T>, false>>;
76
77
template <class T>
78
using DirectPrimaryTypeHashTableContext =
79
        MethodOneNumberDirect<T, JoinHashMap<T, HashCRC32Return32<T>, true>>;
80
81
template <class Key>
82
using FixedKeyHashTableContext = MethodKeysFixed<JoinHashMap<Key, HashCRC32Return32<Key>, false>>;
83
84
using SerializedHashTableContext =
85
        MethodSerialized<JoinHashMap<StringRef, HashCRC32Return32<StringRef>, false>>;
86
using MethodOneString =
87
        MethodStringNoCache<JoinHashMap<StringRef, HashCRC32Return32<StringRef>, false>>;
88
89
using HashTableVariants = std::variant<
90
        std::monostate, SerializedHashTableContext, PrimaryTypeHashTableContext<UInt8>,
91
        PrimaryTypeHashTableContext<UInt16>, PrimaryTypeHashTableContext<UInt32>,
92
        PrimaryTypeHashTableContext<UInt64>, PrimaryTypeHashTableContext<UInt128>,
93
        PrimaryTypeHashTableContext<UInt256>, DirectPrimaryTypeHashTableContext<UInt8>,
94
        DirectPrimaryTypeHashTableContext<UInt16>, DirectPrimaryTypeHashTableContext<UInt32>,
95
        DirectPrimaryTypeHashTableContext<UInt64>, DirectPrimaryTypeHashTableContext<UInt128>,
96
        FixedKeyHashTableContext<UInt64>, FixedKeyHashTableContext<UInt72>,
97
        FixedKeyHashTableContext<UInt96>, FixedKeyHashTableContext<UInt104>,
98
        FixedKeyHashTableContext<UInt128>, FixedKeyHashTableContext<UInt136>,
99
        FixedKeyHashTableContext<UInt256>, MethodOneString>;
100
101
struct JoinDataVariants {
102
    HashTableVariants method_variant;
103
104
63.9k
    void init(const std::vector<DataTypePtr>& data_types, HashKeyType type) {
105
63.9k
        switch (type) {
106
14.3k
        case HashKeyType::serialized:
107
14.3k
            method_variant.emplace<SerializedHashTableContext>();
108
14.3k
            break;
109
896
        case HashKeyType::int8_key:
110
896
            method_variant.emplace<PrimaryTypeHashTableContext<UInt8>>();
111
896
            break;
112
422
        case HashKeyType::int16_key:
113
422
            method_variant.emplace<PrimaryTypeHashTableContext<UInt16>>();
114
422
            break;
115
10.0k
        case HashKeyType::int32_key:
116
10.0k
            method_variant.emplace<PrimaryTypeHashTableContext<UInt32>>();
117
10.0k
            break;
118
3.69k
        case HashKeyType::int64_key:
119
3.69k
            method_variant.emplace<PrimaryTypeHashTableContext<UInt64>>();
120
3.69k
            break;
121
571
        case HashKeyType::int128_key:
122
571
            method_variant.emplace<PrimaryTypeHashTableContext<UInt128>>();
123
571
            break;
124
37
        case HashKeyType::int256_key:
125
37
            method_variant.emplace<PrimaryTypeHashTableContext<UInt256>>();
126
37
            break;
127
1.37k
        case HashKeyType::string_key:
128
1.37k
            method_variant.emplace<MethodOneString>();
129
1.37k
            break;
130
4.40k
        case HashKeyType::fixed64:
131
4.40k
            method_variant.emplace<FixedKeyHashTableContext<UInt64>>(get_key_sizes(data_types));
132
4.40k
            break;
133
3.21k
        case HashKeyType::fixed72:
134
3.21k
            method_variant.emplace<FixedKeyHashTableContext<UInt72>>(get_key_sizes(data_types));
135
3.21k
            break;
136
8.01k
        case HashKeyType::fixed96:
137
8.01k
            method_variant.emplace<FixedKeyHashTableContext<UInt96>>(get_key_sizes(data_types));
138
8.01k
            break;
139
28
        case HashKeyType::fixed104:
140
28
            method_variant.emplace<FixedKeyHashTableContext<UInt104>>(get_key_sizes(data_types));
141
28
            break;
142
8.02k
        case HashKeyType::fixed128:
143
8.02k
            method_variant.emplace<FixedKeyHashTableContext<UInt128>>(get_key_sizes(data_types));
144
8.02k
            break;
145
960
        case HashKeyType::fixed136:
146
960
            method_variant.emplace<FixedKeyHashTableContext<UInt136>>(get_key_sizes(data_types));
147
960
            break;
148
7.93k
        case HashKeyType::fixed256:
149
7.93k
            method_variant.emplace<FixedKeyHashTableContext<UInt256>>(get_key_sizes(data_types));
150
7.93k
            break;
151
0
        default:
152
0
            throw Exception(ErrorCode::INTERNAL_ERROR,
153
0
                            "JoinDataVariants meet invalid key type, type={}", type);
154
63.9k
        }
155
63.9k
    }
156
};
157
158
template <typename Method>
159
void primary_to_direct_mapping(Method* context, const ColumnRawPtrs& key_columns,
160
9.20k
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
9.20k
    using FieldType = typename Method::Base::Key;
162
9.20k
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
9.20k
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
9.20k
    size_t num_rows = key_columns[0]->size();
166
9.20k
    if (key_columns[0]->is_nullable()) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
9.20k
    } else {
182
9.20k
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
22.9M
        for (size_t i = 1; i < num_rows; i++) {
185
22.9M
            max_key = std::max(max_key, input_keys[i]);
186
22.9M
            min_key = std::min(min_key, input_keys[i]);
187
22.9M
        }
188
9.20k
    }
189
190
9.20k
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
9.20k
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
9.20k
    if (allow_direct_mapping) {
193
13.5k
        for (const auto& variant_ptr : variant_ptrs) {
194
13.5k
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
13.5k
                    max_key, min_key);
196
13.5k
        }
197
8.04k
    }
198
9.20k
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberIhNS_13JoinHashTableIhNS_17HashCRC32Return32IhEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
160
561
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
561
    using FieldType = typename Method::Base::Key;
162
561
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
561
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
561
    size_t num_rows = key_columns[0]->size();
166
561
    if (key_columns[0]->is_nullable()) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
561
    } else {
182
561
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
1.76k
        for (size_t i = 1; i < num_rows; i++) {
185
1.20k
            max_key = std::max(max_key, input_keys[i]);
186
1.20k
            min_key = std::min(min_key, input_keys[i]);
187
1.20k
        }
188
561
    }
189
190
561
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
561
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
561
    if (allow_direct_mapping) {
193
788
        for (const auto& variant_ptr : variant_ptrs) {
194
788
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
788
                    max_key, min_key);
196
788
        }
197
469
    }
198
561
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberItNS_13JoinHashTableItNS_17HashCRC32Return32ItEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
160
309
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
309
    using FieldType = typename Method::Base::Key;
162
309
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
309
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
309
    size_t num_rows = key_columns[0]->size();
166
309
    if (key_columns[0]->is_nullable()) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
309
    } else {
182
309
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
2.14k
        for (size_t i = 1; i < num_rows; i++) {
185
1.83k
            max_key = std::max(max_key, input_keys[i]);
186
1.83k
            min_key = std::min(min_key, input_keys[i]);
187
1.83k
        }
188
309
    }
189
190
309
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
309
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
309
    if (allow_direct_mapping) {
193
387
        for (const auto& variant_ptr : variant_ptrs) {
194
387
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
387
                    max_key, min_key);
196
387
        }
197
275
    }
198
309
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberIjNS_13JoinHashTableIjNS_17HashCRC32Return32IjEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
160
6.02k
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
6.02k
    using FieldType = typename Method::Base::Key;
162
6.02k
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
6.02k
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
6.02k
    size_t num_rows = key_columns[0]->size();
166
6.02k
    if (key_columns[0]->is_nullable()) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
6.02k
    } else {
182
6.02k
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
22.7M
        for (size_t i = 1; i < num_rows; i++) {
185
22.7M
            max_key = std::max(max_key, input_keys[i]);
186
22.7M
            min_key = std::min(min_key, input_keys[i]);
187
22.7M
        }
188
6.02k
    }
189
190
6.02k
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
6.02k
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
6.02k
    if (allow_direct_mapping) {
193
9.27k
        for (const auto& variant_ptr : variant_ptrs) {
194
9.27k
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
9.27k
                    max_key, min_key);
196
9.27k
        }
197
5.48k
    }
198
6.02k
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberImNS_13JoinHashTableImNS_17HashCRC32Return32ImEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
160
1.80k
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
1.80k
    using FieldType = typename Method::Base::Key;
162
1.80k
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
1.80k
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
1.80k
    size_t num_rows = key_columns[0]->size();
166
1.80k
    if (key_columns[0]->is_nullable()) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
1.80k
    } else {
182
1.80k
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
260k
        for (size_t i = 1; i < num_rows; i++) {
185
258k
            max_key = std::max(max_key, input_keys[i]);
186
258k
            min_key = std::min(min_key, input_keys[i]);
187
258k
        }
188
1.80k
    }
189
190
1.80k
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
1.80k
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
1.80k
    if (allow_direct_mapping) {
193
2.69k
        for (const auto& variant_ptr : variant_ptrs) {
194
2.69k
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
2.69k
                    max_key, min_key);
196
2.69k
        }
197
1.48k
    }
198
1.80k
}
_ZN5doris25primary_to_direct_mappingINS_15MethodOneNumberIN4wide7integerILm128EjEENS_13JoinHashTableIS4_NS_17HashCRC32Return32IS4_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
Line
Count
Source
160
503
                               const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
161
503
    using FieldType = typename Method::Base::Key;
162
503
    FieldType max_key = std::numeric_limits<FieldType>::min();
163
503
    FieldType min_key = std::numeric_limits<FieldType>::max();
164
165
503
    size_t num_rows = key_columns[0]->size();
166
503
    if (key_columns[0]->is_nullable()) {
167
0
        const FieldType* input_keys = (FieldType*)assert_cast<const ColumnNullable*>(key_columns[0])
168
0
                                              ->get_nested_column_ptr()
169
0
                                              ->get_raw_data()
170
0
                                              .data;
171
0
        const NullMap& null_map =
172
0
                assert_cast<const ColumnNullable*>(key_columns[0])->get_null_map_data();
173
        // skip first mocked row
174
0
        for (size_t i = 1; i < num_rows; i++) {
175
0
            if (null_map[i]) {
176
0
                continue;
177
0
            }
178
0
            max_key = std::max(max_key, input_keys[i]);
179
0
            min_key = std::min(min_key, input_keys[i]);
180
0
        }
181
503
    } else {
182
503
        const FieldType* input_keys = (FieldType*)key_columns[0]->get_raw_data().data;
183
        // skip first mocked row
184
1.72k
        for (size_t i = 1; i < num_rows; i++) {
185
1.22k
            max_key = std::max(max_key, input_keys[i]);
186
1.22k
            min_key = std::min(min_key, input_keys[i]);
187
1.22k
        }
188
503
    }
189
190
503
    constexpr auto MAX_MAPPING_RANGE = 1 << 23;
191
503
    bool allow_direct_mapping = (max_key >= min_key && max_key - min_key < MAX_MAPPING_RANGE - 1);
192
503
    if (allow_direct_mapping) {
193
393
        for (const auto& variant_ptr : variant_ptrs) {
194
393
            variant_ptr->method_variant.emplace<DirectPrimaryTypeHashTableContext<FieldType>>(
195
393
                    max_key, min_key);
196
393
        }
197
332
    }
198
503
}
199
200
template <typename Method>
201
void try_convert_to_direct_mapping(
202
        Method* method, const ColumnRawPtrs& key_columns,
203
47.2k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingISt9monostateEEvPT_RKSt6vectorIPKNS_7IColumnESaIS7_EERKS4_ISt10shared_ptrINS_16JoinDataVariantsEESaISE_EE
_ZN5doris29try_convert_to_direct_mappingINS_16MethodSerializedINS_13JoinHashTableINS_9StringRefENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
14.1k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodOneNumberIN4wide7integerILm256EjEENS_13JoinHashTableIS4_NS_17HashCRC32Return32IS4_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
Line
Count
Source
203
25
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectIhNS_13JoinHashTableIhNS_17HashCRC32Return32IhEELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectItNS_13JoinHashTableItNS_17HashCRC32Return32ItEELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectIjNS_13JoinHashTableIjNS_17HashCRC32Return32IjEELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectImNS_13JoinHashTableImNS_17HashCRC32Return32ImEELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Unexecuted instantiation: _ZN5doris29try_convert_to_direct_mappingINS_21MethodOneNumberDirectIN4wide7integerILm128EjEENS_13JoinHashTableIS4_NS_17HashCRC32Return32IS4_EELb1EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableImNS_17HashCRC32Return32ImEELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISC_EERKS9_ISt10shared_ptrINS_16JoinDataVariantsEESaISJ_EE
Line
Count
Source
203
4.22k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableINS_6UInt72ENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
3.21k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableINS_6UInt96ENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
8.01k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableINS_7UInt104ENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
13
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableIN4wide7integerILm128EjEENS_17HashCRC32Return32IS5_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
Line
Count
Source
203
8.01k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableINS_7UInt136ENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
960
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_15MethodKeysFixedINS_13JoinHashTableIN4wide7integerILm256EjEENS_17HashCRC32Return32IS5_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISF_EERKSC_ISt10shared_ptrINS_16JoinDataVariantsEESaISM_EE
Line
Count
Source
203
7.92k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
_ZN5doris29try_convert_to_direct_mappingINS_19MethodStringNoCacheINS_13JoinHashTableINS_9StringRefENS_17HashCRC32Return32IS3_EELb0EEEEEEEvPT_RKSt6vectorIPKNS_7IColumnESaISD_EERKSA_ISt10shared_ptrINS_16JoinDataVariantsEESaISK_EE
Line
Count
Source
203
645
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {}
204
205
inline void try_convert_to_direct_mapping(
206
        PrimaryTypeHashTableContext<UInt8>* context, const ColumnRawPtrs& key_columns,
207
561
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
208
561
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
209
561
}
210
211
inline void try_convert_to_direct_mapping(
212
        PrimaryTypeHashTableContext<UInt16>* context, const ColumnRawPtrs& key_columns,
213
309
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
214
309
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
215
309
}
216
217
inline void try_convert_to_direct_mapping(
218
        PrimaryTypeHashTableContext<UInt32>* context, const ColumnRawPtrs& key_columns,
219
6.02k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
220
6.02k
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
221
6.02k
}
222
223
inline void try_convert_to_direct_mapping(
224
        PrimaryTypeHashTableContext<UInt64>* context, const ColumnRawPtrs& key_columns,
225
1.80k
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
226
1.80k
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
227
1.80k
}
228
229
inline void try_convert_to_direct_mapping(
230
        PrimaryTypeHashTableContext<UInt128>* context, const ColumnRawPtrs& key_columns,
231
503
        const std::vector<std::shared_ptr<JoinDataVariants>>& variant_ptrs) {
232
503
    primary_to_direct_mapping(context, key_columns, variant_ptrs);
233
503
}
234
235
// ASOF JOIN index with inline values for cache-friendly branchless binary search.
236
// IntType is the integer representation of the ASOF column value:
237
//   uint32_t for DateV2, uint64_t for DateTimeV2 and TimestampTZ.
238
// Rows are sorted by asof_value during build, then materialized into SoA arrays
239
// so probe-side binary search only touches the ASOF values hot path.
240
template <typename IntType>
241
struct AsofIndexGroup {
242
    using int_type = IntType;
243
244
    struct Entry {
245
        IntType asof_value;
246
        uint32_t row_index; // 1-based, 0 = invalid/padding
247
    };
248
249
    std::vector<Entry> entries;
250
    std::vector<IntType> asof_values;
251
    std::vector<uint32_t> row_indexes;
252
253
5.85k
    void add_row(IntType value, uint32_t row_idx) { entries.push_back({value, row_idx}); }
_ZN5doris14AsofIndexGroupIjE7add_rowEjj
Line
Count
Source
253
1.05k
    void add_row(IntType value, uint32_t row_idx) { entries.push_back({value, row_idx}); }
_ZN5doris14AsofIndexGroupImE7add_rowEmj
Line
Count
Source
253
4.80k
    void add_row(IntType value, uint32_t row_idx) { entries.push_back({value, row_idx}); }
254
255
585
    void sort_and_finalize() {
256
585
        if (entries.empty()) {
257
4
            return;
258
4
        }
259
581
        if (entries.size() > 1) {
260
548
            pdqsort(entries.begin(), entries.end(),
261
23.2k
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
_ZZN5doris14AsofIndexGroupIjE17sort_and_finalizeEvENKUlRKNS1_5EntryES4_E_clES4_S4_
Line
Count
Source
261
2.05k
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
_ZZN5doris14AsofIndexGroupImE17sort_and_finalizeEvENKUlRKNS1_5EntryES4_E_clES4_S4_
Line
Count
Source
261
21.1k
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
262
548
        }
263
264
581
        asof_values.resize(entries.size());
265
581
        row_indexes.resize(entries.size());
266
6.45k
        for (size_t i = 0; i < entries.size(); ++i) {
267
5.87k
            asof_values[i] = entries[i].asof_value;
268
5.87k
            row_indexes[i] = entries[i].row_index;
269
5.87k
        }
270
271
581
        std::vector<Entry>().swap(entries);
272
581
    }
_ZN5doris14AsofIndexGroupIjE17sort_and_finalizeEv
Line
Count
Source
255
19
    void sort_and_finalize() {
256
19
        if (entries.empty()) {
257
4
            return;
258
4
        }
259
15
        if (entries.size() > 1) {
260
12
            pdqsort(entries.begin(), entries.end(),
261
12
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
262
12
        }
263
264
15
        asof_values.resize(entries.size());
265
15
        row_indexes.resize(entries.size());
266
1.06k
        for (size_t i = 0; i < entries.size(); ++i) {
267
1.05k
            asof_values[i] = entries[i].asof_value;
268
1.05k
            row_indexes[i] = entries[i].row_index;
269
1.05k
        }
270
271
15
        std::vector<Entry>().swap(entries);
272
15
    }
_ZN5doris14AsofIndexGroupImE17sort_and_finalizeEv
Line
Count
Source
255
566
    void sort_and_finalize() {
256
566
        if (entries.empty()) {
257
0
            return;
258
0
        }
259
566
        if (entries.size() > 1) {
260
536
            pdqsort(entries.begin(), entries.end(),
261
536
                    [](const Entry& a, const Entry& b) { return a.asof_value < b.asof_value; });
262
536
        }
263
264
566
        asof_values.resize(entries.size());
265
566
        row_indexes.resize(entries.size());
266
5.39k
        for (size_t i = 0; i < entries.size(); ++i) {
267
4.82k
            asof_values[i] = entries[i].asof_value;
268
4.82k
            row_indexes[i] = entries[i].row_index;
269
4.82k
        }
270
271
566
        std::vector<Entry>().swap(entries);
272
566
    }
273
274
714
    const IntType* values_data() const { return asof_values.data(); }
_ZNK5doris14AsofIndexGroupIjE11values_dataEv
Line
Count
Source
274
1
    const IntType* values_data() const { return asof_values.data(); }
_ZNK5doris14AsofIndexGroupImE11values_dataEv
Line
Count
Source
274
713
    const IntType* values_data() const { return asof_values.data(); }
275
276
    // Branchless lower_bound: first i where asof_values[i] >= target
277
403
    ALWAYS_INLINE size_t lower_bound(IntType target) const {
278
403
        size_t lo = 0, n = asof_values.size();
279
2.20k
        while (n > 1) {
280
1.80k
            size_t half = n / 2;
281
1.80k
            lo += half * (asof_values[lo + half] < target);
282
1.80k
            n -= half;
283
1.80k
        }
284
403
        if (lo < asof_values.size()) {
285
402
            lo += (asof_values[lo] < target);
286
402
        }
287
403
        return lo;
288
403
    }
_ZNK5doris14AsofIndexGroupIjE11lower_boundEj
Line
Count
Source
277
33
    ALWAYS_INLINE size_t lower_bound(IntType target) const {
278
33
        size_t lo = 0, n = asof_values.size();
279
163
        while (n > 1) {
280
130
            size_t half = n / 2;
281
130
            lo += half * (asof_values[lo + half] < target);
282
130
            n -= half;
283
130
        }
284
33
        if (lo < asof_values.size()) {
285
32
            lo += (asof_values[lo] < target);
286
32
        }
287
33
        return lo;
288
33
    }
_ZNK5doris14AsofIndexGroupImE11lower_boundEm
Line
Count
Source
277
370
    ALWAYS_INLINE size_t lower_bound(IntType target) const {
278
370
        size_t lo = 0, n = asof_values.size();
279
2.04k
        while (n > 1) {
280
1.67k
            size_t half = n / 2;
281
1.67k
            lo += half * (asof_values[lo + half] < target);
282
1.67k
            n -= half;
283
1.67k
        }
284
370
        if (lo < asof_values.size()) {
285
370
            lo += (asof_values[lo] < target);
286
370
        }
287
370
        return lo;
288
370
    }
289
290
    // Branchless upper_bound: first i where asof_values[i] > target
291
801
    ALWAYS_INLINE size_t upper_bound(IntType target) const {
292
801
        size_t lo = 0, n = asof_values.size();
293
3.78k
        while (n > 1) {
294
2.98k
            size_t half = n / 2;
295
2.98k
            lo += half * (asof_values[lo + half] <= target);
296
2.98k
            n -= half;
297
2.98k
        }
298
801
        if (lo < asof_values.size()) {
299
800
            lo += (asof_values[lo] <= target);
300
800
        }
301
801
        return lo;
302
801
    }
_ZNK5doris14AsofIndexGroupIjE11upper_boundEj
Line
Count
Source
291
38
    ALWAYS_INLINE size_t upper_bound(IntType target) const {
292
38
        size_t lo = 0, n = asof_values.size();
293
208
        while (n > 1) {
294
170
            size_t half = n / 2;
295
170
            lo += half * (asof_values[lo + half] <= target);
296
170
            n -= half;
297
170
        }
298
38
        if (lo < asof_values.size()) {
299
37
            lo += (asof_values[lo] <= target);
300
37
        }
301
38
        return lo;
302
38
    }
_ZNK5doris14AsofIndexGroupImE11upper_boundEm
Line
Count
Source
291
763
    ALWAYS_INLINE size_t upper_bound(IntType target) const {
292
763
        size_t lo = 0, n = asof_values.size();
293
3.58k
        while (n > 1) {
294
2.81k
            size_t half = n / 2;
295
2.81k
            lo += half * (asof_values[lo + half] <= target);
296
2.81k
            n -= half;
297
2.81k
        }
298
763
        if (lo < asof_values.size()) {
299
763
            lo += (asof_values[lo] <= target);
300
763
        }
301
763
        return lo;
302
763
    }
303
304
    // Semantics by (is_greater, is_strict):
305
    //   (true,  false): probe >= build  ->  find largest  build value <= probe
306
    //   (true,  true):  probe >  build  ->  find largest  build value <  probe
307
    //   (false, false): probe <= build  ->  find smallest build value >= probe
308
    //   (false, true):  probe <  build  ->  find smallest build value >  probe
309
    // Returns the build row index of the best match, or 0 if no match.
310
    template <bool IsGreater, bool IsStrict>
311
1.19k
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
1.19k
        if (asof_values.empty()) {
313
4
            return 0;
314
4
        }
315
1.18k
        if constexpr (IsGreater) {
316
792
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
792
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
792
        } else {
319
394
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
394
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
394
        }
322
1.18k
    }
_ZNK5doris14AsofIndexGroupIjE15find_best_matchILb1ELb1EEEjj
Line
Count
Source
311
15
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
15
        if (asof_values.empty()) {
313
1
            return 0;
314
1
        }
315
14
        if constexpr (IsGreater) {
316
14
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
14
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
        } else {
319
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
        }
322
14
    }
_ZNK5doris14AsofIndexGroupIjE15find_best_matchILb1ELb0EEEjj
Line
Count
Source
311
19
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
19
        if (asof_values.empty()) {
313
1
            return 0;
314
1
        }
315
18
        if constexpr (IsGreater) {
316
18
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
18
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
        } else {
319
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
        }
322
18
    }
_ZNK5doris14AsofIndexGroupIjE15find_best_matchILb0ELb1EEEjj
Line
Count
Source
311
16
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
16
        if (asof_values.empty()) {
313
1
            return 0;
314
1
        }
315
        if constexpr (IsGreater) {
316
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
15
        } else {
319
15
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
15
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
15
        }
322
15
    }
_ZNK5doris14AsofIndexGroupIjE15find_best_matchILb0ELb0EEEjj
Line
Count
Source
311
15
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
15
        if (asof_values.empty()) {
313
1
            return 0;
314
1
        }
315
        if constexpr (IsGreater) {
316
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
14
        } else {
319
14
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
14
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
14
        }
322
14
    }
_ZNK5doris14AsofIndexGroupImE15find_best_matchILb1ELb1EEEjm
Line
Count
Source
311
178
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
178
        if (asof_values.empty()) {
313
0
            return 0;
314
0
        }
315
178
        if constexpr (IsGreater) {
316
178
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
178
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
        } else {
319
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
        }
322
178
    }
_ZNK5doris14AsofIndexGroupImE15find_best_matchILb1ELb0EEEjm
Line
Count
Source
311
582
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
582
        if (asof_values.empty()) {
313
0
            return 0;
314
0
        }
315
582
        if constexpr (IsGreater) {
316
582
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
582
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
        } else {
319
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
        }
322
582
    }
_ZNK5doris14AsofIndexGroupImE15find_best_matchILb0ELb1EEEjm
Line
Count
Source
311
177
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
177
        if (asof_values.empty()) {
313
0
            return 0;
314
0
        }
315
        if constexpr (IsGreater) {
316
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
177
        } else {
319
177
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
177
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
177
        }
322
177
    }
_ZNK5doris14AsofIndexGroupImE15find_best_matchILb0ELb0EEEjm
Line
Count
Source
311
188
    ALWAYS_INLINE uint32_t find_best_match(IntType probe_value) const {
312
188
        if (asof_values.empty()) {
313
0
            return 0;
314
0
        }
315
        if constexpr (IsGreater) {
316
            size_t pos = IsStrict ? lower_bound(probe_value) : upper_bound(probe_value);
317
            return pos > 0 ? row_indexes[pos - 1] : 0;
318
188
        } else {
319
188
            size_t pos = IsStrict ? upper_bound(probe_value) : lower_bound(probe_value);
320
188
            return pos < asof_values.size() ? row_indexes[pos] : 0;
321
188
        }
322
188
    }
323
};
324
325
// Type-erased container for all ASOF index groups.
326
// DateV2 -> uint32_t, DateTimeV2/TimestampTZ -> uint64_t.
327
using AsofIndexVariant = std::variant<std::monostate, std::vector<AsofIndexGroup<uint32_t>>,
328
                                      std::vector<AsofIndexGroup<uint64_t>>>;
329
330
} // namespace doris