Coverage Report

Created: 2025-06-17 14:03

/root/doris/be/src/pipeline/dependency.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "dependency.h"
19
20
#include <memory>
21
#include <mutex>
22
23
#include "common/logging.h"
24
#include "pipeline/exec/multi_cast_data_streamer.h"
25
#include "pipeline/pipeline_fragment_context.h"
26
#include "pipeline/pipeline_task.h"
27
#include "runtime/exec_env.h"
28
#include "runtime/memory/mem_tracker.h"
29
#include "runtime_filter/runtime_filter_consumer.h"
30
#include "util/brpc_client_cache.h"
31
#include "vec/exprs/vectorized_agg_fn.h"
32
#include "vec/exprs/vslot_ref.h"
33
#include "vec/spill/spill_stream_manager.h"
34
#include "vec/utils/util.hpp"
35
36
namespace doris::pipeline {
37
#include "common/compile_check_begin.h"
38
39
Dependency* BasicSharedState::create_source_dependency(int operator_id, int node_id,
40
78.2k
                                                       const std::string& name) {
41
78.2k
    source_deps.push_back(std::make_shared<Dependency>(operator_id, node_id, name + "_DEPENDENCY"));
42
78.2k
    source_deps.back()->set_shared_state(this);
43
78.2k
    return source_deps.back().get();
44
78.2k
}
45
46
void BasicSharedState::create_source_dependencies(int num_sources, int operator_id, int node_id,
47
17
                                                  const std::string& name) {
48
17
    source_deps.resize(num_sources, nullptr);
49
150
    for (auto& source_dep : source_deps) {
50
150
        source_dep = std::make_shared<Dependency>(operator_id, node_id, name + "_DEPENDENCY");
51
150
        source_dep->set_shared_state(this);
52
150
    }
53
17
}
54
55
Dependency* BasicSharedState::create_sink_dependency(int dest_id, int node_id,
56
78.5k
                                                     const std::string& name) {
57
78.5k
    sink_deps.push_back(std::make_shared<Dependency>(dest_id, node_id, name + "_DEPENDENCY", true));
58
78.5k
    sink_deps.back()->set_shared_state(this);
59
78.5k
    return sink_deps.back().get();
60
78.5k
}
61
62
2.75k
void Dependency::_add_block_task(std::shared_ptr<PipelineTask> task) {
63
2.75k
    DCHECK(_blocked_task.empty() || _blocked_task[_blocked_task.size() - 1].lock() == nullptr ||
64
0
           _blocked_task[_blocked_task.size() - 1].lock().get() != task.get())
65
0
            << "Duplicate task: " << task->debug_string();
66
2.75k
    _blocked_task.push_back(task);
67
2.75k
}
68
69
137k
void Dependency::set_ready() {
70
137k
    if (_ready) {
71
81.1k
        return;
72
81.1k
    }
73
56.2k
    _watcher.stop();
74
56.2k
    std::vector<std::weak_ptr<PipelineTask>> local_block_task {};
75
56.2k
    {
76
56.2k
        std::unique_lock<std::mutex> lc(_task_lock);
77
56.2k
        if (_ready) {
78
0
            return;
79
0
        }
80
56.2k
        _ready = true;
81
56.2k
        local_block_task.swap(_blocked_task);
82
56.2k
    }
83
2.74k
    for (auto task : local_block_task) {
84
2.74k
        if (auto t = task.lock()) {
85
2.74k
            std::unique_lock<std::mutex> lc(_task_lock);
86
2.74k
            THROW_IF_ERROR(t->wake_up(this));
87
2.74k
        }
88
2.74k
    }
89
56.2k
}
90
91
3.45M
Dependency* Dependency::is_blocked_by(std::shared_ptr<PipelineTask> task) {
92
3.45M
    std::unique_lock<std::mutex> lc(_task_lock);
93
3.45M
    auto ready = _ready.load();
94
3.45M
    if (!ready && task) {
95
2.75k
        _add_block_task(task);
96
2.75k
        start_watcher();
97
2.75k
        THROW_IF_ERROR(task->blocked(this));
98
2.75k
    }
99
3.45M
    return ready ? nullptr : this;
100
3.45M
}
101
102
126k
std::string Dependency::debug_string(int indentation_level) {
103
126k
    fmt::memory_buffer debug_string_buffer;
104
126k
    fmt::format_to(debug_string_buffer, "{}{}: id={}, block task = {}, ready={}, _always_ready={}",
105
126k
                   std::string(indentation_level * 2, ' '), _name, _node_id, _blocked_task.size(),
106
126k
                   _ready, _always_ready);
107
126k
    return fmt::to_string(debug_string_buffer);
108
126k
}
109
110
0
std::string CountedFinishDependency::debug_string(int indentation_level) {
111
0
    fmt::memory_buffer debug_string_buffer;
112
0
    fmt::format_to(debug_string_buffer,
113
0
                   "{}{}: id={}, block_task={}, ready={}, _always_ready={}, count={}",
114
0
                   std::string(indentation_level * 2, ' '), _name, _node_id, _blocked_task.size(),
115
0
                   _ready, _always_ready, _counter);
116
0
    return fmt::to_string(debug_string_buffer);
117
0
}
118
119
0
void RuntimeFilterTimer::call_timeout() {
120
0
    _parent->set_ready();
121
0
}
122
123
2
void RuntimeFilterTimer::call_ready() {
124
2
    _parent->set_ready();
125
2
}
126
127
// should check rf timeout in two case:
128
// 1. the rf is ready just remove the wait queue
129
// 2. if the rf have local dependency, the rf should start wait when all local dependency is ready
130
2
bool RuntimeFilterTimer::should_be_check_timeout() {
131
2
    if (!_parent->ready() && !_local_runtime_filter_dependencies.empty()) {
132
0
        bool all_ready = true;
133
0
        for (auto& dep : _local_runtime_filter_dependencies) {
134
0
            if (!dep->ready()) {
135
0
                all_ready = false;
136
0
                break;
137
0
            }
138
0
        }
139
0
        if (all_ready) {
140
0
            _local_runtime_filter_dependencies.clear();
141
0
            _registration_time = MonotonicMillis();
142
0
        }
143
0
        return all_ready;
144
0
    }
145
2
    return true;
146
2
}
147
148
5
void RuntimeFilterTimerQueue::start() {
149
10
    while (!_stop) {
150
7
        std::unique_lock<std::mutex> lk(cv_m);
151
152
1.82k
        while (_que.empty() && !_stop) {
153
3.63k
            cv.wait_for(lk, std::chrono::seconds(3), [this] { return !_que.empty() || _stop; });
154
1.82k
        }
155
7
        if (_stop) {
156
2
            break;
157
2
        }
158
5
        {
159
5
            std::unique_lock<std::mutex> lc(_que_lock);
160
5
            std::list<std::shared_ptr<pipeline::RuntimeFilterTimer>> new_que;
161
5
            for (auto& it : _que) {
162
4
                if (it.use_count() == 1) {
163
                    // `use_count == 1` means this runtime filter has been released
164
2
                } else if (it->should_be_check_timeout()) {
165
2
                    if (it->force_wait_timeout() || it->_parent->is_blocked_by()) {
166
                        // This means runtime filter is not ready, so we call timeout or continue to poll this timer.
167
2
                        int64_t ms_since_registration = MonotonicMillis() - it->registration_time();
168
2
                        if (ms_since_registration > it->wait_time_ms()) {
169
0
                            it->call_timeout();
170
2
                        } else {
171
2
                            new_que.push_back(std::move(it));
172
2
                        }
173
2
                    }
174
2
                } else {
175
0
                    new_que.push_back(std::move(it));
176
0
                }
177
4
            }
178
5
            new_que.swap(_que);
179
5
        }
180
5
        std::this_thread::sleep_for(std::chrono::milliseconds(interval));
181
5
    }
182
5
    _shutdown = true;
183
5
}
184
185
30
void LocalExchangeSharedState::sub_running_sink_operators() {
186
30
    std::unique_lock<std::mutex> lc(le_lock);
187
30
    if (exchanger->_running_sink_operators.fetch_sub(1) == 1) {
188
15
        _set_always_ready();
189
15
    }
190
30
}
191
192
138
void LocalExchangeSharedState::sub_running_source_operators() {
193
138
    std::unique_lock<std::mutex> lc(le_lock);
194
138
    if (exchanger->_running_source_operators.fetch_sub(1) == 1) {
195
15
        _set_always_ready();
196
15
        exchanger->finalize();
197
15
    }
198
138
}
199
200
16
LocalExchangeSharedState::LocalExchangeSharedState(int num_instances) {
201
16
    source_deps.resize(num_instances, nullptr);
202
16
    mem_counters.resize(num_instances, nullptr);
203
16
}
204
205
4
vectorized::MutableColumns AggSharedState::_get_keys_hash_table() {
206
4
    return std::visit(
207
4
            vectorized::Overload {
208
4
                    [&](std::monostate& arg) {
209
0
                        throw doris::Exception(ErrorCode::INTERNAL_ERROR, "uninited hash table");
210
0
                        return vectorized::MutableColumns();
211
0
                    },
212
4
                    [&](auto&& agg_method) -> vectorized::MutableColumns {
213
4
                        vectorized::MutableColumns key_columns;
214
8
                        for (int i = 0; i < probe_expr_ctxs.size(); ++i) {
215
4
                            key_columns.emplace_back(
216
4
                                    probe_expr_ctxs[i]->root()->data_type()->create_column());
217
4
                        }
218
4
                        auto& data = *agg_method.hash_table;
219
4
                        bool has_null_key = data.has_null_key_data();
220
4
                        const auto size = data.size() - has_null_key;
221
4
                        using KeyType = std::decay_t<decltype(agg_method)>::Key;
222
4
                        std::vector<KeyType> keys(size);
223
224
4
                        size_t num_rows = 0;
225
4
                        auto iter = aggregate_data_container->begin();
226
4
                        {
227
27
                            while (iter != aggregate_data_container->end()) {
228
23
                                keys[num_rows] = iter.get_key<KeyType>();
229
23
                                ++iter;
230
23
                                ++num_rows;
231
23
                            }
232
4
                        }
233
4
                        agg_method.insert_keys_into_columns(keys, key_columns, num_rows);
234
4
                        if (has_null_key) {
235
1
                            key_columns[0]->insert_data(nullptr, 0);
236
1
                        }
237
4
                        return key_columns;
238
4
                    }},
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISG_EESaISJ_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISF_EESaISI_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISF_EESaISI_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISF_EESaISI_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISF_EESaISI_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISG_EESaISJ_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISI_EESaISL_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISI_EESaISL_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISH_EESaISK_EEOT_
dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISH_EESaISK_EEOT_
Line
Count
Source
212
2
                    [&](auto&& agg_method) -> vectorized::MutableColumns {
213
2
                        vectorized::MutableColumns key_columns;
214
4
                        for (int i = 0; i < probe_expr_ctxs.size(); ++i) {
215
2
                            key_columns.emplace_back(
216
2
                                    probe_expr_ctxs[i]->root()->data_type()->create_column());
217
2
                        }
218
2
                        auto& data = *agg_method.hash_table;
219
2
                        bool has_null_key = data.has_null_key_data();
220
2
                        const auto size = data.size() - has_null_key;
221
2
                        using KeyType = std::decay_t<decltype(agg_method)>::Key;
222
2
                        std::vector<KeyType> keys(size);
223
224
2
                        size_t num_rows = 0;
225
2
                        auto iter = aggregate_data_container->begin();
226
2
                        {
227
14
                            while (iter != aggregate_data_container->end()) {
228
12
                                keys[num_rows] = iter.get_key<KeyType>();
229
12
                                ++iter;
230
12
                                ++num_rows;
231
12
                            }
232
2
                        }
233
2
                        agg_method.insert_keys_into_columns(keys, key_columns, num_rows);
234
2
                        if (has_null_key) {
235
0
                            key_columns[0]->insert_data(nullptr, 0);
236
0
                        }
237
2
                        return key_columns;
238
2
                    }},
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIhNS4_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISJ_EESaISM_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberItNS4_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISJ_EESaISM_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIjNS4_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISJ_EESaISM_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberImNS4_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISJ_EESaISM_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIjNS4_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISL_EESaISO_EEOT_
dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberImNS4_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISL_EESaISO_EEOT_
Line
Count
Source
212
2
                    [&](auto&& agg_method) -> vectorized::MutableColumns {
213
2
                        vectorized::MutableColumns key_columns;
214
4
                        for (int i = 0; i < probe_expr_ctxs.size(); ++i) {
215
2
                            key_columns.emplace_back(
216
2
                                    probe_expr_ctxs[i]->root()->data_type()->create_column());
217
2
                        }
218
2
                        auto& data = *agg_method.hash_table;
219
2
                        bool has_null_key = data.has_null_key_data();
220
2
                        const auto size = data.size() - has_null_key;
221
2
                        using KeyType = std::decay_t<decltype(agg_method)>::Key;
222
2
                        std::vector<KeyType> keys(size);
223
224
2
                        size_t num_rows = 0;
225
2
                        auto iter = aggregate_data_container->begin();
226
2
                        {
227
13
                            while (iter != aggregate_data_container->end()) {
228
11
                                keys[num_rows] = iter.get_key<KeyType>();
229
11
                                ++iter;
230
11
                                ++num_rows;
231
11
                            }
232
2
                        }
233
2
                        agg_method.insert_keys_into_columns(keys, key_columns, num_rows);
234
2
                        if (has_null_key) {
235
1
                            key_columns[0]->insert_data(nullptr, 0);
236
1
                        }
237
2
                        return key_columns;
238
2
                    }},
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIN4wide7integerILm128EjEENS4_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISM_EESaISP_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIN4wide7integerILm256EjEENS4_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISM_EESaISP_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized26MethodSingleNullableColumnINS4_19MethodStringNoCacheINS4_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISK_EESaISN_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISF_EESaISI_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISI_EESaISL_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISI_EESaISL_EEOT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState20_get_keys_hash_tableEvENK3$_1clIRNS_10vectorized15MethodKeysFixedI9PHHashMapINS4_7UInt136EPc9HashCRC32IS7_EEEEEESt6vectorINS_3COWINS4_7IColumnEE11mutable_ptrISG_EESaISJ_EEOT_
239
4
            agg_data->method_variant);
