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_file.h" |
48 | | #include "runtime/runtime_profile_counter_names.h" |
49 | | #include "util/brpc_closure.h" |
50 | | #include "util/stack_util.h" |
51 | | |
52 | | namespace doris { |
53 | | class AggFnEvaluator; |
54 | | class VSlotRef; |
55 | | } // namespace doris |
56 | | |
57 | | namespace doris { |
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.64M | 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.64M | return reinterpret_cast<TARGET*>(this); |
77 | 2.64M | } _ZN5doris16BasicSharedState4castINS_19HashJoinSharedStateEEEPT_v Line | Count | Source | 72 | 246k | 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 | 246k | return reinterpret_cast<TARGET*>(this); | 77 | 246k | } |
_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 | 501k | 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 | 501k | return reinterpret_cast<TARGET*>(this); | 77 | 501k | } |
_ZN5doris16BasicSharedState4castINS_20SpillSortSharedStateEEEPT_v Line | Count | Source | 72 | 54 | TARGET* cast() { | 73 | 54 | 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 | 54 | return reinterpret_cast<TARGET*>(this); | 77 | 54 | } |
_ZN5doris16BasicSharedState4castINS_25NestedLoopJoinSharedStateEEEPT_v Line | Count | Source | 72 | 17.8k | 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 | 17.8k | return reinterpret_cast<TARGET*>(this); | 77 | 17.8k | } |
_ZN5doris16BasicSharedState4castINS_19AnalyticSharedStateEEEPT_v Line | Count | Source | 72 | 17.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 | 17.7k | return reinterpret_cast<TARGET*>(this); | 77 | 17.7k | } |
_ZN5doris16BasicSharedState4castINS_14AggSharedStateEEEPT_v Line | Count | Source | 72 | 278k | 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 | 278k | return reinterpret_cast<TARGET*>(this); | 77 | 278k | } |
_ZN5doris16BasicSharedState4castINS_25PartitionedAggSharedStateEEEPT_v Line | Count | Source | 72 | 222 | TARGET* cast() { | 73 | 222 | 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 | 222 | return reinterpret_cast<TARGET*>(this); | 77 | 222 | } |
_ZN5doris16BasicSharedState4castINS_16UnionSharedStateEEEPT_v Line | Count | Source | 72 | 13.2k | TARGET* cast() { | 73 | 13.2k | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 5 | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 5 | << " and expect type is" << typeid(TARGET).name(); | 76 | 13.2k | return reinterpret_cast<TARGET*>(this); | 77 | 13.2k | } |
_ZN5doris16BasicSharedState4castINS_28PartitionSortNodeSharedStateEEEPT_v Line | Count | Source | 72 | 1.06k | TARGET* cast() { | 73 | 1.06k | 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 | 1.06k | return reinterpret_cast<TARGET*>(this); | 77 | 1.06k | } |
_ZN5doris16BasicSharedState4castINS_20MultiCastSharedStateEEEPT_v Line | Count | Source | 72 | 12.5k | TARGET* cast() { | 73 | 12.5k | DCHECK(dynamic_cast<TARGET*>(this)) | 74 | 1 | << " Mismatch type! Current type is " << typeid(*this).name() | 75 | 1 | << " and expect type is" << typeid(TARGET).name(); | 76 | 12.5k | return reinterpret_cast<TARGET*>(this); | 77 | 12.5k | } |
_ZN5doris16BasicSharedState4castINS_14SetSharedStateEEEPT_v Line | Count | Source | 72 | 17.1k | 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 | 17.1k | return reinterpret_cast<TARGET*>(this); | 77 | 17.1k | } |
_ZN5doris16BasicSharedState4castINS_24LocalExchangeSharedStateEEEPT_v Line | Count | Source | 72 | 1.02M | 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 | 1.02M | return reinterpret_cast<TARGET*>(this); | 77 | 1.02M | } |
_ZN5doris16BasicSharedState4castIS0_EEPT_v Line | Count | Source | 72 | 510k | 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 | 510k | return reinterpret_cast<TARGET*>(this); | 77 | 510k | } |
_ZN5doris16BasicSharedState4castINS_20DataQueueSharedStateEEEPT_v Line | Count | Source | 72 | 34 | TARGET* cast() { | 73 | 34 | 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 | 34 | return reinterpret_cast<TARGET*>(this); | 77 | 34 | } |
_ZN5doris16BasicSharedState4castINS_17RecCTESharedStateEEEPT_v Line | Count | Source | 72 | 453 | TARGET* cast() { | 73 | 453 | 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 | 453 | return reinterpret_cast<TARGET*>(this); | 77 | 453 | } |
|
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.86M | 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 | 749k | std::vector<DependencySPtr> get_dep_by_channel_id(int channel_id) { |
98 | 749k | DCHECK_LT(channel_id, source_deps.size()); |
99 | 749k | return {source_deps[channel_id]}; |
100 | 749k | } |
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.74M | : _id(id), _node_id(node_id), _name(std::move(name)), _ready(ready) {} |
108 | 6.78M | virtual ~Dependency() = default; |
109 | | |
110 | 0 | [[nodiscard]] int id() const { return _id; } |
111 | 8.27M | [[nodiscard]] virtual std::string name() const { return _name; } |
112 | 318k | BasicSharedState* shared_state() { return _shared_state; } |
113 | 2.53M | void set_shared_state(BasicSharedState* shared_state) { _shared_state = shared_state; } |
114 | | virtual std::string debug_string(int indentation_level = 0); |
115 | 873M | 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 | 5.16M | void start_watcher() { _watcher.start(); } |
119 | 9.24M | [[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 | 548k | void set_ready_to_read(int channel_id = 0) { |
126 | 548k | DCHECK_LT(channel_id, _shared_state->source_deps.size()) << debug_string(); |
127 | 548k | _shared_state->source_deps[channel_id]->set_ready(); |
128 | 548k | } |
129 | 1.11k | void set_ready_to_write() { |
130 | 1.11k | DCHECK_EQ(_shared_state->sink_deps.size(), 1) << debug_string(); |
131 | 1.11k | _shared_state->sink_deps.front()->set_ready(); |
132 | 1.11k | } |
133 | | |
134 | | // Notify downstream pipeline tasks this dependency is blocked. |
135 | 1.70M | void block() { |
136 | 1.70M | if (_always_ready) { |
137 | 298k | return; |
138 | 298k | } |
139 | 1.40M | std::unique_lock<std::mutex> lc(_always_ready_lock); |
140 | 1.40M | if (_always_ready) { |
141 | 1 | return; |
142 | 1 | } |
143 | 1.40M | _ready = false; |
144 | 1.40M | } |
145 | | |
146 | 4.21M | void set_always_ready() { |
147 | 4.21M | if (_always_ready) { |
148 | 1.89M | return; |
149 | 1.89M | } |
150 | 2.31M | std::unique_lock<std::mutex> lc(_always_ready_lock); |
151 | 2.31M | if (_always_ready) { |
152 | 0 | return; |
153 | 0 | } |
154 | 2.31M | _always_ready = true; |
155 | 2.31M | set_ready(); |
156 | 2.31M | } |
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 | 177k | : Dependency(id, node_id, std::move(name), true) {} |
186 | | |
187 | 8.73k | void add(uint32_t count = 1) { |
188 | 8.73k | std::unique_lock<std::mutex> l(_mtx); |
189 | 8.73k | if (!_counter) { |
190 | 8.73k | block(); |
191 | 8.73k | } |
192 | 8.73k | _counter += count; |
193 | 8.73k | } |
194 | | |
195 | 8.73k | void sub() { |
196 | 8.73k | std::unique_lock<std::mutex> l(_mtx); |
197 | 8.73k | _counter--; |
198 | 8.73k | if (!_counter) { |
199 | 8.73k | set_ready(); |
200 | 8.73k | } |
201 | 8.73k | } |
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 | 44.2k | : _parent(std::move(parent)), |
216 | 44.2k | _registration_time(registration_time), |
217 | 44.2k | _wait_time_ms(wait_time_ms), |
218 | 44.2k | _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 | 3.34M | int64_t registration_time() const { return _registration_time; } |
227 | 3.34M | int32_t wait_time_ms() const { return _wait_time_ms; } |
228 | | |
229 | | void set_local_runtime_filter_dependencies( |
230 | 5.99k | const std::vector<std::shared_ptr<Dependency>>& deps) { |
231 | 5.99k | _local_runtime_filter_dependencies = deps; |
232 | 5.99k | } |
233 | | |
234 | | bool should_be_check_timeout(); |
235 | | |
236 | 3.39M | 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 | 6 | while (!_shutdown) { |
262 | 3 | std::this_thread::sleep_for(std::chrono::milliseconds(interval)); |
263 | 3 | } |
264 | 3 | } |
265 | | |
266 | 3 | ~RuntimeFilterTimerQueue() = default; |
267 | 8 | RuntimeFilterTimerQueue() { _thread = std::thread(&RuntimeFilterTimerQueue::start, this); } |
268 | 26.4k | void push_filter_timer(std::vector<std::shared_ptr<RuntimeFilterTimer>>&& filter) { |
269 | 26.4k | std::unique_lock<std::mutex> lc(_que_lock); |
270 | 26.4k | _que.insert(_que.end(), filter.begin(), filter.end()); |
271 | 26.4k | cv.notify_all(); |
272 | 26.4k | } |
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 | 140k | AggSharedState() { agg_data = std::make_unique<AggregatedDataVariants>(); } |
287 | 140k | ~AggSharedState() override { |
288 | 140k | if (!probe_expr_ctxs.empty()) { |
289 | 45.8k | _close_with_serialized_key(); |
290 | 94.4k | } else { |
291 | 94.4k | _close_without_key(); |
292 | 94.4k | } |
293 | 140k | } |
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 | | bool use_simple_count = false; |
324 | | int64_t limit = -1; |
325 | | bool do_sort_limit = false; |
326 | | MutableColumns limit_columns; |
327 | | int limit_columns_min = -1; |
328 | | PaddedPODArray<uint8_t> need_computes; |
329 | | std::vector<uint8_t> cmp_res; |
330 | | std::vector<int> order_directions; |
331 | | std::vector<int> null_directions; |
332 | | |
333 | | struct HeapLimitCursor { |
334 | | HeapLimitCursor(int row_id, MutableColumns& limit_columns, |
335 | | std::vector<int>& order_directions, std::vector<int>& null_directions) |
336 | 52.5k | : _row_id(row_id), |
337 | 52.5k | _limit_columns(limit_columns), |
338 | 52.5k | _order_directions(order_directions), |
339 | 52.5k | _null_directions(null_directions) {} |
340 | | |
341 | | HeapLimitCursor(const HeapLimitCursor& other) = default; |
342 | | |
343 | | HeapLimitCursor(HeapLimitCursor&& other) noexcept |
344 | 331k | : _row_id(other._row_id), |
345 | 331k | _limit_columns(other._limit_columns), |
346 | 331k | _order_directions(other._order_directions), |
347 | 331k | _null_directions(other._null_directions) {} |
348 | | |
349 | 0 | HeapLimitCursor& operator=(const HeapLimitCursor& other) noexcept { |
350 | 0 | _row_id = other._row_id; |
351 | 0 | return *this; |
352 | 0 | } |
353 | | |
354 | 680k | HeapLimitCursor& operator=(HeapLimitCursor&& other) noexcept { |
355 | 680k | _row_id = other._row_id; |
356 | 680k | return *this; |
357 | 680k | } |
358 | | |
359 | 626k | bool operator<(const HeapLimitCursor& rhs) const { |
360 | 971k | for (int i = 0; i < _limit_columns.size(); ++i) { |
361 | 971k | const auto& _limit_column = _limit_columns[i]; |
362 | 971k | auto res = _limit_column->compare_at(_row_id, rhs._row_id, *_limit_column, |
363 | 971k | _null_directions[i]) * |
364 | 971k | _order_directions[i]; |
365 | 971k | if (res < 0) { |
366 | 327k | return true; |
367 | 643k | } else if (res > 0) { |
368 | 311k | return false; |
369 | 311k | } |
370 | 971k | } |
371 | 18.4E | return false; |
372 | 626k | } |
373 | | |
374 | | int _row_id; |
375 | | MutableColumns& _limit_columns; |
376 | | std::vector<int>& _order_directions; |
377 | | std::vector<int>& _null_directions; |
378 | | }; |
379 | | |
380 | | std::priority_queue<HeapLimitCursor> limit_heap; |
381 | | |
382 | | // Refresh the top limit heap with a new row |
383 | | void refresh_top_limit(size_t row_id, const ColumnRawPtrs& key_columns); |
384 | | |
385 | | Arena agg_arena_pool; |
386 | | Arena agg_profile_arena; |
387 | | |
388 | | private: |
389 | | MutableColumns _get_keys_hash_table(); |
390 | | |
391 | 45.7k | void _close_with_serialized_key() { |
392 | 45.7k | std::visit(Overload {[&](std::monostate& arg) -> void { |
393 | | // Do nothing |
394 | 0 | }, |
395 | 45.8k | [&](auto& agg_method) -> void { |
396 | 45.8k | if (use_simple_count) { |
397 | | // Inline count: mapped slots hold UInt64, |
398 | | // not real agg state pointers. Skip destroy. |
399 | 4.17k | return; |
400 | 4.17k | } |
401 | 41.6k | auto& data = *agg_method.hash_table; |
402 | 1.55M | data.for_each_mapped([&](auto& mapped) { |
403 | 1.55M | if (mapped) { |
404 | 1.55M | _destroy_agg_status(mapped); |
405 | 1.55M | mapped = nullptr; |
406 | 1.55M | } |
407 | 1.55M | }); _ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_ Line | Count | Source | 402 | 6.84k | data.for_each_mapped([&](auto& mapped) { | 403 | 6.84k | if (mapped) { | 404 | 6.84k | _destroy_agg_status(mapped); | 405 | 6.84k | mapped = nullptr; | 406 | 6.84k | } | 407 | 6.84k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 402 | 1.50k | data.for_each_mapped([&](auto& mapped) { | 403 | 1.50k | if (mapped) { | 404 | 1.50k | _destroy_agg_status(mapped); | 405 | 1.50k | mapped = nullptr; | 406 | 1.50k | } | 407 | 1.50k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_ Line | Count | Source | 402 | 12.9k | data.for_each_mapped([&](auto& mapped) { | 403 | 12.9k | if (mapped) { | 404 | 12.9k | _destroy_agg_status(mapped); | 405 | 12.9k | mapped = nullptr; | 406 | 12.9k | } | 407 | 12.9k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 402 | 591 | data.for_each_mapped([&](auto& mapped) { | 403 | 591 | if (mapped) { | 404 | 591 | _destroy_agg_status(mapped); | 405 | 591 | mapped = nullptr; | 406 | 591 | } | 407 | 591 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 402 | 7.68k | data.for_each_mapped([&](auto& mapped) { | 403 | 7.68k | if (mapped) { | 404 | 7.68k | _destroy_agg_status(mapped); | 405 | 7.68k | mapped = nullptr; | 406 | 7.68k | } | 407 | 7.68k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 402 | 767 | data.for_each_mapped([&](auto& mapped) { | 403 | 767 | if (mapped) { | 404 | 767 | _destroy_agg_status(mapped); | 405 | 767 | mapped = nullptr; | 406 | 767 | } | 407 | 767 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 402 | 268k | data.for_each_mapped([&](auto& mapped) { | 403 | 268k | if (mapped) { | 404 | 268k | _destroy_agg_status(mapped); | 405 | 268k | mapped = nullptr; | 406 | 268k | } | 407 | 268k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 402 | 4.42k | data.for_each_mapped([&](auto& mapped) { | 403 | 4.42k | if (mapped) { | 404 | 4.42k | _destroy_agg_status(mapped); | 405 | 4.42k | mapped = nullptr; | 406 | 4.42k | } | 407 | 4.42k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ENKUlS2_E_clISC_EEDaS2_ Line | Count | Source | 402 | 9 | data.for_each_mapped([&](auto& mapped) { | 403 | 9 | if (mapped) { | 404 | 9 | _destroy_agg_status(mapped); | 405 | 9 | mapped = nullptr; | 406 | 9 | } | 407 | 9 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ENKUlS2_E_clISC_EEDaS2_ Line | Count | Source | 402 | 370 | data.for_each_mapped([&](auto& mapped) { | 403 | 370 | if (mapped) { | 404 | 370 | _destroy_agg_status(mapped); | 405 | 370 | mapped = nullptr; | 406 | 370 | } | 407 | 370 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 402 | 114k | data.for_each_mapped([&](auto& mapped) { | 403 | 114k | if (mapped) { | 404 | 114k | _destroy_agg_status(mapped); | 405 | 114k | mapped = nullptr; | 406 | 114k | } | 407 | 114k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 402 | 107k | data.for_each_mapped([&](auto& mapped) { | 403 | 107k | if (mapped) { | 404 | 107k | _destroy_agg_status(mapped); | 405 | 107k | mapped = nullptr; | 406 | 107k | } | 407 | 107k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 402 | 4.22k | data.for_each_mapped([&](auto& mapped) { | 403 | 4.22k | if (mapped) { | 404 | 4.22k | _destroy_agg_status(mapped); | 405 | 4.22k | mapped = nullptr; | 406 | 4.22k | } | 407 | 4.22k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 402 | 16.4k | data.for_each_mapped([&](auto& mapped) { | 403 | 16.4k | if (mapped) { | 404 | 16.4k | _destroy_agg_status(mapped); | 405 | 16.4k | mapped = nullptr; | 406 | 16.4k | } | 407 | 16.4k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 402 | 1.05k | data.for_each_mapped([&](auto& mapped) { | 403 | 1.05k | if (mapped) { | 404 | 1.05k | _destroy_agg_status(mapped); | 405 | 1.05k | mapped = nullptr; | 406 | 1.05k | } | 407 | 1.05k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_ Line | Count | Source | 402 | 1.75k | data.for_each_mapped([&](auto& mapped) { | 403 | 1.75k | if (mapped) { | 404 | 1.75k | _destroy_agg_status(mapped); | 405 | 1.75k | mapped = nullptr; | 406 | 1.75k | } | 407 | 1.75k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 402 | 20.4k | data.for_each_mapped([&](auto& mapped) { | 403 | 20.4k | if (mapped) { | 404 | 20.4k | _destroy_agg_status(mapped); | 405 | 20.4k | mapped = nullptr; | 406 | 20.4k | } | 407 | 20.4k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 402 | 879k | data.for_each_mapped([&](auto& mapped) { | 403 | 880k | if (mapped) { | 404 | 880k | _destroy_agg_status(mapped); | 405 | 880k | mapped = nullptr; | 406 | 880k | } | 407 | 879k | }); |
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 | 402 | 101 | data.for_each_mapped([&](auto& mapped) { | 403 | 101 | if (mapped) { | 404 | 101 | _destroy_agg_status(mapped); | 405 | 101 | mapped = nullptr; | 406 | 101 | } | 407 | 101 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 402 | 1.39k | data.for_each_mapped([&](auto& mapped) { | 403 | 1.39k | if (mapped) { | 404 | 1.39k | _destroy_agg_status(mapped); | 405 | 1.39k | mapped = nullptr; | 406 | 1.39k | } | 407 | 1.39k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 402 | 16.3k | data.for_each_mapped([&](auto& mapped) { | 403 | 16.3k | if (mapped) { | 404 | 16.3k | _destroy_agg_status(mapped); | 405 | 16.3k | mapped = nullptr; | 406 | 16.3k | } | 407 | 16.3k | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 402 | 273 | data.for_each_mapped([&](auto& mapped) { | 403 | 273 | if (mapped) { | 404 | 273 | _destroy_agg_status(mapped); | 405 | 273 | mapped = nullptr; | 406 | 273 | } | 407 | 273 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 402 | 34 | data.for_each_mapped([&](auto& mapped) { | 403 | 34 | if (mapped) { | 404 | 34 | _destroy_agg_status(mapped); | 405 | 34 | mapped = nullptr; | 406 | 34 | } | 407 | 34 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_ Line | Count | Source | 402 | 250 | data.for_each_mapped([&](auto& mapped) { | 403 | 250 | if (mapped) { | 404 | 250 | _destroy_agg_status(mapped); | 405 | 250 | mapped = nullptr; | 406 | 250 | } | 407 | 250 | }); |
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_ Line | Count | Source | 402 | 90.3k | data.for_each_mapped([&](auto& mapped) { | 403 | 90.3k | if (mapped) { | 404 | 90.3k | _destroy_agg_status(mapped); | 405 | 90.3k | mapped = nullptr; | 406 | 90.3k | } | 407 | 90.3k | }); |
|
408 | 41.6k | if (data.has_null_key_data()) { |
409 | 1.08k | _destroy_agg_status( |
410 | 1.08k | data.template get_null_key_data<AggregateDataPtr>()); |
411 | 1.08k | } |
412 | 41.6k | }}, _ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEvS2_ Line | Count | Source | 395 | 2.87k | [&](auto& agg_method) -> void { | 396 | 2.87k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 62 | return; | 400 | 62 | } | 401 | 2.80k | auto& data = *agg_method.hash_table; | 402 | 2.80k | data.for_each_mapped([&](auto& mapped) { | 403 | 2.80k | if (mapped) { | 404 | 2.80k | _destroy_agg_status(mapped); | 405 | 2.80k | mapped = nullptr; | 406 | 2.80k | } | 407 | 2.80k | }); | 408 | 2.80k | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 2.80k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS7_EEEEEEvS2_ Line | Count | Source | 395 | 1.85k | [&](auto& agg_method) -> void { | 396 | 1.85k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 147 | return; | 400 | 147 | } | 401 | 1.70k | auto& data = *agg_method.hash_table; | 402 | 1.70k | data.for_each_mapped([&](auto& mapped) { | 403 | 1.70k | if (mapped) { | 404 | 1.70k | _destroy_agg_status(mapped); | 405 | 1.70k | mapped = nullptr; | 406 | 1.70k | } | 407 | 1.70k | }); | 408 | 1.70k | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 1.70k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEvS2_ Line | Count | Source | 395 | 173 | [&](auto& agg_method) -> void { | 396 | 173 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 65 | return; | 400 | 65 | } | 401 | 108 | auto& data = *agg_method.hash_table; | 402 | 108 | data.for_each_mapped([&](auto& mapped) { | 403 | 108 | if (mapped) { | 404 | 108 | _destroy_agg_status(mapped); | 405 | 108 | mapped = nullptr; | 406 | 108 | } | 407 | 108 | }); | 408 | 108 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 108 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS7_EEEEEEvS2_ Line | Count | Source | 395 | 837 | [&](auto& agg_method) -> void { | 396 | 837 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 67 | return; | 400 | 67 | } | 401 | 770 | auto& data = *agg_method.hash_table; | 402 | 770 | data.for_each_mapped([&](auto& mapped) { | 403 | 770 | if (mapped) { | 404 | 770 | _destroy_agg_status(mapped); | 405 | 770 | mapped = nullptr; | 406 | 770 | } | 407 | 770 | }); | 408 | 770 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 770 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS7_EEEEEEvS2_ Line | Count | Source | 395 | 591 | [&](auto& agg_method) -> void { | 396 | 591 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 2 | return; | 400 | 2 | } | 401 | 589 | auto& data = *agg_method.hash_table; | 402 | 589 | data.for_each_mapped([&](auto& mapped) { | 403 | 589 | if (mapped) { | 404 | 589 | _destroy_agg_status(mapped); | 405 | 589 | mapped = nullptr; | 406 | 589 | } | 407 | 589 | }); | 408 | 589 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 589 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS7_EEEEEEvS2_ Line | Count | Source | 395 | 1.16k | [&](auto& agg_method) -> void { | 396 | 1.16k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 65 | return; | 400 | 65 | } | 401 | 1.09k | auto& data = *agg_method.hash_table; | 402 | 1.09k | data.for_each_mapped([&](auto& mapped) { | 403 | 1.09k | if (mapped) { | 404 | 1.09k | _destroy_agg_status(mapped); | 405 | 1.09k | mapped = nullptr; | 406 | 1.09k | } | 407 | 1.09k | }); | 408 | 1.09k | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 1.09k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ Line | Count | Source | 395 | 982 | [&](auto& agg_method) -> void { | 396 | 982 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 88 | return; | 400 | 88 | } | 401 | 894 | auto& data = *agg_method.hash_table; | 402 | 894 | data.for_each_mapped([&](auto& mapped) { | 403 | 894 | if (mapped) { | 404 | 894 | _destroy_agg_status(mapped); | 405 | 894 | mapped = nullptr; | 406 | 894 | } | 407 | 894 | }); | 408 | 894 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 894 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEvS2_ Line | Count | Source | 395 | 3.32k | [&](auto& agg_method) -> void { | 396 | 3.32k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 620 | return; | 400 | 620 | } | 401 | 2.70k | auto& data = *agg_method.hash_table; | 402 | 2.70k | data.for_each_mapped([&](auto& mapped) { | 403 | 2.70k | if (mapped) { | 404 | 2.70k | _destroy_agg_status(mapped); | 405 | 2.70k | mapped = nullptr; | 406 | 2.70k | } | 407 | 2.70k | }); | 408 | 2.70k | if (data.has_null_key_data()) { | 409 | 60 | _destroy_agg_status( | 410 | 60 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 60 | } | 412 | 2.70k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ Line | Count | Source | 395 | 14 | [&](auto& agg_method) -> void { | 396 | 14 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 0 | return; | 400 | 0 | } | 401 | 14 | auto& data = *agg_method.hash_table; | 402 | 14 | data.for_each_mapped([&](auto& mapped) { | 403 | 14 | if (mapped) { | 404 | 14 | _destroy_agg_status(mapped); | 405 | 14 | mapped = nullptr; | 406 | 14 | } | 407 | 14 | }); | 408 | 14 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 14 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ Line | Count | Source | 395 | 422 | [&](auto& agg_method) -> void { | 396 | 422 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 2 | return; | 400 | 2 | } | 401 | 420 | auto& data = *agg_method.hash_table; | 402 | 420 | data.for_each_mapped([&](auto& mapped) { | 403 | 420 | if (mapped) { | 404 | 420 | _destroy_agg_status(mapped); | 405 | 420 | mapped = nullptr; | 406 | 420 | } | 407 | 420 | }); | 408 | 420 | if (data.has_null_key_data()) { | 409 | 4 | _destroy_agg_status( | 410 | 4 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 4 | } | 412 | 420 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS2_ Line | Count | Source | 395 | 4.76k | [&](auto& agg_method) -> void { | 396 | 4.76k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 647 | return; | 400 | 647 | } | 401 | 4.11k | auto& data = *agg_method.hash_table; | 402 | 4.11k | data.for_each_mapped([&](auto& mapped) { | 403 | 4.11k | if (mapped) { | 404 | 4.11k | _destroy_agg_status(mapped); | 405 | 4.11k | mapped = nullptr; | 406 | 4.11k | } | 407 | 4.11k | }); | 408 | 4.11k | if (data.has_null_key_data()) { | 409 | 148 | _destroy_agg_status( | 410 | 148 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 148 | } | 412 | 4.11k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS2_ Line | Count | Source | 395 | 9.97k | [&](auto& agg_method) -> void { | 396 | 9.97k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 830 | return; | 400 | 830 | } | 401 | 9.14k | auto& data = *agg_method.hash_table; | 402 | 9.14k | data.for_each_mapped([&](auto& mapped) { | 403 | 9.14k | if (mapped) { | 404 | 9.14k | _destroy_agg_status(mapped); | 405 | 9.14k | mapped = nullptr; | 406 | 9.14k | } | 407 | 9.14k | }); | 408 | 9.14k | if (data.has_null_key_data()) { | 409 | 408 | _destroy_agg_status( | 410 | 408 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 408 | } | 412 | 9.14k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS2_ Line | Count | Source | 395 | 585 | [&](auto& agg_method) -> void { | 396 | 585 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 27 | return; | 400 | 27 | } | 401 | 558 | auto& data = *agg_method.hash_table; | 402 | 558 | data.for_each_mapped([&](auto& mapped) { | 403 | 558 | if (mapped) { | 404 | 558 | _destroy_agg_status(mapped); | 405 | 558 | mapped = nullptr; | 406 | 558 | } | 407 | 558 | }); | 408 | 558 | if (data.has_null_key_data()) { | 409 | 55 | _destroy_agg_status( | 410 | 55 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 55 | } | 412 | 558 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS2_ Line | Count | Source | 395 | 1.13k | [&](auto& agg_method) -> void { | 396 | 1.13k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 47 | return; | 400 | 47 | } | 401 | 1.08k | auto& data = *agg_method.hash_table; | 402 | 1.08k | data.for_each_mapped([&](auto& mapped) { | 403 | 1.08k | if (mapped) { | 404 | 1.08k | _destroy_agg_status(mapped); | 405 | 1.08k | mapped = nullptr; | 406 | 1.08k | } | 407 | 1.08k | }); | 408 | 1.08k | if (data.has_null_key_data()) { | 409 | 24 | _destroy_agg_status( | 410 | 24 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 24 | } | 412 | 1.08k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS2_ Line | Count | Source | 395 | 611 | [&](auto& agg_method) -> void { | 396 | 611 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 18 | return; | 400 | 18 | } | 401 | 593 | auto& data = *agg_method.hash_table; | 402 | 593 | data.for_each_mapped([&](auto& mapped) { | 403 | 593 | if (mapped) { | 404 | 593 | _destroy_agg_status(mapped); | 405 | 593 | mapped = nullptr; | 406 | 593 | } | 407 | 593 | }); | 408 | 593 | if (data.has_null_key_data()) { | 409 | 20 | _destroy_agg_status( | 410 | 20 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 20 | } | 412 | 593 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS2_ Line | Count | Source | 395 | 2.09k | [&](auto& agg_method) -> void { | 396 | 2.09k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 285 | return; | 400 | 285 | } | 401 | 1.80k | auto& data = *agg_method.hash_table; | 402 | 1.80k | data.for_each_mapped([&](auto& mapped) { | 403 | 1.80k | if (mapped) { | 404 | 1.80k | _destroy_agg_status(mapped); | 405 | 1.80k | mapped = nullptr; | 406 | 1.80k | } | 407 | 1.80k | }); | 408 | 1.80k | if (data.has_null_key_data()) { | 409 | 363 | _destroy_agg_status( | 410 | 363 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 363 | } | 412 | 1.80k | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS2_ Line | Count | Source | 395 | 1.50k | [&](auto& agg_method) -> void { | 396 | 1.50k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 535 | return; | 400 | 535 | } | 401 | 967 | auto& data = *agg_method.hash_table; | 402 | 967 | data.for_each_mapped([&](auto& mapped) { | 403 | 967 | if (mapped) { | 404 | 967 | _destroy_agg_status(mapped); | 405 | 967 | mapped = nullptr; | 406 | 967 | } | 407 | 967 | }); | 408 | 967 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 967 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS2_ Line | Count | Source | 395 | 2.44k | [&](auto& agg_method) -> void { | 396 | 2.44k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 52 | return; | 400 | 52 | } | 401 | 2.39k | auto& data = *agg_method.hash_table; | 402 | 2.39k | data.for_each_mapped([&](auto& mapped) { | 403 | 2.39k | if (mapped) { | 404 | 2.39k | _destroy_agg_status(mapped); | 405 | 2.39k | mapped = nullptr; | 406 | 2.39k | } | 407 | 2.39k | }); | 408 | 2.39k | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 2.39k | }}, |
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 | 395 | 106 | [&](auto& agg_method) -> void { | 396 | 106 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 6 | return; | 400 | 6 | } | 401 | 100 | auto& data = *agg_method.hash_table; | 402 | 100 | data.for_each_mapped([&](auto& mapped) { | 403 | 100 | if (mapped) { | 404 | 100 | _destroy_agg_status(mapped); | 405 | 100 | mapped = nullptr; | 406 | 100 | } | 407 | 100 | }); | 408 | 100 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 100 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEvS2_ Line | Count | Source | 395 | 774 | [&](auto& agg_method) -> void { | 396 | 774 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 107 | return; | 400 | 107 | } | 401 | 667 | auto& data = *agg_method.hash_table; | 402 | 667 | data.for_each_mapped([&](auto& mapped) { | 403 | 667 | if (mapped) { | 404 | 667 | _destroy_agg_status(mapped); | 405 | 667 | mapped = nullptr; | 406 | 667 | } | 407 | 667 | }); | 408 | 667 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 667 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ Line | Count | Source | 395 | 225 | [&](auto& agg_method) -> void { | 396 | 225 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 82 | return; | 400 | 82 | } | 401 | 143 | auto& data = *agg_method.hash_table; | 402 | 143 | data.for_each_mapped([&](auto& mapped) { | 403 | 143 | if (mapped) { | 404 | 143 | _destroy_agg_status(mapped); | 405 | 143 | mapped = nullptr; | 406 | 143 | } | 407 | 143 | }); | 408 | 143 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 143 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS2_ Line | Count | Source | 395 | 431 | [&](auto& agg_method) -> void { | 396 | 431 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 10 | return; | 400 | 10 | } | 401 | 421 | auto& data = *agg_method.hash_table; | 402 | 421 | data.for_each_mapped([&](auto& mapped) { | 403 | 421 | if (mapped) { | 404 | 421 | _destroy_agg_status(mapped); | 405 | 421 | mapped = nullptr; | 406 | 421 | } | 407 | 421 | }); | 408 | 421 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 421 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS2_ Line | Count | Source | 395 | 48 | [&](auto& agg_method) -> void { | 396 | 48 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 0 | return; | 400 | 0 | } | 401 | 48 | auto& data = *agg_method.hash_table; | 402 | 48 | data.for_each_mapped([&](auto& mapped) { | 403 | 48 | if (mapped) { | 404 | 48 | _destroy_agg_status(mapped); | 405 | 48 | mapped = nullptr; | 406 | 48 | } | 407 | 48 | }); | 408 | 48 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 48 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS2_ Line | Count | Source | 395 | 288 | [&](auto& agg_method) -> void { | 396 | 288 | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 1 | return; | 400 | 1 | } | 401 | 287 | auto& data = *agg_method.hash_table; | 402 | 287 | data.for_each_mapped([&](auto& mapped) { | 403 | 287 | if (mapped) { | 404 | 287 | _destroy_agg_status(mapped); | 405 | 287 | mapped = nullptr; | 406 | 287 | } | 407 | 287 | }); | 408 | 287 | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 287 | }}, |
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEvS2_ Line | Count | Source | 395 | 8.61k | [&](auto& agg_method) -> void { | 396 | 8.61k | if (use_simple_count) { | 397 | | // Inline count: mapped slots hold UInt64, | 398 | | // not real agg state pointers. Skip destroy. | 399 | 408 | return; | 400 | 408 | } | 401 | 8.20k | auto& data = *agg_method.hash_table; | 402 | 8.20k | data.for_each_mapped([&](auto& mapped) { | 403 | 8.20k | if (mapped) { | 404 | 8.20k | _destroy_agg_status(mapped); | 405 | 8.20k | mapped = nullptr; | 406 | 8.20k | } | 407 | 8.20k | }); | 408 | 8.20k | if (data.has_null_key_data()) { | 409 | 0 | _destroy_agg_status( | 410 | 0 | data.template get_null_key_data<AggregateDataPtr>()); | 411 | 0 | } | 412 | 8.20k | }}, |
|
413 | 45.7k | agg_data->method_variant); |
414 | 45.7k | } |
415 | | |
416 | 94.5k | void _close_without_key() { |
417 | | //because prepare maybe failed, and couldn't create agg data. |
418 | | //but finally call close to destory agg data, if agg data has bitmapValue |
419 | | //will be core dump, it's not initialized |
420 | 94.6k | if (agg_data_created_without_key) { |
421 | 94.6k | _destroy_agg_status(agg_data->without_key); |
422 | 94.6k | agg_data_created_without_key = false; |
423 | 94.6k | } |
424 | 94.5k | } |
425 | | void _destroy_agg_status(AggregateDataPtr data); |
426 | | }; |
427 | | |
428 | | struct PartitionedAggSharedState : public BasicSharedState, |
429 | | public std::enable_shared_from_this<PartitionedAggSharedState> { |
430 | | ENABLE_FACTORY_CREATOR(PartitionedAggSharedState) |
431 | | |
432 | 136 | PartitionedAggSharedState() = default; |
433 | 136 | ~PartitionedAggSharedState() override = default; |
434 | | |
435 | | void close(); |
436 | | |
437 | | AggSharedState* _in_mem_shared_state = nullptr; |
438 | | std::shared_ptr<BasicSharedState> _in_mem_shared_state_sptr; |
439 | | |
440 | | // partition count is no longer stored in shared state; operators maintain their own |
441 | | std::atomic<bool> _is_spilled = false; |
442 | | std::deque<SpillFileSPtr> _spill_partitions; |
443 | | }; |
444 | | |
445 | | struct SortSharedState : public BasicSharedState { |
446 | | ENABLE_FACTORY_CREATOR(SortSharedState) |
447 | | public: |
448 | | std::shared_ptr<Sorter> sorter; |
449 | | }; |
450 | | |
451 | | struct SpillSortSharedState : public BasicSharedState, |
452 | | public std::enable_shared_from_this<SpillSortSharedState> { |
453 | | ENABLE_FACTORY_CREATOR(SpillSortSharedState) |
454 | | |
455 | 32 | SpillSortSharedState() = default; |
456 | 32 | ~SpillSortSharedState() override = default; |
457 | | |
458 | 489 | void update_spill_block_batch_row_count(RuntimeState* state, const Block* block) { |
459 | 489 | auto rows = block->rows(); |
460 | 489 | if (rows > 0 && 0 == avg_row_bytes) { |
461 | 19 | avg_row_bytes = std::max((std::size_t)1, block->bytes() / rows); |
462 | 19 | spill_block_batch_row_count = |
463 | 19 | (state->spill_buffer_size_bytes() + avg_row_bytes - 1) / avg_row_bytes; |
464 | 19 | LOG(INFO) << "spill sort block batch row count: " << spill_block_batch_row_count; |
465 | 19 | } |
466 | 489 | } |
467 | | |
468 | | void close(); |
469 | | |
470 | | SortSharedState* in_mem_shared_state = nullptr; |
471 | | bool enable_spill = false; |
472 | | bool is_spilled = false; |
473 | | int64_t limit = -1; |
474 | | int64_t offset = 0; |
475 | | std::atomic_bool is_closed = false; |
476 | | std::shared_ptr<BasicSharedState> in_mem_shared_state_sptr; |
477 | | |
478 | | std::deque<SpillFileSPtr> sorted_spill_groups; |
479 | | size_t avg_row_bytes = 0; |
480 | | size_t spill_block_batch_row_count; |
481 | | }; |
482 | | |
483 | | struct UnionSharedState : public BasicSharedState { |
484 | | ENABLE_FACTORY_CREATOR(UnionSharedState) |
485 | | |
486 | | public: |
487 | 4.36k | UnionSharedState(int child_count = 1) : data_queue(child_count), _child_count(child_count) {}; |
488 | 0 | int child_count() const { return _child_count; } |
489 | | DataQueue data_queue; |
490 | | const int _child_count; |
491 | | }; |
492 | | |
493 | | struct DataQueueSharedState : public BasicSharedState { |
494 | | ENABLE_FACTORY_CREATOR(DataQueueSharedState) |
495 | | public: |
496 | | DataQueue data_queue; |
497 | | }; |
498 | | |
499 | | class MultiCastDataStreamer; |
500 | | |
501 | | struct MultiCastSharedState : public BasicSharedState, |
502 | | public std::enable_shared_from_this<MultiCastSharedState> { |
503 | | MultiCastSharedState(ObjectPool* pool, int cast_sender_count, int node_id); |
504 | | |
505 | | std::unique_ptr<MultiCastDataStreamer> multi_cast_data_streamer; |
506 | | }; |
507 | | |
508 | | struct AnalyticSharedState : public BasicSharedState { |
509 | | ENABLE_FACTORY_CREATOR(AnalyticSharedState) |
510 | | |
511 | | public: |
512 | 9.26k | AnalyticSharedState() = default; |
513 | | std::queue<Block> blocks_buffer; |
514 | | std::mutex buffer_mutex; |
515 | | bool sink_eos = false; |
516 | | std::mutex sink_eos_lock; |
517 | | Arena agg_arena_pool; |
518 | | }; |
519 | | |
520 | | struct JoinSharedState : public BasicSharedState { |
521 | | // For some join case, we can apply a short circuit strategy |
522 | | // 1. _has_null_in_build_side = true |
523 | | // 2. build side rows is empty, Join op is: inner join/right outer join/left semi/right semi/right anti |
524 | | bool _has_null_in_build_side = false; |
525 | | bool short_circuit_for_probe = false; |
526 | | // for some join, when build side rows is empty, we could return directly by add some additional null data in probe table. |
527 | | bool empty_right_table_need_probe_dispose = false; |
528 | | JoinOpVariants join_op_variants; |
529 | | }; |
530 | | |
531 | | struct HashJoinSharedState : public JoinSharedState { |
532 | | ENABLE_FACTORY_CREATOR(HashJoinSharedState) |
533 | 130k | HashJoinSharedState() { |
534 | 130k | hash_table_variant_vector.push_back(std::make_shared<JoinDataVariants>()); |
535 | 130k | } |
536 | 2.84k | HashJoinSharedState(int num_instances) { |
537 | 2.84k | source_deps.resize(num_instances, nullptr); |
538 | 2.84k | hash_table_variant_vector.resize(num_instances, nullptr); |
539 | 20.3k | for (int i = 0; i < num_instances; i++) { |
540 | 17.5k | hash_table_variant_vector[i] = std::make_shared<JoinDataVariants>(); |
541 | 17.5k | } |
542 | 2.84k | } |
543 | | std::shared_ptr<Arena> arena = std::make_shared<Arena>(); |
544 | | |
545 | | const std::vector<TupleDescriptor*> build_side_child_desc; |
546 | | size_t build_exprs_size = 0; |
547 | | std::shared_ptr<Block> build_block; |
548 | | std::shared_ptr<std::vector<uint32_t>> build_indexes_null; |
549 | | |
550 | | // Used by shared hash table |
551 | | // For probe operator, hash table in _hash_table_variants is read-only if visited flags is not |
552 | | // used. (visited flags will be used only in right / full outer join). |
553 | | // |
554 | | // For broadcast join, although hash table is read-only, some states in `_hash_table_variants` |
555 | | // are still could be written. For example, serialized keys will be written in a continuous |
556 | | // memory in `_hash_table_variants`. So before execution, we should use a local _hash_table_variants |
557 | | // which has a shared hash table in it. |
558 | | std::vector<std::shared_ptr<JoinDataVariants>> hash_table_variant_vector; |
559 | | |
560 | | // whether left semi join could directly return |
561 | | // if runtime filters contains local in filter, we can make sure all input rows are matched |
562 | | // local filter will always be applied, and in filter could guarantee precise filtering |
563 | | // ATTN: we should disable always_true logic for in filter when we set this flag |
564 | | bool left_semi_direct_return = false; |
565 | | |
566 | | // ASOF JOIN specific fields |
567 | | // Whether the inequality is >= or > (true) vs <= or < (false) |
568 | | bool asof_inequality_is_greater = true; |
569 | | // Whether the inequality is strict (> or <) vs non-strict (>= or <=) |
570 | | bool asof_inequality_is_strict = false; |
571 | | |
572 | | // ASOF JOIN pre-sorted index with inline values for O(log K) branchless lookup |
573 | | // Typed AsofIndexGroups stored in a variant (uint32_t for DateV2, uint64_t for DateTimeV2/TimestampTZ) |
574 | | AsofIndexVariant asof_index_groups; |
575 | | // build_row_index -> bucket_id for O(1) reverse lookup |
576 | | std::vector<uint32_t> asof_build_row_to_bucket; |
577 | | }; |
578 | | |
579 | | struct PartitionedHashJoinSharedState |
580 | | : public HashJoinSharedState, |
581 | | public std::enable_shared_from_this<PartitionedHashJoinSharedState> { |
582 | | ENABLE_FACTORY_CREATOR(PartitionedHashJoinSharedState) |
583 | | |
584 | | std::unique_ptr<RuntimeState> _inner_runtime_state; |
585 | | std::shared_ptr<HashJoinSharedState> _inner_shared_state; |
586 | | std::vector<std::unique_ptr<MutableBlock>> _partitioned_build_blocks; |
587 | | std::vector<SpillFileSPtr> _spilled_build_groups; |
588 | | std::atomic<bool> _is_spilled = false; |
589 | | }; |
590 | | |
591 | | struct NestedLoopJoinSharedState : public JoinSharedState { |
592 | | ENABLE_FACTORY_CREATOR(NestedLoopJoinSharedState) |
593 | | // if true, probe child has no more rows to process |
594 | | bool probe_side_eos = false; |
595 | | // Visited flags for each row in build side. |
596 | | MutableColumns build_side_visited_flags; |
597 | | // List of build blocks, constructed in prepare() |
598 | | Blocks build_blocks; |
599 | | }; |
600 | | |
601 | | struct PartitionSortNodeSharedState : public BasicSharedState { |
602 | | ENABLE_FACTORY_CREATOR(PartitionSortNodeSharedState) |
603 | | public: |
604 | | std::queue<Block> blocks_buffer; |
605 | | std::mutex buffer_mutex; |
606 | | std::vector<std::unique_ptr<PartitionSorter>> partition_sorts; |
607 | | bool sink_eos = false; |
608 | | std::mutex sink_eos_lock; |
609 | | std::mutex prepared_finish_lock; |
610 | | }; |
611 | | |
612 | | struct SetSharedState : public BasicSharedState { |
613 | | ENABLE_FACTORY_CREATOR(SetSharedState) |
614 | | public: |
615 | | /// default init |
616 | | Block build_block; // build to source |
617 | | //record element size in hashtable |
618 | | int64_t valid_element_in_hash_tbl = 0; |
619 | | //first: idx mapped to column types |
620 | | //second: column_id, could point to origin column or cast column |
621 | | std::unordered_map<int, int> build_col_idx; |
622 | | |
623 | | //// shared static states (shared, decided in prepare/open...) |
624 | | |
625 | | /// init in setup_local_state |
626 | | std::unique_ptr<SetDataVariants> hash_table_variants = |
627 | | std::make_unique<SetDataVariants>(); // the real data HERE. |
628 | | std::vector<bool> build_not_ignore_null; |
629 | | |
630 | | // The SET operator's child might have different nullable attributes. |
631 | | // If a calculation involves both nullable and non-nullable columns, the final output should be a nullable column |
632 | | Status update_build_not_ignore_null(const VExprContextSPtrs& ctxs); |
633 | | |
634 | | size_t get_hash_table_size() const; |
635 | | /// init in both upstream side. |
636 | | //The i-th result expr list refers to the i-th child. |
637 | | std::vector<VExprContextSPtrs> child_exprs_lists; |
638 | | |
639 | | /// init in build side |
640 | | size_t child_quantity; |
641 | | VExprContextSPtrs build_child_exprs; |
642 | | std::vector<Dependency*> probe_finished_children_dependency; |
643 | | |
644 | | /// init in probe side |
645 | | std::vector<VExprContextSPtrs> probe_child_exprs_lists; |
646 | | |
647 | | std::atomic<bool> ready_for_read = false; |
648 | | |
649 | | Arena arena; |
650 | | |
651 | | /// called in setup_local_state |
652 | | Status hash_table_init(); |
653 | | }; |
654 | | |
655 | | enum class ExchangeType : uint8_t { |
656 | | NOOP = 0, |
657 | | // Shuffle data by Crc32CHashPartitioner |
658 | | HASH_SHUFFLE = 1, |
659 | | // Round-robin passthrough data blocks. |
660 | | PASSTHROUGH = 2, |
661 | | // Shuffle data by Crc32HashPartitioner<ShuffleChannelIds> (e.g. same as storage engine). |
662 | | BUCKET_HASH_SHUFFLE = 3, |
663 | | // Passthrough data blocks to all channels. |
664 | | BROADCAST = 4, |
665 | | // Passthrough data to channels evenly in an adaptive way. |
666 | | ADAPTIVE_PASSTHROUGH = 5, |
667 | | // Send all data to the first channel. |
668 | | PASS_TO_ONE = 6, |
669 | | }; |
670 | | |
671 | 232k | inline std::string get_exchange_type_name(ExchangeType idx) { |
672 | 232k | switch (idx) { |
673 | 14 | case ExchangeType::NOOP: |
674 | 14 | return "NOOP"; |
675 | 31.2k | case ExchangeType::HASH_SHUFFLE: |
676 | 31.2k | return "HASH_SHUFFLE"; |
677 | 191k | case ExchangeType::PASSTHROUGH: |
678 | 191k | return "PASSTHROUGH"; |
679 | 1.09k | case ExchangeType::BUCKET_HASH_SHUFFLE: |
680 | 1.09k | return "BUCKET_HASH_SHUFFLE"; |
681 | 520 | case ExchangeType::BROADCAST: |
682 | 520 | return "BROADCAST"; |
683 | 1.77k | case ExchangeType::ADAPTIVE_PASSTHROUGH: |
684 | 1.77k | return "ADAPTIVE_PASSTHROUGH"; |
685 | 5.60k | case ExchangeType::PASS_TO_ONE: |
686 | 5.60k | return "PASS_TO_ONE"; |
687 | 232k | } |
688 | 0 | throw Exception(Status::FatalError("__builtin_unreachable")); |
689 | 232k | } |
690 | | |
691 | | struct DataDistribution { |
692 | 2.67M | DataDistribution(ExchangeType type) : distribution_type(type) {} |
693 | | DataDistribution(ExchangeType type, const std::vector<TExpr>& partition_exprs_) |
694 | 226k | : distribution_type(type), partition_exprs(partition_exprs_) {} |
695 | 251k | DataDistribution(const DataDistribution& other) = default; |
696 | 816k | bool need_local_exchange() const { return distribution_type != ExchangeType::NOOP; } |
697 | 778k | DataDistribution& operator=(const DataDistribution& other) = default; |
698 | | ExchangeType distribution_type; |
699 | | std::vector<TExpr> partition_exprs; |
700 | | }; |
701 | | |
702 | | class ExchangerBase; |
703 | | |
704 | | struct LocalExchangeSharedState : public BasicSharedState { |
705 | | public: |
706 | | ENABLE_FACTORY_CREATOR(LocalExchangeSharedState); |
707 | | LocalExchangeSharedState(int num_instances); |
708 | | ~LocalExchangeSharedState() override; |
709 | | std::unique_ptr<ExchangerBase> exchanger {}; |
710 | | std::vector<RuntimeProfile::Counter*> mem_counters; |
711 | | std::atomic<int64_t> mem_usage = 0; |
712 | | std::atomic<size_t> _buffer_mem_limit = config::local_exchange_buffer_mem_limit; |
713 | | // 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. |
714 | | std::mutex le_lock; |
715 | | void sub_running_sink_operators(); |
716 | | void sub_running_source_operators(); |
717 | 232k | void _set_always_ready() { |
718 | 1.49M | for (auto& dep : source_deps) { |
719 | 1.49M | DCHECK(dep); |
720 | 1.49M | dep->set_always_ready(); |
721 | 1.49M | } |
722 | 232k | for (auto& dep : sink_deps) { |
723 | 232k | DCHECK(dep); |
724 | 232k | dep->set_always_ready(); |
725 | 232k | } |
726 | 232k | } |
727 | | |
728 | 295k | Dependency* get_sink_dep_by_channel_id(int channel_id) { return nullptr; } |
729 | | |
730 | 251k | void set_ready_to_read(int channel_id) { |
731 | 251k | auto& dep = source_deps[channel_id]; |
732 | 18.4E | DCHECK(dep) << channel_id; |
733 | 251k | dep->set_ready(); |
734 | 251k | } |
735 | | |
736 | 251k | void add_mem_usage(int channel_id, size_t delta) { mem_counters[channel_id]->update(delta); } |
737 | | |
738 | 251k | void sub_mem_usage(int channel_id, size_t delta) { |
739 | 251k | mem_counters[channel_id]->update(-(int64_t)delta); |
740 | 251k | } |
741 | | |
742 | 218k | void add_total_mem_usage(size_t delta) { |
743 | 218k | if (cast_set<int64_t>(mem_usage.fetch_add(delta) + delta) > _buffer_mem_limit) { |
744 | 29 | sink_deps.front()->block(); |
745 | 29 | } |
746 | 218k | } |
747 | | |
748 | 218k | void sub_total_mem_usage(size_t delta) { |
749 | 218k | auto prev_usage = mem_usage.fetch_sub(delta); |
750 | 218k | DCHECK_GE(prev_usage - delta, 0) << "prev_usage: " << prev_usage << " delta: " << delta; |
751 | 218k | if (cast_set<int64_t>(prev_usage - delta) <= _buffer_mem_limit) { |
752 | 218k | sink_deps.front()->set_ready(); |
753 | 218k | } |
754 | 218k | } |
755 | | |
756 | 0 | void set_low_memory_mode(RuntimeState* state) { |
757 | 0 | _buffer_mem_limit = std::min<int64_t>(config::local_exchange_buffer_mem_limit, |
758 | 0 | state->low_memory_mode_buffer_limit()); |
759 | 0 | } |
760 | | }; |
761 | | |
762 | | } // namespace doris |