be/src/exec/pipeline/dependency.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 | | #ifdef __APPLE__ |
21 | | #include <netinet/in.h> |
22 | | #include <sys/_types/_u_int.h> |
23 | | #endif |
24 | | |
25 | | #include <concurrentqueue.h> |
26 | | #include <gen_cpp/internal_service.pb.h> |
27 | | #include <sqltypes.h> |
28 | | |
29 | | #include <atomic> |
30 | | #include <functional> |
31 | | #include <memory> |
32 | | #include <mutex> |
33 | | #include <thread> |
34 | | #include <utility> |
35 | | |
36 | | #include "common/config.h" |
37 | | #include "common/logging.h" |
38 | | #include "core/block/block.h" |
39 | | #include "core/types.h" |
40 | | #include "exec/common/agg_utils.h" |
41 | | #include "exec/common/join_utils.h" |
42 | | #include "exec/common/set_utils.h" |
43 | | #include "exec/operator/data_queue.h" |
44 | | #include "exec/operator/join/process_hash_table_probe.h" |
45 | | #include "exec/sort/partition_sorter.h" |
46 | | #include "exec/sort/sorter.h" |
47 | | #include "exec/spill/spill_stream.h" |
48 | | #include "util/brpc_closure.h" |
49 | | #include "util/stack_util.h" |
50 | | |
51 | | namespace doris { |
52 | | class AggFnEvaluator; |
53 | | class VSlotRef; |
54 | | } // namespace doris |
55 | | |
56 | | namespace doris { |
57 | | #include "common/compile_check_begin.h" |
58 | | class Dependency; |
59 | | class PipelineTask; |
60 | | struct BasicSharedState; |
61 | | using DependencySPtr = std::shared_ptr<Dependency>; |
62 | | class LocalExchangeSourceLocalState; |
63 | | |
64 | | static constexpr auto SLOW_DEPENDENCY_THRESHOLD = 60 * 1000L * 1000L * 1000L; |
65 | | static constexpr auto TIME_UNIT_DEPENDENCY_LOG = 30 * 1000L * 1000L * 1000L; |
66 | | static_assert(TIME_UNIT_DEPENDENCY_LOG < SLOW_DEPENDENCY_THRESHOLD); |
67 | | |
68 | | struct BasicSharedState { |
69 | | ENABLE_FACTORY_CREATOR(BasicSharedState) |
70 | | |
71 | | template <class TARGET> |
72 | 2.42M | TARGET* cast() { |
73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) |
74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() |
75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); |
76 | 2.42M | return reinterpret_cast<TARGET*>(this); |
77 | 2.42M | } _ZN5doris16BasicSharedState4castINS_19HashJoinSharedStateEEEPT_v Line | Count | Source | 72 | 313k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 313k | return reinterpret_cast<TARGET*>(this); | 77 | 313k | } |
_ZN5doris16BasicSharedState4castINS_30PartitionedHashJoinSharedStateEEEPT_v Line | Count | Source | 72 | 3 | TARGET* cast() { | 73 | 3 | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 0 | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 0 | << " and expect type is" << typeid(TARGET).name(); | 76 | 3 | return reinterpret_cast<TARGET*>(this); | 77 | 3 | } |
_ZN5doris16BasicSharedState4castINS_15SortSharedStateEEEPT_v Line | Count | Source | 72 | 378k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 378k | return reinterpret_cast<TARGET*>(this); | 77 | 378k | } |
_ZN5doris16BasicSharedState4castINS_20SpillSortSharedStateEEEPT_v Line | Count | Source | 72 | 37 | TARGET* cast() { | 73 | 37 | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 0 | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 0 | << " and expect type is" << typeid(TARGET).name(); | 76 | 37 | return reinterpret_cast<TARGET*>(this); | 77 | 37 | } |
_ZN5doris16BasicSharedState4castINS_25NestedLoopJoinSharedStateEEEPT_v Line | Count | Source | 72 | 11.0k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 11.0k | return reinterpret_cast<TARGET*>(this); | 77 | 11.0k | } |
_ZN5doris16BasicSharedState4castINS_19AnalyticSharedStateEEEPT_v Line | Count | Source | 72 | 13.6k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 13.6k | return reinterpret_cast<TARGET*>(this); | 77 | 13.6k | } |
_ZN5doris16BasicSharedState4castINS_14AggSharedStateEEEPT_v Line | Count | Source | 72 | 238k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 238k | return reinterpret_cast<TARGET*>(this); | 77 | 238k | } |
_ZN5doris16BasicSharedState4castINS_25PartitionedAggSharedStateEEEPT_v Line | Count | Source | 72 | 630 | TARGET* cast() { | 73 | 630 | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 0 | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 0 | << " and expect type is" << typeid(TARGET).name(); | 76 | 630 | return reinterpret_cast<TARGET*>(this); | 77 | 630 | } |
_ZN5doris16BasicSharedState4castINS_16UnionSharedStateEEEPT_v Line | Count | Source | 72 | 10.5k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 10.5k | return reinterpret_cast<TARGET*>(this); | 77 | 10.5k | } |
_ZN5doris16BasicSharedState4castINS_28PartitionSortNodeSharedStateEEEPT_v Line | Count | Source | 72 | 866 | TARGET* cast() { | 73 | 866 | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 0 | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 0 | << " and expect type is" << typeid(TARGET).name(); | 76 | 866 | return reinterpret_cast<TARGET*>(this); | 77 | 866 | } |
_ZN5doris16BasicSharedState4castINS_20MultiCastSharedStateEEEPT_v Line | Count | Source | 72 | 13.7k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 13.7k | return reinterpret_cast<TARGET*>(this); | 77 | 13.7k | } |
_ZN5doris16BasicSharedState4castINS_14SetSharedStateEEEPT_v Line | Count | Source | 72 | 16.9k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 16.9k | return reinterpret_cast<TARGET*>(this); | 77 | 16.9k | } |
_ZN5doris16BasicSharedState4castINS_24LocalExchangeSharedStateEEEPT_v Line | Count | Source | 72 | 973k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 973k | return reinterpret_cast<TARGET*>(this); | 77 | 973k | } |
_ZN5doris16BasicSharedState4castIS0_EEPT_v Line | Count | Source | 72 | 447k | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 447k | return reinterpret_cast<TARGET*>(this); | 77 | 447k | } |
_ZN5doris16BasicSharedState4castINS_20DataQueueSharedStateEEEPT_v Line | Count | Source | 72 | 735 | TARGET* cast() { | 73 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 76 | 735 | return reinterpret_cast<TARGET*>(this); | 77 | 735 | } |
_ZN5doris16BasicSharedState4castINS_17RecCTESharedStateEEEPT_v Line | Count | Source | 72 | 450 | TARGET* cast() { | 73 | 450 | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 0 | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 0 | << " and expect type is" << typeid(TARGET).name(); | 76 | 450 | return reinterpret_cast<TARGET*>(this); | 77 | 450 | } |
|
78 | | template <class TARGET> |
79 | | const TARGET* cast() const { |
80 | | DCHECK(dynamic_cast<const TARGET*>(this)) |
81 | | << " Mismatch type! Current type is " << typeid(*this).name() |
82 | | << " and expect type is" << typeid(TARGET).name(); |
83 | | return reinterpret_cast<const TARGET*>(this); |
84 | | } |
85 | | std::vector<DependencySPtr> source_deps; |
86 | | std::vector<DependencySPtr> sink_deps; |
87 | | int id = 0; |
88 | | std::set<int> related_op_ids; |
89 | | |
90 | 1.66M | virtual ~BasicSharedState() = default; |
91 | | |
92 | | void create_source_dependencies(int num_sources, int operator_id, int node_id, |
93 | | const std::string& name); |
94 | | Dependency* create_source_dependency(int operator_id, int node_id, const std::string& name); |
95 | | |
96 | | Dependency* create_sink_dependency(int dest_id, int node_id, const std::string& name); |
97 | 676k | std::vector<DependencySPtr> get_dep_by_channel_id(int channel_id) { |
98 | 676k | DCHECK_LT(channel_id, source_deps.size()); |
99 | 676k | return {source_deps[channel_id]}; |
100 | 676k | } |
101 | | }; |
102 | | |
103 | | class Dependency : public std::enable_shared_from_this<Dependency> { |
104 | | public: |
105 | | ENABLE_FACTORY_CREATOR(Dependency); |
106 | | Dependency(int id, int node_id, std::string name, bool ready = false) |
107 | 6.34M | : _id(id), _node_id(node_id), _name(std::move(name)), _ready(ready) {} |
108 | 6.38M | virtual ~Dependency() = default; |
109 | | |
110 | 0 | [[nodiscard]] int id() const { return _id; } |
111 | 7.33M | [[nodiscard]] virtual std::string name() const { return _name; } |
112 | 329k | BasicSharedState* shared_state() { return _shared_state; } |
113 | 2.26M | void set_shared_state(BasicSharedState* shared_state) { _shared_state = shared_state; } |
114 | | virtual std::string debug_string(int indentation_level = 0); |
115 | 894M | bool ready() const { return _ready; } |
116 | | |
117 | | // Start the watcher. We use it to count how long this dependency block the current pipeline task. |
118 | 4.50M | void start_watcher() { _watcher.start(); } |
119 | 9.26M | [[nodiscard]] int64_t watcher_elapse_time() { return _watcher.elapsed_time(); } |
120 | | |
121 | | // Which dependency current pipeline task is blocked by. `nullptr` if this dependency is ready. |
122 | | [[nodiscard]] Dependency* is_blocked_by(std::shared_ptr<PipelineTask> task = nullptr); |
123 | | // Notify downstream pipeline tasks this dependency is ready. |
124 | | void set_ready(); |
125 | 491k | void set_ready_to_read(int channel_id = 0) { |
126 | 491k | DCHECK_LT(channel_id, _shared_state->source_deps.size()) << debug_string(); |
127 | 491k | _shared_state->source_deps[channel_id]->set_ready(); |
128 | 491k | } |
129 | 999 | void set_ready_to_write() { |
130 | 999 | DCHECK_EQ(_shared_state->sink_deps.size(), 1) << debug_string(); |
131 | 999 | _shared_state->sink_deps.front()->set_ready(); |
132 | 999 | } |
133 | | |
134 | | // Notify downstream pipeline tasks this dependency is blocked. |
135 | 1.18M | void block() { |
136 | 1.18M | if (_always_ready) { |
137 | 234k | return; |
138 | 234k | } |
139 | 948k | std::unique_lock<std::mutex> lc(_always_ready_lock); |
140 | 948k | if (_always_ready) { |
141 | 0 | return; |
142 | 0 | } |
143 | 948k | _ready = false; |
144 | 948k | } |
145 | | |
146 | 4.02M | void set_always_ready() { |
147 | 4.02M | if (_always_ready) { |
148 | 1.92M | return; |
149 | 1.92M | } |
150 | 2.09M | std::unique_lock<std::mutex> lc(_always_ready_lock); |
151 | 2.09M | if (_always_ready) { |
152 | 1 | return; |
153 | 1 | } |
154 | 2.09M | _always_ready = true; |
155 | 2.09M | set_ready(); |
156 | 2.09M | } |
157 | | |
158 | | protected: |
159 | | void _add_block_task(std::shared_ptr<PipelineTask> task); |
160 | | |
161 | | const int _id; |
162 | | const int _node_id; |
163 | | const std::string _name; |
164 | | std::atomic<bool> _ready; |
165 | | |
166 | | BasicSharedState* _shared_state = nullptr; |
167 | | MonotonicStopWatch _watcher; |
168 | | |
169 | | std::mutex _task_lock; |
170 | | std::vector<std::weak_ptr<PipelineTask>> _blocked_task; |
171 | | |
172 | | // If `_always_ready` is true, `block()` will never block tasks. |
173 | | std::atomic<bool> _always_ready = false; |
174 | | std::mutex _always_ready_lock; |
175 | | }; |
176 | | |
177 | | struct FakeSharedState final : public BasicSharedState { |
178 | | ENABLE_FACTORY_CREATOR(FakeSharedState) |
179 | | }; |
180 | | |
181 | | class CountedFinishDependency final : public Dependency { |
182 | | public: |
183 | | using SharedState = FakeSharedState; |
184 | | CountedFinishDependency(int id, int node_id, std::string name) |
185 | 210k | : Dependency(id, node_id, std::move(name), true) {} |
186 | | |
187 | 17.9k | void add(uint32_t count = 1) { |
188 | 17.9k | std::unique_lock<std::mutex> l(_mtx); |
189 | 17.9k | if (!_counter) { |
190 | 17.9k | block(); |
191 | 17.9k | } |
192 | 17.9k | _counter += count; |
193 | 17.9k | } |
194 | | |
195 | 17.9k | void sub() { |
196 | 17.9k | std::unique_lock<std::mutex> l(_mtx); |
197 | 17.9k | _counter--; |
198 | 17.9k | if (!_counter) { |
199 | 17.9k | set_ready(); |
200 | 17.9k | } |
201 | 17.9k | } |
202 | | |
203 | | std::string debug_string(int indentation_level = 0) override; |
204 | | |
205 | | private: |
206 | | std::mutex _mtx; |
207 | | uint32_t _counter = 0; |
208 | | }; |
209 | | |
210 | | struct RuntimeFilterTimerQueue; |
211 | | class RuntimeFilterTimer { |
212 | | public: |
213 | | RuntimeFilterTimer(int64_t registration_time, int32_t wait_time_ms, |
214 | | std::shared_ptr<Dependency> parent, bool force_wait_timeout = false) |
215 | 72.7k | : _parent(std::move(parent)), |
216 | 72.7k | _registration_time(registration_time), |
217 | 72.7k | _wait_time_ms(wait_time_ms), |
218 | 72.7k | _force_wait_timeout(force_wait_timeout) {} |
219 | | |
220 | | // Called by runtime filter producer. |
221 | | void call_ready(); |
222 | | |
223 | | // Called by RuntimeFilterTimerQueue which is responsible for checking if this rf is timeout. |
224 | | void call_timeout(); |
225 | | |
226 | 11.3M | int64_t registration_time() const { return _registration_time; } |
227 | 11.3M | int32_t wait_time_ms() const { return _wait_time_ms; } |
228 | | |
229 | | void set_local_runtime_filter_dependencies( |
230 | 8.35k | const std::vector<std::shared_ptr<Dependency>>& deps) { |
231 | 8.35k | _local_runtime_filter_dependencies = deps; |
232 | 8.35k | } |
233 | | |
234 | | bool should_be_check_timeout(); |
235 | | |
236 | 11.4M | bool force_wait_timeout() { return _force_wait_timeout; } |
237 | | |
238 | | private: |
239 | | friend struct RuntimeFilterTimerQueue; |
240 | | std::shared_ptr<Dependency> _parent = nullptr; |
241 | | std::vector<std::shared_ptr<Dependency>> _local_runtime_filter_dependencies; |
242 | | std::mutex _lock; |
243 | | int64_t _registration_time; |
244 | | const int32_t _wait_time_ms; |
245 | | // true only for group_commit_scan_operator |
246 | | bool _force_wait_timeout; |
247 | | }; |
248 | | |
249 | | struct RuntimeFilterTimerQueue { |
250 | | constexpr static int64_t interval = 10; |
251 | 8 | void run() { _thread.detach(); } |
252 | | void start(); |
253 | | |
254 | 3 | void stop() { |
255 | 3 | _stop = true; |
256 | 3 | cv.notify_all(); |
257 | 3 | wait_for_shutdown(); |
258 | 3 | } |
259 | | |
260 | 3 | void wait_for_shutdown() const { |
261 | 5 | while (!_shutdown) { |
262 | 2 | std::this_thread::sleep_for(std::chrono::milliseconds(interval)); |
263 | 2 | } |
264 | 3 | } |
265 | | |
266 | 3 | ~RuntimeFilterTimerQueue() = default; |
267 | 8 | RuntimeFilterTimerQueue() { _thread = std::thread(&RuntimeFilterTimerQueue::start, this); } |
268 | 46.6k | void push_filter_timer(std::vector<std::shared_ptr<RuntimeFilterTimer>>&& filter) { |
269 | 46.6k | std::unique_lock<std::mutex> lc(_que_lock); |
270 | 46.6k | _que.insert(_que.end(), filter.begin(), filter.end()); |
271 | 46.6k | cv.notify_all(); |
272 | 46.6k | } |
273 | | |
274 | | std::thread _thread; |
275 | | std::condition_variable cv; |
276 | | std::mutex cv_m; |
277 | | std::mutex _que_lock; |
278 | | std::atomic_bool _stop = false; |
279 | | std::atomic_bool _shutdown = false; |
280 | | std::list<std::shared_ptr<RuntimeFilterTimer>> _que; |
281 | | }; |
282 | | |
283 | | struct AggSharedState : public BasicSharedState { |
284 | | ENABLE_FACTORY_CREATOR(AggSharedState) |
285 | | public: |
286 | 120k | AggSharedState() { agg_data = std::make_unique<AggregatedDataVariants>(); } |
287 | 120k | ~AggSharedState() override { |
288 | 120k | if (!probe_expr_ctxs.empty()) { |
289 | 55.8k | _close_with_serialized_key(); |
290 | 64.4k | } else { |
291 | 64.4k | _close_without_key(); |
292 | 64.4k | } |
293 | 120k | } |
294 | | |
295 | | Status reset_hash_table(); |
296 | | |
297 | | bool do_limit_filter(Block* block, size_t num_rows, const std::vector<int>* key_locs = nullptr); |
298 | | void build_limit_heap(size_t hash_table_size); |
299 | | |
300 | | // We should call this function only at 1st phase. |
301 | | // 1st phase: is_merge=true, only have one SlotRef. |
302 | | // 2nd phase: is_merge=false, maybe have multiple exprs. |
303 | | static int get_slot_column_id(const AggFnEvaluator* evaluator); |
304 | | |
305 | | AggregatedDataVariantsUPtr agg_data = nullptr; |
306 | | std::unique_ptr<AggregateDataContainer> aggregate_data_container; |
307 | | std::vector<AggFnEvaluator*> aggregate_evaluators; |
308 | | // group by k1,k2 |
309 | | VExprContextSPtrs probe_expr_ctxs; |
310 | | size_t input_num_rows = 0; |
311 | | std::vector<AggregateDataPtr> values; |
312 | | /// The total size of the row from the aggregate functions. |
313 | | size_t total_size_of_aggregate_states = 0; |
314 | | size_t align_aggregate_states = 1; |
315 | | /// The offset to the n-th aggregate function in a row of aggregate functions. |
316 | | Sizes offsets_of_aggregate_states; |
317 | | std::vector<size_t> make_nullable_keys; |
318 | | |
319 | | bool agg_data_created_without_key = false; |
320 | | bool enable_spill = false; |
321 | | bool reach_limit = false; |
322 | | |
323 | | int64_t limit = -1; |
324 | | bool do_sort_limit = false; |
325 | | MutableColumns limit_columns; |
326 | | int limit_columns_min = -1; |
327 | | PaddedPODArray<uint8_t> need_computes; |
328 | | std::vector<uint8_t> cmp_res; |
329 | | std::vector<int> order_directions; |
330 | | std::vector<int> null_directions; |
331 | | |
332 | | struct HeapLimitCursor { |
333 | | HeapLimitCursor(int row_id, MutableColumns& limit_columns, |
334 | | std::vector<int>& order_directions, std::vector<int>& null_directions) |
335 | 10.2k | : _row_id(row_id), |
336 | 10.2k | _limit_columns(limit_columns), |
337 | 10.2k | _order_directions(order_directions), |
338 | 10.2k | _null_directions(null_directions) {} |
339 | | |
340 | | HeapLimitCursor(const HeapLimitCursor& other) = default; |
341 | | |
342 | | HeapLimitCursor(HeapLimitCursor&& other) noexcept |
343 | 63.9k | : _row_id(other._row_id), |
344 | 63.9k | _limit_columns(other._limit_columns), |
345 | 63.9k | _order_directions(other._order_directions), |
346 | 63.9k | _null_directions(other._null_directions) {} |
347 | | |
348 | 0 | HeapLimitCursor& operator=(const HeapLimitCursor& other) noexcept { |
349 | 0 | _row_id = other._row_id; |
350 | 0 | return *this; |
351 | 0 | } |
352 | | |
353 | 138k | HeapLimitCursor& operator=(HeapLimitCursor&& other) noexcept { |
354 | 138k | _row_id = other._row_id; |
355 | 138k | return *this; |
356 | 138k | } |
357 | | |
358 | 121k | bool operator<(const HeapLimitCursor& rhs) const { |
359 | 143k | for (int i = 0; i < _limit_columns.size(); ++i) { |
360 | 143k | const auto& _limit_column = _limit_columns[i]; |
361 | 143k | auto res = _limit_column->compare_at(_row_id, rhs._row_id, *_limit_column, |
362 | 143k | _null_directions[i]) * |
363 | 143k | _order_directions[i]; |
364 | 143k | if (res < 0) { |
365 | 78.7k | return true; |
366 | 78.7k | } else if (res > 0) { |
367 | 44.0k | return false; |
368 | 44.0k | } |
369 | 143k | } |
370 | 18.4E | return false; |
371 | 121k | } |
372 | | |
373 | | int _row_id; |
374 | | MutableColumns& _limit_columns; |
375 | | std::vector<int>& _order_directions; |
376 | | std::vector<int>& _null_directions; |
377 | | }; |
378 | | |
379 | | std::priority_queue<HeapLimitCursor> limit_heap; |
380 | | |
381 | | // Refresh the top limit heap with a new row |
382 | | void refresh_top_limit(size_t row_id, const ColumnRawPtrs& key_columns); |
383 | | |
384 | | Arena agg_arena_pool; |
385 | | Arena agg_profile_arena; |
386 | | |
387 | | private: |
388 | | MutableColumns _get_keys_hash_table(); |
389 | | |
390 | 55.7k | void _close_with_serialized_key() { |
391 | 55.7k | std::visit(Overload {[&](std::monostate& arg) -> void { |
392 | | // Do nothing |
393 | 0 | }, |
394 | 55.7k | [&](auto& agg_method) -> void { |
395 | 55.7k | auto& data = *agg_method.hash_table; |
396 | 1.01M | data.for_each_mapped([&](auto& mapped) { |
397 | 1.01M | if (mapped) { |
398 | 1.01M | _destroy_agg_status(mapped); |
399 | 1.01M | mapped = nullptr; |
400 | 1.01M | } |
401 | 1.01M | }); _ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_ Line | Count | Source | 396 | 4.23k | data.for_each_mapped([&](auto& mapped) { | 397 | 4.23k | if (mapped) { | 398 | 4.23k | _destroy_agg_status(mapped); | 399 | 4.23k | mapped = nullptr; | 400 | 4.23k | } | 401 | 4.23k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 396 | 1.44k | data.for_each_mapped([&](auto& mapped) { | 397 | 1.44k | if (mapped) { | 398 | 1.44k | _destroy_agg_status(mapped); | 399 | 1.44k | mapped = nullptr; | 400 | 1.44k | } | 401 | 1.44k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_ Line | Count | Source | 396 | 23.6k | data.for_each_mapped([&](auto& mapped) { | 397 | 23.6k | if (mapped) { | 398 | 23.6k | _destroy_agg_status(mapped); | 399 | 23.6k | mapped = nullptr; | 400 | 23.6k | } | 401 | 23.6k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 396 | 532 | data.for_each_mapped([&](auto& mapped) { | 397 | 532 | if (mapped) { | 398 | 532 | _destroy_agg_status(mapped); | 399 | 532 | mapped = nullptr; | 400 | 532 | } | 401 | 532 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 396 | 7.72k | data.for_each_mapped([&](auto& mapped) { | 397 | 7.72k | if (mapped) { | 398 | 7.72k | _destroy_agg_status(mapped); | 399 | 7.72k | mapped = nullptr; | 400 | 7.72k | } | 401 | 7.72k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 396 | 862 | data.for_each_mapped([&](auto& mapped) { | 397 | 862 | if (mapped) { | 398 | 862 | _destroy_agg_status(mapped); | 399 | 862 | mapped = nullptr; | 400 | 862 | } | 401 | 862 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 396 | 83.5k | data.for_each_mapped([&](auto& mapped) { | 397 | 83.7k | if (mapped) { | 398 | 83.7k | _destroy_agg_status(mapped); | 399 | 83.7k | mapped = nullptr; | 400 | 83.7k | } | 401 | 83.5k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 396 | 2.99k | data.for_each_mapped([&](auto& mapped) { | 397 | 2.99k | if (mapped) { | 398 | 2.99k | _destroy_agg_status(mapped); | 399 | 2.99k | mapped = nullptr; | 400 | 2.99k | } | 401 | 2.99k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ENKUlS2_E_clISC_EEDaS2_ Line | Count | Source | 396 | 9 | data.for_each_mapped([&](auto& mapped) { | 397 | 9 | if (mapped) { | 398 | 9 | _destroy_agg_status(mapped); | 399 | 9 | mapped = nullptr; | 400 | 9 | } | 401 | 9 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ENKUlS2_E_clISC_EEDaS2_ Line | Count | Source | 396 | 633 | data.for_each_mapped([&](auto& mapped) { | 397 | 633 | if (mapped) { | 398 | 633 | _destroy_agg_status(mapped); | 399 | 633 | mapped = nullptr; | 400 | 633 | } | 401 | 633 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 396 | 49.5k | data.for_each_mapped([&](auto& mapped) { | 397 | 49.5k | if (mapped) { | 398 | 49.5k | _destroy_agg_status(mapped); | 399 | 49.5k | mapped = nullptr; | 400 | 49.5k | } | 401 | 49.5k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 396 | 68.3k | data.for_each_mapped([&](auto& mapped) { | 397 | 68.3k | if (mapped) { | 398 | 68.3k | _destroy_agg_status(mapped); | 399 | 68.3k | mapped = nullptr; | 400 | 68.3k | } | 401 | 68.3k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 396 | 42.3k | data.for_each_mapped([&](auto& mapped) { | 397 | 42.3k | if (mapped) { | 398 | 42.3k | _destroy_agg_status(mapped); | 399 | 42.3k | mapped = nullptr; | 400 | 42.3k | } | 401 | 42.3k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 396 | 38.4k | data.for_each_mapped([&](auto& mapped) { | 397 | 38.4k | if (mapped) { | 398 | 38.4k | _destroy_agg_status(mapped); | 399 | 38.4k | mapped = nullptr; | 400 | 38.4k | } | 401 | 38.4k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 396 | 804 | data.for_each_mapped([&](auto& mapped) { | 397 | 804 | if (mapped) { | 398 | 804 | _destroy_agg_status(mapped); | 399 | 804 | mapped = nullptr; | 400 | 804 | } | 401 | 804 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 396 | 2.18k | data.for_each_mapped([&](auto& mapped) { | 397 | 2.18k | if (mapped) { | 398 | 2.18k | _destroy_agg_status(mapped); | 399 | 2.18k | mapped = nullptr; | 400 | 2.18k | } | 401 | 2.18k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 396 | 22.0k | data.for_each_mapped([&](auto& mapped) { | 397 | 22.0k | if (mapped) { | 398 | 22.0k | _destroy_agg_status(mapped); | 399 | 22.0k | mapped = nullptr; | 400 | 22.0k | } | 401 | 22.0k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 396 | 587k | data.for_each_mapped([&](auto& mapped) { | 397 | 588k | if (mapped) { | 398 | 588k | _destroy_agg_status(mapped); | 399 | 588k | mapped = nullptr; | 400 | 588k | } | 401 | 587k | }); |
Unexecuted instantiation: _ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_ _ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_ Line | Count | Source | 396 | 399 | data.for_each_mapped([&](auto& mapped) { | 397 | 399 | if (mapped) { | 398 | 399 | _destroy_agg_status(mapped); | 399 | 399 | mapped = nullptr; | 400 | 399 | } | 401 | 399 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 396 | 1.25k | data.for_each_mapped([&](auto& mapped) { | 397 | 1.25k | if (mapped) { | 398 | 1.25k | _destroy_agg_status(mapped); | 399 | 1.25k | mapped = nullptr; | 400 | 1.25k | } | 401 | 1.25k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 396 | 1.34k | data.for_each_mapped([&](auto& mapped) { | 397 | 1.34k | if (mapped) { | 398 | 1.34k | _destroy_agg_status(mapped); | 399 | 1.34k | mapped = nullptr; | 400 | 1.34k | } | 401 | 1.34k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 396 | 6.11k | data.for_each_mapped([&](auto& mapped) { | 397 | 6.11k | if (mapped) { | 398 | 6.11k | _destroy_agg_status(mapped); | 399 | 6.11k | mapped = nullptr; | 400 | 6.11k | } | 401 | 6.11k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 396 | 437 | data.for_each_mapped([&](auto& mapped) { | 397 | 437 | if (mapped) { | 398 | 437 | _destroy_agg_status(mapped); | 399 | 437 | mapped = nullptr; | 400 | 437 | } | 401 | 437 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 396 | 632 | data.for_each_mapped([&](auto& mapped) { | 397 | 632 | if (mapped) { | 398 | 632 | _destroy_agg_status(mapped); | 399 | 632 | mapped = nullptr; | 400 | 632 | } | 401 | 632 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 396 | 69.7k | data.for_each_mapped([&](auto& mapped) { | 397 | 69.7k | if (mapped) { | 398 | 69.7k | _destroy_agg_status(mapped); | 399 | 69.7k | mapped = nullptr; | 400 | 69.7k | } | 401 | 69.7k | }); |
|
402 | 55.7k | if (data.has_null_key_data()) { |
403 | 1.09k | _destroy_agg_status( |
404 | 1.09k | data.template get_null_key_data<AggregateDataPtr>()); |
405 | 1.09k | } |
406 | 55.7k | }}, _ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEvS2_ Line | Count | Source | 394 | 7.47k | [&](auto& agg_method) -> void { | 395 | 7.47k | auto& data = *agg_method.hash_table; | 396 | 7.47k | data.for_each_mapped([&](auto& mapped) { | 397 | 7.47k | if (mapped) { | 398 | 7.47k | _destroy_agg_status(mapped); | 399 | 7.47k | mapped = nullptr; | 400 | 7.47k | } | 401 | 7.47k | }); | 402 | 7.47k | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 7.47k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS7_EEEEEEvS2_ Line | Count | Source | 394 | 1.58k | [&](auto& agg_method) -> void { | 395 | 1.58k | auto& data = *agg_method.hash_table; | 396 | 1.58k | data.for_each_mapped([&](auto& mapped) { | 397 | 1.58k | if (mapped) { | 398 | 1.58k | _destroy_agg_status(mapped); | 399 | 1.58k | mapped = nullptr; | 400 | 1.58k | } | 401 | 1.58k | }); | 402 | 1.58k | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 1.58k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEvS2_ Line | Count | Source | 394 | 126 | [&](auto& agg_method) -> void { | 395 | 126 | auto& data = *agg_method.hash_table; | 396 | 126 | data.for_each_mapped([&](auto& mapped) { | 397 | 126 | if (mapped) { | 398 | 126 | _destroy_agg_status(mapped); | 399 | 126 | mapped = nullptr; | 400 | 126 | } | 401 | 126 | }); | 402 | 126 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 126 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS7_EEEEEEvS2_ Line | Count | Source | 394 | 776 | [&](auto& agg_method) -> void { | 395 | 776 | auto& data = *agg_method.hash_table; | 396 | 776 | data.for_each_mapped([&](auto& mapped) { | 397 | 776 | if (mapped) { | 398 | 776 | _destroy_agg_status(mapped); | 399 | 776 | mapped = nullptr; | 400 | 776 | } | 401 | 776 | }); | 402 | 776 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 776 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS7_EEEEEEvS2_ Line | Count | Source | 394 | 739 | [&](auto& agg_method) -> void { | 395 | 739 | auto& data = *agg_method.hash_table; | 396 | 739 | data.for_each_mapped([&](auto& mapped) { | 397 | 739 | if (mapped) { | 398 | 739 | _destroy_agg_status(mapped); | 399 | 739 | mapped = nullptr; | 400 | 739 | } | 401 | 739 | }); | 402 | 739 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 739 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS7_EEEEEEvS2_ Line | Count | Source | 394 | 1.20k | [&](auto& agg_method) -> void { | 395 | 1.20k | auto& data = *agg_method.hash_table; | 396 | 1.20k | data.for_each_mapped([&](auto& mapped) { | 397 | 1.20k | if (mapped) { | 398 | 1.20k | _destroy_agg_status(mapped); | 399 | 1.20k | mapped = nullptr; | 400 | 1.20k | } | 401 | 1.20k | }); | 402 | 1.20k | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 1.20k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ Line | Count | Source | 394 | 725 | [&](auto& agg_method) -> void { | 395 | 725 | auto& data = *agg_method.hash_table; | 396 | 725 | data.for_each_mapped([&](auto& mapped) { | 397 | 725 | if (mapped) { | 398 | 725 | _destroy_agg_status(mapped); | 399 | 725 | mapped = nullptr; | 400 | 725 | } | 401 | 725 | }); | 402 | 725 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 725 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEvS2_ Line | Count | Source | 394 | 2.42k | [&](auto& agg_method) -> void { | 395 | 2.42k | auto& data = *agg_method.hash_table; | 396 | 2.42k | data.for_each_mapped([&](auto& mapped) { | 397 | 2.42k | if (mapped) { | 398 | 2.42k | _destroy_agg_status(mapped); | 399 | 2.42k | mapped = nullptr; | 400 | 2.42k | } | 401 | 2.42k | }); | 402 | 2.42k | if (data.has_null_key_data()) { | 403 | 39 | _destroy_agg_status( | 404 | 39 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 39 | } | 406 | 2.42k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ Line | Count | Source | 394 | 12 | [&](auto& agg_method) -> void { | 395 | 12 | auto& data = *agg_method.hash_table; | 396 | 12 | data.for_each_mapped([&](auto& mapped) { | 397 | 12 | if (mapped) { | 398 | 12 | _destroy_agg_status(mapped); | 399 | 12 | mapped = nullptr; | 400 | 12 | } | 401 | 12 | }); | 402 | 12 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 12 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ Line | Count | Source | 394 | 350 | [&](auto& agg_method) -> void { | 395 | 350 | auto& data = *agg_method.hash_table; | 396 | 350 | data.for_each_mapped([&](auto& mapped) { | 397 | 350 | if (mapped) { | 398 | 350 | _destroy_agg_status(mapped); | 399 | 350 | mapped = nullptr; | 400 | 350 | } | 401 | 350 | }); | 402 | 350 | if (data.has_null_key_data()) { | 403 | 3 | _destroy_agg_status( | 404 | 3 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 3 | } | 406 | 350 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS2_ Line | Count | Source | 394 | 5.78k | [&](auto& agg_method) -> void { | 395 | 5.78k | auto& data = *agg_method.hash_table; | 396 | 5.78k | data.for_each_mapped([&](auto& mapped) { | 397 | 5.78k | if (mapped) { | 398 | 5.78k | _destroy_agg_status(mapped); | 399 | 5.78k | mapped = nullptr; | 400 | 5.78k | } | 401 | 5.78k | }); | 402 | 5.78k | if (data.has_null_key_data()) { | 403 | 104 | _destroy_agg_status( | 404 | 104 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 104 | } | 406 | 5.78k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS2_ Line | Count | Source | 394 | 8.52k | [&](auto& agg_method) -> void { | 395 | 8.52k | auto& data = *agg_method.hash_table; | 396 | 8.52k | data.for_each_mapped([&](auto& mapped) { | 397 | 8.52k | if (mapped) { | 398 | 8.52k | _destroy_agg_status(mapped); | 399 | 8.52k | mapped = nullptr; | 400 | 8.52k | } | 401 | 8.52k | }); | 402 | 8.52k | if (data.has_null_key_data()) { | 403 | 360 | _destroy_agg_status( | 404 | 360 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 360 | } | 406 | 8.52k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS2_ Line | Count | Source | 394 | 1.10k | [&](auto& agg_method) -> void { | 395 | 1.10k | auto& data = *agg_method.hash_table; | 396 | 1.10k | data.for_each_mapped([&](auto& mapped) { | 397 | 1.10k | if (mapped) { | 398 | 1.10k | _destroy_agg_status(mapped); | 399 | 1.10k | mapped = nullptr; | 400 | 1.10k | } | 401 | 1.10k | }); | 402 | 1.10k | if (data.has_null_key_data()) { | 403 | 50 | _destroy_agg_status( | 404 | 50 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 50 | } | 406 | 1.10k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS2_ Line | Count | Source | 394 | 1.72k | [&](auto& agg_method) -> void { | 395 | 1.72k | auto& data = *agg_method.hash_table; | 396 | 1.72k | data.for_each_mapped([&](auto& mapped) { | 397 | 1.72k | if (mapped) { | 398 | 1.72k | _destroy_agg_status(mapped); | 399 | 1.72k | mapped = nullptr; | 400 | 1.72k | } | 401 | 1.72k | }); | 402 | 1.72k | if (data.has_null_key_data()) { | 403 | 13 | _destroy_agg_status( | 404 | 13 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 13 | } | 406 | 1.72k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS2_ Line | Count | Source | 394 | 552 | [&](auto& agg_method) -> void { | 395 | 552 | auto& data = *agg_method.hash_table; | 396 | 552 | data.for_each_mapped([&](auto& mapped) { | 397 | 552 | if (mapped) { | 398 | 552 | _destroy_agg_status(mapped); | 399 | 552 | mapped = nullptr; | 400 | 552 | } | 401 | 552 | }); | 402 | 552 | if (data.has_null_key_data()) { | 403 | 33 | _destroy_agg_status( | 404 | 33 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 33 | } | 406 | 552 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS2_ Line | Count | Source | 394 | 2.84k | [&](auto& agg_method) -> void { | 395 | 2.84k | auto& data = *agg_method.hash_table; | 396 | 2.84k | data.for_each_mapped([&](auto& mapped) { | 397 | 2.84k | if (mapped) { | 398 | 2.84k | _destroy_agg_status(mapped); | 399 | 2.84k | mapped = nullptr; | 400 | 2.84k | } | 401 | 2.84k | }); | 402 | 2.84k | if (data.has_null_key_data()) { | 403 | 492 | _destroy_agg_status( | 404 | 492 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 492 | } | 406 | 2.84k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS2_ Line | Count | Source | 394 | 1.33k | [&](auto& agg_method) -> void { | 395 | 1.33k | auto& data = *agg_method.hash_table; | 396 | 1.33k | data.for_each_mapped([&](auto& mapped) { | 397 | 1.33k | if (mapped) { | 398 | 1.33k | _destroy_agg_status(mapped); | 399 | 1.33k | mapped = nullptr; | 400 | 1.33k | } | 401 | 1.33k | }); | 402 | 1.33k | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 1.33k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS2_ Line | Count | Source | 394 | 2.44k | [&](auto& agg_method) -> void { | 395 | 2.44k | auto& data = *agg_method.hash_table; | 396 | 2.44k | data.for_each_mapped([&](auto& mapped) { | 397 | 2.44k | if (mapped) { | 398 | 2.44k | _destroy_agg_status(mapped); | 399 | 2.44k | mapped = nullptr; | 400 | 2.44k | } | 401 | 2.44k | }); | 402 | 2.44k | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 2.44k | }}, |
Unexecuted instantiation: _ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEEvS2_ _ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapIS8_Pc9HashCRC32IS8_EEEEEEvS2_ Line | Count | Source | 394 | 129 | [&](auto& agg_method) -> void { | 395 | 129 | auto& data = *agg_method.hash_table; | 396 | 129 | data.for_each_mapped([&](auto& mapped) { | 397 | 129 | if (mapped) { | 398 | 129 | _destroy_agg_status(mapped); | 399 | 129 | mapped = nullptr; | 400 | 129 | } | 401 | 129 | }); | 402 | 129 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 129 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEvS2_ Line | Count | Source | 394 | 769 | [&](auto& agg_method) -> void { | 395 | 769 | auto& data = *agg_method.hash_table; | 396 | 769 | data.for_each_mapped([&](auto& mapped) { | 397 | 769 | if (mapped) { | 398 | 769 | _destroy_agg_status(mapped); | 399 | 769 | mapped = nullptr; | 400 | 769 | } | 401 | 769 | }); | 402 | 769 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 769 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ Line | Count | Source | 394 | 135 | [&](auto& agg_method) -> void { | 395 | 135 | auto& data = *agg_method.hash_table; | 396 | 135 | data.for_each_mapped([&](auto& mapped) { | 397 | 135 | if (mapped) { | 398 | 135 | _destroy_agg_status(mapped); | 399 | 135 | mapped = nullptr; | 400 | 135 | } | 401 | 135 | }); | 402 | 135 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 135 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS2_ Line | Count | Source | 394 | 154 | [&](auto& agg_method) -> void { | 395 | 154 | auto& data = *agg_method.hash_table; | 396 | 154 | data.for_each_mapped([&](auto& mapped) { | 397 | 154 | if (mapped) { | 398 | 154 | _destroy_agg_status(mapped); | 399 | 154 | mapped = nullptr; | 400 | 154 | } | 401 | 154 | }); | 402 | 154 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 154 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS2_ Line | Count | Source | 394 | 57 | [&](auto& agg_method) -> void { | 395 | 57 | auto& data = *agg_method.hash_table; | 396 | 57 | data.for_each_mapped([&](auto& mapped) { | 397 | 57 | if (mapped) { | 398 | 57 | _destroy_agg_status(mapped); | 399 | 57 | mapped = nullptr; | 400 | 57 | } | 401 | 57 | }); | 402 | 57 | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 57 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS2_ Line | Count | Source | 394 | 1.26k | [&](auto& agg_method) -> void { | 395 | 1.26k | auto& data = *agg_method.hash_table; | 396 | 1.26k | data.for_each_mapped([&](auto& mapped) { | 397 | 1.26k | if (mapped) { | 398 | 1.26k | _destroy_agg_status(mapped); | 399 | 1.26k | mapped = nullptr; | 400 | 1.26k | } | 401 | 1.26k | }); | 402 | 1.26k | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 1.26k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEvS2_ Line | Count | Source | 394 | 13.5k | [&](auto& agg_method) -> void { | 395 | 13.5k | auto& data = *agg_method.hash_table; | 396 | 13.5k | data.for_each_mapped([&](auto& mapped) { | 397 | 13.5k | if (mapped) { | 398 | 13.5k | _destroy_agg_status(mapped); | 399 | 13.5k | mapped = nullptr; | 400 | 13.5k | } | 401 | 13.5k | }); | 402 | 13.5k | if (data.has_null_key_data()) { | 403 | 0 | _destroy_agg_status( | 404 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 405 | 0 | } | 406 | 13.5k | }}, |
|
407 | 55.7k | agg_data->method_variant); |
408 | 55.7k | } |
409 | | |
410 | 64.5k | void _close_without_key() { |
411 | | //because prepare maybe failed, and couldn't create agg data. |
412 | | //but finally call close to destory agg data, if agg data has bitmapValue |
413 | | //will be core dump, it's not initialized |
414 | 64.5k | if (agg_data_created_without_key) { |
415 | 64.5k | _destroy_agg_status(agg_data->without_key); |
416 | 64.5k | agg_data_created_without_key = false; |
417 | 64.5k | } |
418 | 64.5k | } |
419 | | void _destroy_agg_status(AggregateDataPtr data); |
420 | | }; |
421 | | |
422 | | struct BasicSpillSharedState { |
423 | 4.36k | virtual ~BasicSpillSharedState() = default; |
424 | | |
425 | | // These two counters are shared to spill source operators as the initial value |
426 | | // of 'SpillWriteFileCurrentBytes' and 'SpillWriteFileCurrentCount'. |
427 | | // Total bytes of spill data written to disk file(after serialized) |
428 | | RuntimeProfile::Counter* _spill_write_file_total_size = nullptr; |
429 | | RuntimeProfile::Counter* _spill_file_total_count = nullptr; |
430 | | |
431 | 4.33k | void setup_shared_profile(RuntimeProfile* sink_profile) { |
432 | 4.33k | _spill_file_total_count = |
433 | 4.33k | ADD_COUNTER_WITH_LEVEL(sink_profile, "SpillWriteFileTotalCount", TUnit::UNIT, 1); |
434 | 4.33k | _spill_write_file_total_size = |
435 | 4.33k | ADD_COUNTER_WITH_LEVEL(sink_profile, "SpillWriteFileBytes", TUnit::BYTES, 1); |
436 | 4.33k | } |
437 | | |
438 | | virtual void update_spill_stream_profiles(RuntimeProfile* source_profile) = 0; |
439 | | }; |
440 | | |
441 | | struct AggSpillPartition; |
442 | | struct PartitionedAggSharedState : public BasicSharedState, |
443 | | public BasicSpillSharedState, |
444 | | public std::enable_shared_from_this<PartitionedAggSharedState> { |
445 | | ENABLE_FACTORY_CREATOR(PartitionedAggSharedState) |
446 | | |
447 | 319 | PartitionedAggSharedState() = default; |
448 | 318 | ~PartitionedAggSharedState() override = default; |
449 | | |
450 | | void update_spill_stream_profiles(RuntimeProfile* source_profile) override; |
451 | | |
452 | | void init_spill_params(size_t spill_partition_count); |
453 | | |
454 | | void close(); |
455 | | |
456 | | AggSharedState* in_mem_shared_state = nullptr; |
457 | | std::shared_ptr<BasicSharedState> in_mem_shared_state_sptr; |
458 | | |
459 | | size_t partition_count; |
460 | | size_t max_partition_index; |
461 | | bool is_spilled = false; |
462 | | std::atomic_bool is_closed = false; |
463 | | std::deque<std::shared_ptr<AggSpillPartition>> spill_partitions; |
464 | | |
465 | 1.05M | size_t get_partition_index(size_t hash_value) const { return hash_value % partition_count; } |
466 | | }; |
467 | | |
468 | | struct AggSpillPartition { |
469 | | static constexpr int64_t AGG_SPILL_FILE_SIZE = 1024 * 1024 * 1024; // 1G |
470 | | |
471 | 10.1k | AggSpillPartition() = default; |
472 | | |
473 | | void close(); |
474 | | |
475 | | Status get_spill_stream(RuntimeState* state, int node_id, RuntimeProfile* profile, |
476 | | SpillStreamSPtr& spilling_stream); |
477 | | |
478 | 3.97k | Status flush_if_full() { |
479 | 3.97k | DCHECK(spilling_stream_); |
480 | 3.97k | Status status; |
481 | | // avoid small spill files |
482 | 3.97k | if (spilling_stream_->get_written_bytes() >= AGG_SPILL_FILE_SIZE) { |
483 | 0 | status = spilling_stream_->spill_eof(); |
484 | 0 | spilling_stream_.reset(); |
485 | 0 | } |
486 | 3.97k | return status; |
487 | 3.97k | } |
488 | | |
489 | 34.4k | Status finish_current_spilling(bool eos = false) { |
490 | 34.4k | if (spilling_stream_) { |
491 | 17.2k | if (eos || spilling_stream_->get_written_bytes() >= AGG_SPILL_FILE_SIZE) { |
492 | 1.96k | auto status = spilling_stream_->spill_eof(); |
493 | 1.96k | spilling_stream_.reset(); |
494 | 1.96k | return status; |
495 | 1.96k | } |
496 | 17.2k | } |
497 | 32.5k | return Status::OK(); |
498 | 34.4k | } |
499 | | |
500 | | std::deque<SpillStreamSPtr> spill_streams_; |
501 | | SpillStreamSPtr spilling_stream_; |
502 | | }; |
503 | | using AggSpillPartitionSPtr = std::shared_ptr<AggSpillPartition>; |
504 | | struct SortSharedState : public BasicSharedState { |
505 | | ENABLE_FACTORY_CREATOR(SortSharedState) |
506 | | public: |
507 | | std::shared_ptr<Sorter> sorter; |
508 | | }; |
509 | | |
510 | | struct SpillSortSharedState : public BasicSharedState, |
511 | | public BasicSpillSharedState, |
512 | | public std::enable_shared_from_this<SpillSortSharedState> { |
513 | | ENABLE_FACTORY_CREATOR(SpillSortSharedState) |
514 | | |
515 | 22 | SpillSortSharedState() = default; |
516 | 22 | ~SpillSortSharedState() override = default; |
517 | | |
518 | 455 | void update_spill_block_batch_row_count(RuntimeState* state, const Block* block) { |
519 | 455 | auto rows = block->rows(); |
520 | 455 | if (rows > 0 && 0 == avg_row_bytes) { |
521 | 16 | avg_row_bytes = std::max((std::size_t)1, block->bytes() / rows); |
522 | 16 | spill_block_batch_row_count = |
523 | 16 | (state->spill_sort_batch_bytes() + avg_row_bytes - 1) / avg_row_bytes; |
524 | 16 | LOG(INFO) << "spill sort block batch row count: " << spill_block_batch_row_count; |
525 | 16 | } |
526 | 455 | } |
527 | | |
528 | | void update_spill_stream_profiles(RuntimeProfile* source_profile) override; |
529 | | |
530 | | void close(); |
531 | | |
532 | | SortSharedState* in_mem_shared_state = nullptr; |
533 | | bool enable_spill = false; |
534 | | bool is_spilled = false; |
535 | | int64_t limit = -1; |
536 | | int64_t offset = 0; |
537 | | std::atomic_bool is_closed = false; |
538 | | std::shared_ptr<BasicSharedState> in_mem_shared_state_sptr; |
539 | | |
540 | | std::deque<SpillStreamSPtr> sorted_streams; |
541 | | size_t avg_row_bytes = 0; |
542 | | size_t spill_block_batch_row_count; |
543 | | }; |
544 | | |
545 | | struct UnionSharedState : public BasicSharedState { |
546 | | ENABLE_FACTORY_CREATOR(UnionSharedState) |
547 | | |
548 | | public: |
549 | 3.39k | UnionSharedState(int child_count = 1) : data_queue(child_count), _child_count(child_count) {}; |
550 | 0 | int child_count() const { return _child_count; } |
551 | | DataQueue data_queue; |
552 | | const int _child_count; |
553 | | }; |
554 | | |
555 | | struct DataQueueSharedState : public BasicSharedState { |
556 | | ENABLE_FACTORY_CREATOR(DataQueueSharedState) |
557 | | public: |
558 | | DataQueue data_queue; |
559 | | }; |
560 | | |
561 | | class MultiCastDataStreamer; |
562 | | |
563 | | struct MultiCastSharedState : public BasicSharedState, |
564 | | public BasicSpillSharedState, |
565 | | public std::enable_shared_from_this<MultiCastSharedState> { |
566 | | MultiCastSharedState(ObjectPool* pool, int cast_sender_count, int node_id); |
567 | | std::unique_ptr<MultiCastDataStreamer> multi_cast_data_streamer; |
568 | | |
569 | | void update_spill_stream_profiles(RuntimeProfile* source_profile) override; |
570 | | }; |
571 | | |
572 | | struct AnalyticSharedState : public BasicSharedState { |
573 | | ENABLE_FACTORY_CREATOR(AnalyticSharedState) |
574 | | |
575 | | public: |
576 | 6.88k | AnalyticSharedState() = default; |
577 | | std::queue<Block> blocks_buffer; |
578 | | std::mutex buffer_mutex; |
579 | | bool sink_eos = false; |
580 | | std::mutex sink_eos_lock; |
581 | | Arena agg_arena_pool; |
582 | | }; |
583 | | |
584 | | struct JoinSharedState : public BasicSharedState { |
585 | | // For some join case, we can apply a short circuit strategy |
586 | | // 1. _has_null_in_build_side = true |
587 | | // 2. build side rows is empty, Join op is: inner join/right outer join/left semi/right semi/right anti |
588 | | bool _has_null_in_build_side = false; |
589 | | bool short_circuit_for_probe = false; |
590 | | // for some join, when build side rows is empty, we could return directly by add some additional null data in probe table. |
591 | | bool empty_right_table_need_probe_dispose = false; |
592 | | JoinOpVariants join_op_variants; |
593 | | }; |
594 | | |
595 | | struct HashJoinSharedState : public JoinSharedState { |
596 | | ENABLE_FACTORY_CREATOR(HashJoinSharedState) |
597 | 168k | HashJoinSharedState() { |
598 | 168k | hash_table_variant_vector.push_back(std::make_shared<JoinDataVariants>()); |
599 | 168k | } |
600 | 2.49k | HashJoinSharedState(int num_instances) { |
601 | 2.49k | source_deps.resize(num_instances, nullptr); |
602 | 2.49k | hash_table_variant_vector.resize(num_instances, nullptr); |
603 | 15.7k | for (int i = 0; i < num_instances; i++) { |
604 | 13.2k | hash_table_variant_vector[i] = std::make_shared<JoinDataVariants>(); |
605 | 13.2k | } |
606 | 2.49k | } |
607 | | std::shared_ptr<Arena> arena = std::make_shared<Arena>(); |
608 | | |
609 | | const std::vector<TupleDescriptor*> build_side_child_desc; |
610 | | size_t build_exprs_size = 0; |
611 | | std::shared_ptr<Block> build_block; |
612 | | std::shared_ptr<std::vector<uint32_t>> build_indexes_null; |
613 | | |
614 | | // Used by shared hash table |
615 | | // For probe operator, hash table in _hash_table_variants is read-only if visited flags is not |
616 | | // used. (visited flags will be used only in right / full outer join). |
617 | | // |
618 | | // For broadcast join, although hash table is read-only, some states in `_hash_table_variants` |
619 | | // are still could be written. For example, serialized keys will be written in a continuous |
620 | | // memory in `_hash_table_variants`. So before execution, we should use a local _hash_table_variants |
621 | | // which has a shared hash table in it. |
622 | | std::vector<std::shared_ptr<JoinDataVariants>> hash_table_variant_vector; |
623 | | |
624 | | // whether left semi join could directly return |
625 | | // if runtime filters contains local in filter, we can make sure all input rows are matched |
626 | | // local filter will always be applied, and in filter could guarantee precise filtering |
627 | | // ATTN: we should disable always_true logic for in filter when we set this flag |
628 | | bool left_semi_direct_return = false; |
629 | | |
630 | | // ASOF JOIN specific fields |
631 | | // Whether the inequality is >= or > (true) vs <= or < (false) |
632 | | bool asof_inequality_is_greater = true; |
633 | | // Whether the inequality is strict (> or <) vs non-strict (>= or <=) |
634 | | bool asof_inequality_is_strict = false; |
635 | | |
636 | | // ASOF JOIN pre-sorted index with inline values for O(log K) branchless lookup |
637 | | // Typed AsofIndexGroups stored in a variant (uint32_t for DateV2, uint64_t for DateTimeV2/TimestampTZ) |
638 | | AsofIndexVariant asof_index_groups; |
639 | | // build_row_index -> bucket_id for O(1) reverse lookup |
640 | | std::vector<uint32_t> asof_build_row_to_bucket; |
641 | | }; |
642 | | |
643 | | struct PartitionedHashJoinSharedState |
644 | | : public HashJoinSharedState, |
645 | | public BasicSpillSharedState, |
646 | | public std::enable_shared_from_this<PartitionedHashJoinSharedState> { |
647 | | ENABLE_FACTORY_CREATOR(PartitionedHashJoinSharedState) |
648 | | |
649 | 0 | void update_spill_stream_profiles(RuntimeProfile* source_profile) override { |
650 | 0 | for (auto& stream : spilled_streams) { |
651 | 0 | if (stream) { |
652 | 0 | stream->update_shared_profiles(source_profile); |
653 | 0 | } |
654 | 0 | } |
655 | 0 | } |
656 | | |
657 | | std::unique_ptr<RuntimeState> inner_runtime_state; |
658 | | std::shared_ptr<HashJoinSharedState> inner_shared_state; |
659 | | std::vector<std::unique_ptr<MutableBlock>> partitioned_build_blocks; |
660 | | std::vector<SpillStreamSPtr> spilled_streams; |
661 | | bool is_spilled = false; |
662 | | }; |
663 | | |
664 | | struct NestedLoopJoinSharedState : public JoinSharedState { |
665 | | ENABLE_FACTORY_CREATOR(NestedLoopJoinSharedState) |
666 | | // if true, probe child has no more rows to process |
667 | | bool probe_side_eos = false; |
668 | | // Visited flags for each row in build side. |
669 | | MutableColumns build_side_visited_flags; |
670 | | // List of build blocks, constructed in prepare() |
671 | | Blocks build_blocks; |
672 | | }; |
673 | | |
674 | | struct PartitionSortNodeSharedState : public BasicSharedState { |
675 | | ENABLE_FACTORY_CREATOR(PartitionSortNodeSharedState) |
676 | | public: |
677 | | std::queue<Block> blocks_buffer; |
678 | | std::mutex buffer_mutex; |
679 | | std::vector<std::unique_ptr<PartitionSorter>> partition_sorts; |
680 | | bool sink_eos = false; |
681 | | std::mutex sink_eos_lock; |
682 | | std::mutex prepared_finish_lock; |
683 | | }; |
684 | | |
685 | | struct SetSharedState : public BasicSharedState { |
686 | | ENABLE_FACTORY_CREATOR(SetSharedState) |
687 | | public: |
688 | | /// default init |
689 | | Block build_block; // build to source |
690 | | //record element size in hashtable |
691 | | int64_t valid_element_in_hash_tbl = 0; |
692 | | //first: idx mapped to column types |
693 | | //second: column_id, could point to origin column or cast column |
694 | | std::unordered_map<int, int> build_col_idx; |
695 | | |
696 | | //// shared static states (shared, decided in prepare/open...) |
697 | | |
698 | | /// init in setup_local_state |
699 | | std::unique_ptr<SetDataVariants> hash_table_variants = |
700 | | std::make_unique<SetDataVariants>(); // the real data HERE. |
701 | | std::vector<bool> build_not_ignore_null; |
702 | | |
703 | | // The SET operator's child might have different nullable attributes. |
704 | | // If a calculation involves both nullable and non-nullable columns, the final output should be a nullable column |
705 | | Status update_build_not_ignore_null(const VExprContextSPtrs& ctxs); |
706 | | |
707 | | size_t get_hash_table_size() const; |
708 | | /// init in both upstream side. |
709 | | //The i-th result expr list refers to the i-th child. |
710 | | std::vector<VExprContextSPtrs> child_exprs_lists; |
711 | | |
712 | | /// init in build side |
713 | | size_t child_quantity; |
714 | | VExprContextSPtrs build_child_exprs; |
715 | | std::vector<Dependency*> probe_finished_children_dependency; |
716 | | |
717 | | /// init in probe side |
718 | | std::vector<VExprContextSPtrs> probe_child_exprs_lists; |
719 | | |
720 | | std::atomic<bool> ready_for_read = false; |
721 | | |
722 | | Arena arena; |
723 | | |
724 | | /// called in setup_local_state |
725 | | Status hash_table_init(); |
726 | | }; |
727 | | |
728 | | enum class ExchangeType : uint8_t { |
729 | | NOOP = 0, |
730 | | // Shuffle data by Crc32CHashPartitioner |
731 | | HASH_SHUFFLE = 1, |
732 | | // Round-robin passthrough data blocks. |
733 | | PASSTHROUGH = 2, |
734 | | // Shuffle data by Crc32HashPartitioner<ShuffleChannelIds> (e.g. same as storage engine). |
735 | | BUCKET_HASH_SHUFFLE = 3, |
736 | | // Passthrough data blocks to all channels. |
737 | | BROADCAST = 4, |
738 | | // Passthrough data to channels evenly in an adaptive way. |
739 | | ADAPTIVE_PASSTHROUGH = 5, |
740 | | // Send all data to the first channel. |
741 | | PASS_TO_ONE = 6, |
742 | | }; |
743 | | |
744 | 187k | inline std::string get_exchange_type_name(ExchangeType idx) { |
745 | 187k | switch (idx) { |
746 | 14 | case ExchangeType::NOOP: |
747 | 14 | return "NOOP"; |
748 | 35.1k | case ExchangeType::HASH_SHUFFLE: |
749 | 35.1k | return "HASH_SHUFFLE"; |
750 | 146k | case ExchangeType::PASSTHROUGH: |
751 | 146k | return "PASSTHROUGH"; |
752 | 706 | case ExchangeType::BUCKET_HASH_SHUFFLE: |
753 | 706 | return "BUCKET_HASH_SHUFFLE"; |
754 | 468 | case ExchangeType::BROADCAST: |
755 | 468 | return "BROADCAST"; |
756 | 1.68k | case ExchangeType::ADAPTIVE_PASSTHROUGH: |
757 | 1.68k | return "ADAPTIVE_PASSTHROUGH"; |
758 | 3.38k | case ExchangeType::PASS_TO_ONE: |
759 | 3.38k | return "PASS_TO_ONE"; |
760 | 187k | } |
761 | 0 | throw Exception(Status::FatalError("__builtin_unreachable")); |
762 | 187k | } |
763 | | |
764 | | struct DataDistribution { |
765 | 2.08M | DataDistribution(ExchangeType type) : distribution_type(type) {} |
766 | | DataDistribution(ExchangeType type, const std::vector<TExpr>& partition_exprs_) |
767 | 257k | : distribution_type(type), partition_exprs(partition_exprs_) {} |
768 | 196k | DataDistribution(const DataDistribution& other) = default; |
769 | 655k | bool need_local_exchange() const { return distribution_type != ExchangeType::NOOP; } |
770 | 602k | DataDistribution& operator=(const DataDistribution& other) = default; |
771 | | ExchangeType distribution_type; |
772 | | std::vector<TExpr> partition_exprs; |
773 | | }; |
774 | | |
775 | | class ExchangerBase; |
776 | | |
777 | | struct LocalExchangeSharedState : public BasicSharedState { |
778 | | public: |
779 | | ENABLE_FACTORY_CREATOR(LocalExchangeSharedState); |
780 | | LocalExchangeSharedState(int num_instances); |
781 | | ~LocalExchangeSharedState() override; |
782 | | std::unique_ptr<ExchangerBase> exchanger {}; |
783 | | std::vector<RuntimeProfile::Counter*> mem_counters; |
784 | | std::atomic<int64_t> mem_usage = 0; |
785 | | std::atomic<size_t> _buffer_mem_limit = config::local_exchange_buffer_mem_limit; |
786 | | // We need to make sure to add mem_usage first and then enqueue, otherwise sub mem_usage may cause negative mem_usage during concurrent dequeue. |
787 | | std::mutex le_lock; |
788 | | void sub_running_sink_operators(); |
789 | | void sub_running_source_operators(); |
790 | 187k | void _set_always_ready() { |
791 | 1.35M | for (auto& dep : source_deps) { |
792 | 1.35M | DCHECK(dep); |
793 | 1.35M | dep->set_always_ready(); |
794 | 1.35M | } |
795 | 187k | for (auto& dep : sink_deps) { |
796 | 187k | DCHECK(dep); |
797 | 187k | dep->set_always_ready(); |
798 | 187k | } |
799 | 187k | } |
800 | | |
801 | 311k | Dependency* get_sink_dep_by_channel_id(int channel_id) { return nullptr; } |
802 | | |
803 | 203k | void set_ready_to_read(int channel_id) { |
804 | 203k | auto& dep = source_deps[channel_id]; |
805 | 18.4E | DCHECK(dep) << channel_id; |
806 | 203k | dep->set_ready(); |
807 | 203k | } |
808 | | |
809 | 203k | void add_mem_usage(int channel_id, size_t delta) { mem_counters[channel_id]->update(delta); } |
810 | | |
811 | 203k | void sub_mem_usage(int channel_id, size_t delta) { |
812 | 203k | mem_counters[channel_id]->update(-(int64_t)delta); |
813 | 203k | } |
814 | | |
815 | 174k | void add_total_mem_usage(size_t delta) { |
816 | 174k | if (cast_set<int64_t>(mem_usage.fetch_add(delta) + delta) > _buffer_mem_limit) { |
817 | 18 | sink_deps.front()->block(); |
818 | 18 | } |
819 | 174k | } |
820 | | |
821 | 174k | void sub_total_mem_usage(size_t delta) { |
822 | 174k | auto prev_usage = mem_usage.fetch_sub(delta); |
823 | 174k | DCHECK_GE(prev_usage - delta, 0) << "prev_usage: " << prev_usage << " delta: " << delta; |
824 | 174k | if (cast_set<int64_t>(prev_usage - delta) <= _buffer_mem_limit) { |
825 | 174k | sink_deps.front()->set_ready(); |
826 | 174k | } |
827 | 174k | } |
828 | | |
829 | 130 | void set_low_memory_mode(RuntimeState* state) { |
830 | 130 | _buffer_mem_limit = std::min<int64_t>(config::local_exchange_buffer_mem_limit, |
831 | 130 | state->low_memory_mode_buffer_limit()); |
832 | 130 | } |
833 | | }; |
834 | | |
835 | | #include "common/compile_check_end.h" |
836 | | } // namespace doris |