240
4
}
241
242
4
void AggSharedState::build_limit_heap(size_t hash_table_size) {
243
4
    limit_columns = _get_keys_hash_table();
244
28
    for (size_t i = 0; i < hash_table_size; ++i) {
245
24
        limit_heap.emplace(i, limit_columns, order_directions, null_directions);
246
24
    }
247
16
    while (hash_table_size > limit) {
248
12
        limit_heap.pop();
249
12
        hash_table_size--;
250
12
    }
251
4
    limit_columns_min = limit_heap.top()._row_id;
252
4
}
253
254
bool AggSharedState::do_limit_filter(vectorized::Block* block, size_t num_rows,
255
8
                                     const std::vector<int>* key_locs) {
256
8
    if (num_rows) {
257
8
        cmp_res.resize(num_rows);
258
8
        need_computes.resize(num_rows);
259
8
        memset(need_computes.data(), 0, need_computes.size());
260
8
        memset(cmp_res.data(), 0, cmp_res.size());
261
262
8
        const auto key_size = null_directions.size();
263
16
        for (int i = 0; i < key_size; i++) {
264
8
            block->get_by_position(key_locs ? key_locs->operator[](i) : i)
265
8
                    .column->compare_internal(limit_columns_min, *limit_columns[i],
266
8
                                              null_directions[i], order_directions[i], cmp_res,
267
8
                                              need_computes.data());
268
8
        }
269
270
8
        auto set_computes_arr = [](auto* __restrict res, auto* __restrict computes, size_t rows) {
271
58
            for (size_t i = 0; i < rows; ++i) {
272
50
                computes[i] = computes[i] == res[i];
273
50
            }
274
8
        };
275
8
        set_computes_arr(cmp_res.data(), need_computes.data(), num_rows);
276
277
8
        return std::find(need_computes.begin(), need_computes.end(), 0) != need_computes.end();
278
8
    }
279
280
0
    return false;
281
8
}
282
283
15
Status AggSharedState::reset_hash_table() {
284
15
    return std::visit(
285
15
            vectorized::Overload {
286
15
                    [&](std::monostate& arg) -> Status {
287
0
                        return Status::InternalError("Uninited hash table");
288
0
                    },
289
15
                    [&](auto& agg_method) {
290
15
                        auto& hash_table = *agg_method.hash_table;
291
15
                        using HashTableType = std::decay_t<decltype(hash_table)>;
292
293
15
                        agg_method.arena.clear();
294
15
                        agg_method.inited_iterator = false;
295
296
1.04M
                        hash_table.for_each_mapped([&](auto& mapped) {
297
1.04M
                            if (mapped) {
298
1.04M
                                static_cast<void>(_destroy_agg_status(mapped));
299
1.04M
                                mapped = nullptr;
300
1.04M
                            }
301
1.04M
                        });
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEDaRT_ENKUlSE_E_clIS8_EEDaSE_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEDaRT_ENKUlSD_E_clIS7_EEDaSD_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEDaRT_ENKUlSD_E_clIS7_EEDaSD_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEDaRT_ENKUlSD_E_clIS7_EEDaSD_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEDaRT_ENKUlSD_E_clIS7_EEDaSD_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEEDaRT_ENKUlSE_E_clIS7_EEDaSE_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEEDaRT_ENKUlSG_E_clISA_EEDaSG_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEEDaRT_ENKUlSG_E_clISA_EEDaSG_
dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEDaRT_ENKUlSF_E_clIS7_EEDaSF_
Line
Count
Source
296
1.04M
                        hash_table.for_each_mapped([&](auto& mapped) {
297
1.04M
                            if (mapped) {
298
1.04M
                                static_cast<void>(_destroy_agg_status(mapped));
299
1.04M
                                mapped = nullptr;
300
1.04M
                            }
301
1.04M
                        });
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEDaRT_ENKUlSF_E_clIS7_EEDaSF_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIhNS4_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEDaRT_ENKUlSH_E_clIS9_EEDaSH_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberItNS4_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEDaRT_ENKUlSH_E_clIS9_EEDaSH_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIjNS4_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEDaRT_ENKUlSH_E_clIS9_EEDaSH_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberImNS4_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEDaRT_ENKUlSH_E_clIS9_EEDaSH_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIjNS4_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEDaRT_ENKUlSJ_E_clIS9_EEDaSJ_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberImNS4_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEDaRT_ENKUlSJ_E_clIS9_EEDaSJ_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIN4wide7integerILm128EjEENS4_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEDaRT_ENKUlSK_E_clISC_EEDaSK_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIN4wide7integerILm256EjEENS4_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEDaRT_ENKUlSK_E_clISC_EEDaSK_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_19MethodStringNoCacheINS4_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEEEEEEDaRT_ENKUlSI_E_clIS9_EEDaSI_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEDaRT_ENKUlSD_E_clIS7_EEDaSD_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEDaRT_ENKUlSG_E_clISA_EEDaSG_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEDaRT_ENKUlSG_E_clISA_EEDaSG_
Unexecuted instantiation: dependency.cpp:_ZZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodKeysFixedI9PHHashMapINS4_7UInt136EPc9HashCRC32IS7_EEEEEEDaRT_ENKUlSE_E_clIS8_EEDaSE_
302
303
15
                        if (hash_table.has_null_key_data()) {
304
0
                            auto st = _destroy_agg_status(hash_table.template get_null_key_data<
305
0
                                                          vectorized::AggregateDataPtr>());
306
0
                            RETURN_IF_ERROR(st);
307
0
                        }
308
309
15
                        aggregate_data_container.reset(new AggregateDataContainer(
310
15
                                sizeof(typename HashTableType::key_type),
311
15
                                ((total_size_of_aggregate_states + align_aggregate_states - 1) /
312
15
                                 align_aggregate_states) *
313
15
                                        align_aggregate_states));
314
15
                        agg_method.hash_table.reset(new HashTableType());
315
15
                        agg_arena_pool.reset(new vectorized::Arena);
316
15
                        return Status::OK();
317
15
                    }},
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEEDaRT_
dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEDaRT_
Line
Count
Source
289
15
                    [&](auto& agg_method) {
290
15
                        auto& hash_table = *agg_method.hash_table;
291
15
                        using HashTableType = std::decay_t<decltype(hash_table)>;
292
293
15
                        agg_method.arena.clear();
294
15
                        agg_method.inited_iterator = false;
295
296
15
                        hash_table.for_each_mapped([&](auto& mapped) {
297
15
                            if (mapped) {
298
15
                                static_cast<void>(_destroy_agg_status(mapped));
299
15
                                mapped = nullptr;
300
15
                            }
301
15
                        });
302
303
15
                        if (hash_table.has_null_key_data()) {
304
0
                            auto st = _destroy_agg_status(hash_table.template get_null_key_data<
305
0
                                                          vectorized::AggregateDataPtr>());
306
0
                            RETURN_IF_ERROR(st);
307
0
                        }
308
309
15
                        aggregate_data_container.reset(new AggregateDataContainer(
310
15
                                sizeof(typename HashTableType::key_type),
311
15
                                ((total_size_of_aggregate_states + align_aggregate_states - 1) /
312
15
                                 align_aggregate_states) *
313
15
                                        align_aggregate_states));
314
15
                        agg_method.hash_table.reset(new HashTableType());
315
15
                        agg_arena_pool.reset(new vectorized::Arena);
316
15
                        return Status::OK();
317
15
                    }},
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIhNS4_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberItNS4_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIjNS4_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberImNS4_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIjNS4_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberImNS4_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIN4wide7integerILm128EjEENS4_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIN4wide7integerILm256EjEENS4_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized26MethodSingleNullableColumnINS4_19MethodStringNoCacheINS4_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEDaRT_
Unexecuted instantiation: dependency.cpp:_ZZN5doris8pipeline14AggSharedState16reset_hash_tableEvENK3$_1clINS_10vectorized15MethodKeysFixedI9PHHashMapINS4_7UInt136EPc9HashCRC32IS7_EEEEEEDaRT_
318
15
            agg_data->method_variant);
319
15
}
320
321
11
void PartitionedAggSharedState::init_spill_params(size_t spill_partition_count) {
322
11
    partition_count = spill_partition_count;
323
11
    max_partition_index = partition_count - 1;
324
325
363
    for (int i = 0; i < partition_count; ++i) {
326
352
        spill_partitions.emplace_back(std::make_shared<AggSpillPartition>());
327
352
    }
328
11
}
329
330
0
void PartitionedAggSharedState::update_spill_stream_profiles(RuntimeProfile* source_profile) {
331
0
    for (auto& partition : spill_partitions) {
332
0
        if (partition->spilling_stream_) {
333
0
            partition->spilling_stream_->update_shared_profiles(source_profile);
334
0
        }
335
0
        for (auto& stream : partition->spill_streams_) {
336
0
            if (stream) {
337
0
                stream->update_shared_profiles(source_profile);
338
0
            }
339
0
        }
340
0
    }
341
0
}
342
343
Status AggSpillPartition::get_spill_stream(RuntimeState* state, int node_id,
344
                                           RuntimeProfile* profile,
345
65
                                           vectorized::SpillStreamSPtr& spill_stream) {
346
65
    if (spilling_stream_) {
347
16
        spill_stream = spilling_stream_;
348
16
        return Status::OK();
349
16
    }
350
49
    RETURN_IF_ERROR(ExecEnv::GetInstance()->spill_stream_mgr()->register_spill_stream(
351
49
            state, spilling_stream_, print_id(state->query_id()), "agg", node_id,
352
49
            std::numeric_limits<int32_t>::max(), std::numeric_limits<size_t>::max(), profile));
353
49
    spill_streams_.emplace_back(spilling_stream_);
354
49
    spill_stream = spilling_stream_;
355
49
    return Status::OK();
356
49
}
357
110
void AggSpillPartition::close() {
358
110
    if (spilling_stream_) {
359
1
        spilling_stream_.reset();
360
1
    }
361
110
    for (auto& stream : spill_streams_) {
362
5
        (void)ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
363
5
    }
364
110
    spill_streams_.clear();
365
110
}
366
367
7
void PartitionedAggSharedState::close() {
368
    // need to use CAS instead of only `if (!is_closed)` statement,
369
    // to avoid concurrent entry of close() both pass the if statement
370
7
    bool false_close = false;
371
7
    if (!is_closed.compare_exchange_strong(false_close, true)) {
372
2
        return;
373
2
    }
374
5
    DCHECK(!false_close && is_closed);
375
110
    for (auto partition : spill_partitions) {
376
110
        partition->close();
377
110
    }
378
5
    spill_partitions.clear();
379
5
}
380
381
4
void SpillSortSharedState::update_spill_stream_profiles(RuntimeProfile* source_profile) {
382
12
    for (auto& stream : sorted_streams) {
383
12
        if (stream) {
384
12
            stream->update_shared_profiles(source_profile);
385
12
        }
386
12
    }
387
4
}
388
389
7
void SpillSortSharedState::close() {
390
    // need to use CAS instead of only `if (!is_closed)` statement,
391
    // to avoid concurrent entry of close() both pass the if statement
392
7
    bool false_close = false;
393
7
    if (!is_closed.compare_exchange_strong(false_close, true)) {
394
2
        return;
395
2
    }
396
5
    DCHECK(!false_close && is_closed);
397
5
    for (auto& stream : sorted_streams) {
398
1
        (void)ExecEnv::GetInstance()->spill_stream_mgr()->delete_spill_stream(stream);
399
1
    }
400
5
    sorted_streams.clear();
401
5
}
402
403
MultiCastSharedState::MultiCastSharedState(ObjectPool* pool, int cast_sender_count, int node_id)
404
        : multi_cast_data_streamer(std::make_unique<pipeline::MultiCastDataStreamer>(
405
3
                  this, pool, cast_sender_count, node_id)) {}
406
407
0
void MultiCastSharedState::update_spill_stream_profiles(RuntimeProfile* source_profile) {}
408
409
7
int AggSharedState::get_slot_column_id(const vectorized::AggFnEvaluator* evaluator) {
410
7
    auto ctxs = evaluator->input_exprs_ctxs();
411
7
    CHECK(ctxs.size() == 1 && ctxs[0]->root()->is_slot_ref())
412
0
            << "input_exprs_ctxs is invalid, input_exprs_ctx[0]="
413
0
            << ctxs[0]->root()->debug_string();
414
7
    return ((vectorized::VSlotRef*)ctxs[0]->root().get())->column_id();
415
7
}
416
417
1.04M
Status AggSharedState::_destroy_agg_status(vectorized::AggregateDataPtr data) {
418
2.09M
    for (int i = 0; i < aggregate_evaluators.size(); ++i) {
419
1.04M
        aggregate_evaluators[i]->function()->destroy(data + offsets_of_aggregate_states[i]);
420
1.04M
    }
421
1.04M
    return Status::OK();
422
1.04M
}
423
424
16
LocalExchangeSharedState::~LocalExchangeSharedState() = default;
425
426
23
Status SetSharedState::update_build_not_ignore_null(const vectorized::VExprContextSPtrs& ctxs) {
427
23
    if (ctxs.size() > build_not_ignore_null.size()) {
428
0
        return Status::InternalError("build_not_ignore_null not initialized");
429
0
    }
430
431
60
    for (int i = 0; i < ctxs.size(); ++i) {
432
37
        build_not_ignore_null[i] = build_not_ignore_null[i] || ctxs[i]->root()->is_nullable();
433
37
    }
434
435
23
    return Status::OK();
436
23
}
437
438
13
size_t SetSharedState::get_hash_table_size() const {
439
13
    size_t hash_table_size = 0;
440
13
    std::visit(
441
13
            [&](auto&& arg) {
442
13
                using HashTableCtxType = std::decay_t<decltype(arg)>;
443
13
                if constexpr (!std::is_same_v<HashTableCtxType, std::monostate>) {
444
13
                    hash_table_size = arg.hash_table->size();
445
13
                }
446
13
            },
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRSt9monostateEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized16MethodSerializedI9PHHashMapINS_9StringRefENS_14RowRefWithFlagE11DefaultHashIS7_vEEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized19MethodStringNoCacheI9PHHashMapINS_9StringRefENS_14RowRefWithFlagE11DefaultHashIS7_vEEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIhNS4_15DataWithNullKeyI9PHHashMapIhNS_14RowRefWithFlagE9HashCRC32IhEEEEEEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberItNS4_15DataWithNullKeyI9PHHashMapItNS_14RowRefWithFlagE9HashCRC32ItEEEEEEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIjNS4_15DataWithNullKeyI9PHHashMapIjNS_14RowRefWithFlagE9HashCRC32IjEEEEEEEEEEDaOT_
dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberImNS4_15DataWithNullKeyI9PHHashMapImNS_14RowRefWithFlagE9HashCRC32ImEEEEEEEEEEDaOT_
Line
Count
Source
441
2
            [&](auto&& arg) {
442
2
                using HashTableCtxType = std::decay_t<decltype(arg)>;
443
2
                if constexpr (!std::is_same_v<HashTableCtxType, std::monostate>) {
444
2
                    hash_table_size = arg.hash_table->size();
445
2
                }
446
2
            },
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIN4wide7integerILm128EjEENS4_15DataWithNullKeyI9PHHashMapIS9_NS_14RowRefWithFlagE9HashCRC32IS9_EEEEEEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized26MethodSingleNullableColumnINS4_15MethodOneNumberIN4wide7integerILm256EjEENS4_15DataWithNullKeyI9PHHashMapIS9_NS_14RowRefWithFlagE9HashCRC32IS9_EEEEEEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodOneNumberIh9PHHashMapIhNS_14RowRefWithFlagE9HashCRC32IhEEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodOneNumberIt9PHHashMapItNS_14RowRefWithFlagE9HashCRC32ItEEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodOneNumberIj9PHHashMapIjNS_14RowRefWithFlagE9HashCRC32IjEEEEEEDaOT_
dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodOneNumberIm9PHHashMapImNS_14RowRefWithFlagE9HashCRC32ImEEEEEEDaOT_
Line
Count
Source
441
8
            [&](auto&& arg) {
442
8
                using HashTableCtxType = std::decay_t<decltype(arg)>;
443
8
                if constexpr (!std::is_same_v<HashTableCtxType, std::monostate>) {
444
8
                    hash_table_size = arg.hash_table->size();
445
8
                }
446
8
            },
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapIS8_NS_14RowRefWithFlagE9HashCRC32IS8_EEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapIS8_NS_14RowRefWithFlagE9HashCRC32IS8_EEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodKeysFixedI9PHHashMapImNS_14RowRefWithFlagE9HashCRC32ImEEEEEEDaOT_
Unexecuted instantiation: dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEENS_14RowRefWithFlagE9HashCRC32IS9_EEEEEEDaOT_
dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEENS_14RowRefWithFlagE9HashCRC32IS9_EEEEEEDaOT_
Line
Count
Source
441
2
            [&](auto&& arg) {
442
2
                using HashTableCtxType = std::decay_t<decltype(arg)>;
443
2
                if constexpr (!std::is_same_v<HashTableCtxType, std::monostate>) {
444
2
                    hash_table_size = arg.hash_table->size();
445
2
                }
446
2
            },
dependency.cpp:_ZZNK5doris8pipeline14SetSharedState19get_hash_table_sizeEvENK3$_0clIRNS_10vectorized15MethodKeysFixedI9PHHashMapINS4_7UInt136ENS_14RowRefWithFlagE9HashCRC32IS7_EEEEEEDaOT_
Line
Count
Source
441
1
            [&](auto&& arg) {
442
1
                using HashTableCtxType = std::decay_t<decltype(arg)>;
443
1
                if constexpr (!std::is_same_v<HashTableCtxType, std::monostate>) {
444
1
                    hash_table_size = arg.hash_table->size();
445
1
                }
446
1
            },
447
13
            hash_table_variants->method_variant);
448
13
    return hash_table_size;
449
13
}
450
451
10
Status SetSharedState::hash_table_init() {
452
10
    std::vector<vectorized::DataTypePtr> data_types;
453
27
    for (size_t i = 0; i != child_exprs_lists[0].size(); ++i) {
454
17
        auto& ctx = child_exprs_lists[0][i];
455
17
        auto data_type = ctx->root()->data_type();
456
17
        if (build_not_ignore_null[i]) {
457
4
            data_type = vectorized::make_nullable(data_type);
458
4
        }
459
17
        data_types.emplace_back(std::move(data_type));
460
17
    }
461
10
    return init_hash_method<SetDataVariants>(hash_table_variants.get(), data_types, true);
462
10
}
463
464
void AggSharedState::refresh_top_limit(size_t row_id,
465
4
                                       const vectorized::ColumnRawPtrs& key_columns) {
466
8
    for (int j = 0; j < key_columns.size(); ++j) {
467
4
        limit_columns[j]->insert_from(*key_columns[j], row_id);
468
4
    }
469
4
    limit_heap.emplace(limit_columns[0]->size() - 1, limit_columns, order_directions,
470
4
                       null_directions);
471
472
4
    limit_heap.pop();
473
4
    limit_columns_min = limit_heap.top()._row_id;
474
4
}
475
476
4
Status MaterializationSharedState::merge_multi_response(vectorized::Block* block) {
477
4
    std::map<int64_t, std::pair<vectorized::Block, int>> _block_maps;
478
9
    for (int i = 0; i < block_order_results.size(); ++i) {
479
8
        for (auto& [backend_id, rpc_struct] : rpc_struct_map) {
480
8
            vectorized::Block partial_block;
481
8
            DCHECK(rpc_struct.callback->response_->blocks_size() > i);
482
8
            RETURN_IF_ERROR(
483
8
                    partial_block.deserialize(rpc_struct.callback->response_->blocks(i).block()));
484
485
8
            if (!partial_block.is_empty_column()) {
486
8
                _block_maps[backend_id] = std::make_pair(std::move(partial_block), 0);
487
8
            }
488
8
        }
489
490
930
        for (int j = 0; j < block_order_results[i].size(); ++j) {
491
925
            auto backend_id = block_order_results[i][j];
492
925
            if (backend_id) {
493
922
                auto& source_block_rows = _block_maps[backend_id];
494
922
                DCHECK(source_block_rows.second < source_block_rows.first.rows());
495
11.9k
                for (int k = 0; k < response_blocks[i].columns(); ++k) {
496
10.9k
                    response_blocks[i].get_column_by_position(k)->insert_from(
497
10.9k
                            *source_block_rows.first.get_by_position(k).column,
498
10.9k
                            source_block_rows.second);
499
10.9k
                }
500
922
                source_block_rows.second++;
501
922
            } else {
502
6
                for (int k = 0; k < response_blocks[i].columns(); ++k) {
503
3
                    response_blocks[i].get_column_by_position(k)->insert_default();
504
3
                }
505
3
            }
506
925
        }
507
5
    }
508
509
    // clear request/response
510
6
    for (auto& [_, rpc_struct] : rpc_struct_map) {
511
12
        for (int i = 0; i < rpc_struct.request.request_block_descs_size(); ++i) {
512
6
            rpc_struct.request.mutable_request_block_descs(i)->clear_row_id();
513
6
            rpc_struct.request.mutable_request_block_descs(i)->clear_file_id();
514
6
        }
515
6
    }
516
517
16
    for (int i = 0, j = 0, rowid_to_block_loc = rowid_locs[j]; i < origin_block.columns(); i++) {
518
12
        if (i != rowid_to_block_loc) {
519
7
            block->insert(origin_block.get_by_position(i));
520
7
        } else {
521
5
            auto response_block = response_blocks[j].to_block();
522
32
            for (int k = 0; k < response_block.columns(); k++) {
523
27
                auto& data = response_block.get_by_position(k);
524
27
                response_blocks[j].mutable_columns()[k] = data.column->clone_empty();
525
27
                block->insert(data);
526
27
            }
527
5
            if (++j < rowid_locs.size()) {
528
1
                rowid_to_block_loc = rowid_locs[j];
529
1
            }
530
5
        }
531
12
    }
532
4
    origin_block.clear();
533
534
4
    return Status::OK();
535
4
}
536
537
void MaterializationSharedState::create_counter_dependency(int operator_id, int node_id,
538
2
                                                           const std::string& name) {
539
2
    auto dep =
540
2
            std::make_shared<CountedFinishDependency>(operator_id, node_id, name + "_DEPENDENCY");
541
2
    dep->set_shared_state(this);
542
    // just block source wait for add the counter in sink
543
2
    dep->add(0);
544
545
2
    source_deps.push_back(dep);
546
2
}
547
548
Status MaterializationSharedState::create_muiltget_result(const vectorized::Columns& columns,
549
5
                                                          bool eos, bool gc_id_map) {
550
5
    const auto rows = columns.empty() ? 0 : columns[0]->size();
551
5
    block_order_results.resize(columns.size());
552
553
8
    for (int i = 0; i < columns.size(); ++i) {
554
3
        const uint8_t* null_map = nullptr;
555
3
        const vectorized::ColumnString* column_rowid = nullptr;
556
3
        auto& column = columns[i];
557
558
3
        if (auto column_ptr = check_and_get_column<vectorized::ColumnNullable>(*column)) {
559
0
            null_map = column_ptr->get_null_map_data().data();
560
0
            column_rowid = assert_cast<const vectorized::ColumnString*>(
561
0
                    column_ptr->get_nested_column_ptr().get());
562
3
        } else {
563
3
            column_rowid = assert_cast<const vectorized::ColumnString*>(column.get());
564
3
        }
565
566
3
        auto& block_order = block_order_results[i];
567
3
        block_order.resize(rows);
568
569
921
        for (int j = 0; j < rows; ++j) {
570
918
            if (!null_map || !null_map[j]) {
571
918
                DCHECK(column_rowid->get_data_at(j).size == sizeof(GlobalRowLoacationV2));
572
918
                GlobalRowLoacationV2 row_location =
573
918
                        *((GlobalRowLoacationV2*)column_rowid->get_data_at(j).data);
574
918
                auto rpc_struct = rpc_struct_map.find(row_location.backend_id);
575
918
                if (UNLIKELY(rpc_struct == rpc_struct_map.end())) {
576
0
                    return Status::InternalError(
577
0
                            "MaterializationSinkOperatorX failed to find rpc_struct, backend_id={}",
578
0
                            row_location.backend_id);
579
0
                }
580
918
                rpc_struct->second.request.mutable_request_block_descs(i)->add_row_id(
581
918
                        row_location.row_id);
582
918
                rpc_struct->second.request.mutable_request_block_descs(i)->add_file_id(
583
918
                        row_location.file_id);
584
918
                block_order[j] = row_location.backend_id;
585
918
            } else {
586
0
                block_order[j] = 0;
587
0
            }
588
918
        }
589
3
    }
590
591
5
    if (eos && gc_id_map) {
592
4
        for (auto& [_, rpc_struct] : rpc_struct_map) {
593
4
            rpc_struct.request.set_gc_id_map(true);
594
4
        }
595
3
    }
596
5
    last_block = eos;
597
5
    need_merge_block = rows > 0;
598
599
5
    return Status::OK();
600
5
}
601
602
Status MaterializationSharedState::init_multi_requests(
603
2
        const TMaterializationNode& materialization_node, RuntimeState* state) {
604
2
    rpc_struct_inited = true;
605
2
    PMultiGetRequestV2 multi_get_request;
606
    // Initialize the base struct of PMultiGetRequestV2
607
2
    multi_get_request.set_be_exec_version(state->be_exec_version());
608
2
    multi_get_request.set_wg_id(state->get_query_ctx()->workload_group()->id());
609
2
    auto query_id = multi_get_request.mutable_query_id();
610
2
    query_id->set_hi(state->query_id().hi);
611
2
    query_id->set_lo(state->query_id().lo);
612
2
    DCHECK_EQ(materialization_node.column_descs_lists.size(),
613
2
              materialization_node.slot_locs_lists.size());
614
615
2
    const auto& tuple_desc =
616
2
            state->desc_tbl().get_tuple_descriptor(materialization_node.intermediate_tuple_id);
617
2
    const auto& slots = tuple_desc->slots();
618
2
    response_blocks =
619
2
            std::vector<vectorized::MutableBlock>(materialization_node.column_descs_lists.size());
620
621
4
    for (int i = 0; i < materialization_node.column_descs_lists.size(); ++i) {
622
2
        auto request_block_desc = multi_get_request.add_request_block_descs();
623
2
        request_block_desc->set_fetch_row_store(materialization_node.fetch_row_stores[i]);
624
        // Initialize the column_descs and slot_locs
625
2
        auto& column_descs = materialization_node.column_descs_lists[i];
626
24
        for (auto& column_desc_item : column_descs) {
627
24
            TabletColumn(column_desc_item).to_schema_pb(request_block_desc->add_column_descs());
628
24
        }
629
630
2
        auto& slot_locs = materialization_node.slot_locs_lists[i];
631
2
        tuple_desc->to_protobuf(request_block_desc->mutable_desc());
632
633
2
        auto& column_idxs = materialization_node.column_idxs_lists[i];
634
24
        for (auto idx : column_idxs) {
635
24
            request_block_desc->add_column_idxs(idx);
636
24
        }
637
638
2
        std::vector<SlotDescriptor*> slots_res;
639
24
        for (auto& slot_loc_item : slot_locs) {
640
24
            slots[slot_loc_item]->to_protobuf(request_block_desc->add_slots());
641
24
            slots_res.emplace_back(slots[slot_loc_item]);
642
24
        }
643
2
        response_blocks[i] = vectorized::MutableBlock(vectorized::Block(slots_res, 10));
644
2
    }
645
646
    // Initialize the stubs and requests for each BE
647
2
    for (const auto& node_info : materialization_node.nodes_info.nodes) {
648
2
        auto client = ExecEnv::GetInstance()->brpc_internal_client_cache()->get_client(
649
2
                node_info.host, node_info.async_internal_port);
650
2
        if (!client) {
651
0
            LOG(WARNING) << "Get rpc stub failed, host=" << node_info.host
652
0
                         << ", port=" << node_info.async_internal_port;
653
0
            return Status::InternalError("RowIDFetcher failed to init rpc client, host={}, port={}",
654
0
                                         node_info.host, node_info.async_internal_port);
655
0
        }
656
2
        rpc_struct_map.emplace(node_info.id, FetchRpcStruct {.stub = std::move(client),
657
2
                                                             .request = multi_get_request,
658
2
                                                             .callback = nullptr,
659
2
                                                             .rpc_timer = MonotonicStopWatch()});
660
2
    }
661
    // add be_num ad count finish counter for source dependency
662
2
    ((CountedFinishDependency*)source_deps.back().get())->add((int)rpc_struct_map.size());
663
664
2
    return Status::OK();
665
2
}
666
667
} // namespace doris::pipeline