/root/doris/be/src/pipeline/dependency.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <concurrentqueue.h> |
21 | | #include <sqltypes.h> |
22 | | |
23 | | #include <atomic> |
24 | | #include <functional> |
25 | | #include <memory> |
26 | | #include <mutex> |
27 | | #include <thread> |
28 | | #include <utility> |
29 | | |
30 | | #include "common/config.h" |
31 | | #include "common/logging.h" |
32 | | #include "pipeline/common/agg_utils.h" |
33 | | #include "pipeline/common/join_utils.h" |
34 | | #include "pipeline/common/set_utils.h" |
35 | | #include "pipeline/exec/data_queue.h" |
36 | | #include "pipeline/exec/join/process_hash_table_probe.h" |
37 | | #include "util/stack_util.h" |
38 | | #include "vec/common/sort/partition_sorter.h" |
39 | | #include "vec/common/sort/sorter.h" |
40 | | #include "vec/core/block.h" |
41 | | #include "vec/core/types.h" |
42 | | #include "vec/spill/spill_stream.h" |
43 | | |
44 | | namespace doris::vectorized { |
45 | | class AggFnEvaluator; |
46 | | class VSlotRef; |
47 | | } // namespace doris::vectorized |
48 | | |
49 | | namespace doris::pipeline { |
50 | | #include "common/compile_check_begin.h" |
51 | | class Dependency; |
52 | | class PipelineTask; |
53 | | struct BasicSharedState; |
54 | | using DependencySPtr = std::shared_ptr<Dependency>; |
55 | | class LocalExchangeSourceLocalState; |
56 | | |
57 | | static constexpr auto SLOW_DEPENDENCY_THRESHOLD = 60 * 1000L * 1000L * 1000L; |
58 | | static constexpr auto TIME_UNIT_DEPENDENCY_LOG = 30 * 1000L * 1000L * 1000L; |
59 | | static_assert(TIME_UNIT_DEPENDENCY_LOG < SLOW_DEPENDENCY_THRESHOLD); |
60 | | |
61 | | struct BasicSharedState { |
62 | | ENABLE_FACTORY_CREATOR(BasicSharedState) |
63 | | |
64 | | template <class TARGET> |
65 | 4.47M | TARGET* cast() { |
66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) |
67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() |
68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); |
69 | 4.47M | return reinterpret_cast<TARGET*>(this); |
70 | 4.47M | } _ZN5doris8pipeline16BasicSharedState4castINS0_19HashJoinSharedStateEEEPT_v Line | Count | Source | 65 | 333k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 333k | return reinterpret_cast<TARGET*>(this); | 70 | 333k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_30PartitionedHashJoinSharedStateEEEPT_v Line | Count | Source | 65 | 83.4k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 83.4k | return reinterpret_cast<TARGET*>(this); | 70 | 83.4k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_15SortSharedStateEEEPT_v Line | Count | Source | 65 | 734k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 734k | return reinterpret_cast<TARGET*>(this); | 70 | 734k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_20SpillSortSharedStateEEEPT_v Line | Count | Source | 65 | 513k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 513k | return reinterpret_cast<TARGET*>(this); | 70 | 513k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_25NestedLoopJoinSharedStateEEEPT_v Line | Count | Source | 65 | 32.1k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 32.1k | return reinterpret_cast<TARGET*>(this); | 70 | 32.1k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_19AnalyticSharedStateEEEPT_v Line | Count | Source | 65 | 45.4k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 45.4k | return reinterpret_cast<TARGET*>(this); | 70 | 45.4k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_14AggSharedStateEEEPT_v Line | Count | Source | 65 | 694k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 694k | return reinterpret_cast<TARGET*>(this); | 70 | 694k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_25PartitionedAggSharedStateEEEPT_v Line | Count | Source | 65 | 314k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 314k | return reinterpret_cast<TARGET*>(this); | 70 | 314k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_16UnionSharedStateEEEPT_v Line | Count | Source | 65 | 18.3k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 18.3k | return reinterpret_cast<TARGET*>(this); | 70 | 18.3k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_28PartitionSortNodeSharedStateEEEPT_v Line | Count | Source | 65 | 1.62k | TARGET* cast() { | 66 | 1.62k | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 0 | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 0 | << " and expect type is" << typeid(TARGET).name(); | 69 | 1.62k | return reinterpret_cast<TARGET*>(this); | 70 | 1.62k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_20MultiCastSharedStateEEEPT_v Line | Count | Source | 65 | 9.70k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 9.70k | return reinterpret_cast<TARGET*>(this); | 70 | 9.70k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_14SetSharedStateEEEPT_v Line | Count | Source | 65 | 4.88k | TARGET* cast() { | 66 | 4.88k | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 0 | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 0 | << " and expect type is" << typeid(TARGET).name(); | 69 | 4.88k | return reinterpret_cast<TARGET*>(this); | 70 | 4.88k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_24LocalExchangeSharedStateEEEPT_v Line | Count | Source | 65 | 1.24M | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 1.24M | return reinterpret_cast<TARGET*>(this); | 70 | 1.24M | } |
_ZN5doris8pipeline16BasicSharedState4castIS1_EEPT_v Line | Count | Source | 65 | 439k | TARGET* cast() { | 66 | 18.4E | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 18.4E | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 18.4E | << " and expect type is" << typeid(TARGET).name(); | 69 | 439k | return reinterpret_cast<TARGET*>(this); | 70 | 439k | } |
_ZN5doris8pipeline16BasicSharedState4castINS0_16CacheSharedStateEEEPT_v Line | Count | Source | 65 | 182 | TARGET* cast() { | 66 | 182 | DCHECK(dynamic_cast<TARGET*>(this)) | 67 | 0 | << " Mismatch type! Current type is " << typeid(*this).name() | 68 | 0 | << " and expect type is" << typeid(TARGET).name(); | 69 | 182 | return reinterpret_cast<TARGET*>(this); | 70 | 182 | } |
|
71 | | template <class TARGET> |
72 | | const TARGET* cast() const { |
73 | | DCHECK(dynamic_cast<const TARGET*>(this)) |
74 | | << " Mismatch type! Current type is " << typeid(*this).name() |
75 | | << " and expect type is" << typeid(TARGET).name(); |
76 | | return reinterpret_cast<const TARGET*>(this); |
77 | | } |
78 | | std::vector<DependencySPtr> source_deps; |
79 | | std::vector<DependencySPtr> sink_deps; |
80 | | int id = 0; |
81 | | std::set<int> related_op_ids; |
82 | | |
83 | 2.92M | virtual ~BasicSharedState() = default; |
84 | | |
85 | | Dependency* create_source_dependency(int operator_id, int node_id, const std::string& name); |
86 | | void create_source_dependencies(int num_sources, int operator_id, int node_id, |
87 | | const std::string& name); |
88 | | Dependency* create_sink_dependency(int dest_id, int node_id, const std::string& name); |
89 | 916k | std::vector<DependencySPtr> get_dep_by_channel_id(int channel_id) { |
90 | 916k | DCHECK_LT(channel_id, source_deps.size()); |
91 | 916k | return {source_deps[channel_id]}; |
92 | 916k | } |
93 | | }; |
94 | | |
95 | | class Dependency : public std::enable_shared_from_this<Dependency> { |
96 | | public: |
97 | | ENABLE_FACTORY_CREATOR(Dependency); |
98 | | Dependency(int id, int node_id, std::string name, bool ready = false) |
99 | 10.0M | : _id(id), _node_id(node_id), _name(std::move(name)), _ready(ready) {} |
100 | 10.0M | virtual ~Dependency() = default; |
101 | | |
102 | 0 | [[nodiscard]] int id() const { return _id; } |
103 | 14.5M | [[nodiscard]] virtual std::string name() const { return _name; } |
104 | 410k | BasicSharedState* shared_state() { return _shared_state; } |
105 | 4.28M | void set_shared_state(BasicSharedState* shared_state) { _shared_state = shared_state; } |
106 | | virtual std::string debug_string(int indentation_level = 0); |
107 | 731M | bool ready() const { return _ready; } |
108 | | |
109 | | // Start the watcher. We use it to count how long this dependency block the current pipeline task. |
110 | 9.46M | void start_watcher() { _watcher.start(); } |
111 | 9.55M | [[nodiscard]] int64_t watcher_elapse_time() { return _watcher.elapsed_time(); } |
112 | | |
113 | | // Which dependency current pipeline task is blocked by. `nullptr` if this dependency is ready. |
114 | | [[nodiscard]] Dependency* is_blocked_by(std::shared_ptr<PipelineTask> task = nullptr); |
115 | | // Notify downstream pipeline tasks this dependency is ready. |
116 | | void set_ready(); |
117 | 971k | void set_ready_to_read(int channel_id = 0) { |
118 | 971k | DCHECK_LT(channel_id, _shared_state->source_deps.size()) << debug_string(); |
119 | 971k | _shared_state->source_deps[channel_id]->set_ready(); |
120 | 971k | } |
121 | 794 | void set_ready_to_write() { |
122 | 794 | DCHECK_EQ(_shared_state->sink_deps.size(), 1) << debug_string(); |
123 | 794 | _shared_state->sink_deps.front()->set_ready(); |
124 | 794 | } |
125 | | |
126 | | // Notify downstream pipeline tasks this dependency is blocked. |
127 | 582M | void block() { |
128 | 582M | if (_always_ready) { |
129 | 458k | return; |
130 | 458k | } |
131 | 581M | std::unique_lock<std::mutex> lc(_always_ready_lock); |
132 | 581M | if (_always_ready) { |
133 | 10 | return; |
134 | 10 | } |
135 | 581M | _ready = false; |
136 | 581M | } |
137 | | |
138 | 5.24M | void set_always_ready() { |
139 | 5.24M | if (_always_ready) { |
140 | 2.62M | return; |
141 | 2.62M | } |
142 | 2.61M | std::unique_lock<std::mutex> lc(_always_ready_lock); |
143 | 2.61M | if (_always_ready) { |
144 | 0 | return; |
145 | 0 | } |
146 | 2.61M | _always_ready = true; |
147 | 2.61M | set_ready(); |
148 | 2.61M | } |
149 | | |
150 | | protected: |
151 | | void _add_block_task(std::shared_ptr<PipelineTask> task); |
152 | | |
153 | | const int _id; |
154 | | const int _node_id; |
155 | | const std::string _name; |
156 | | std::atomic<bool> _ready; |
157 | | |
158 | | BasicSharedState* _shared_state = nullptr; |
159 | | MonotonicStopWatch _watcher; |
160 | | |
161 | | std::mutex _task_lock; |
162 | | std::vector<std::weak_ptr<PipelineTask>> _blocked_task; |
163 | | |
164 | | // If `_always_ready` is true, `block()` will never block tasks. |
165 | | std::atomic<bool> _always_ready = false; |
166 | | std::mutex _always_ready_lock; |
167 | | }; |
168 | | |
169 | | struct FakeSharedState final : public BasicSharedState { |
170 | | ENABLE_FACTORY_CREATOR(FakeSharedState) |
171 | | }; |
172 | | |
173 | | class CountedFinishDependency final : public Dependency { |
174 | | public: |
175 | | using SharedState = FakeSharedState; |
176 | | CountedFinishDependency(int id, int node_id, std::string name) |
177 | 192k | : Dependency(id, node_id, std::move(name), true) {} |
178 | | |
179 | 12.6k | void add() { |
180 | 12.6k | std::unique_lock<std::mutex> l(_mtx); |
181 | 12.6k | if (!_counter) { |
182 | 12.6k | block(); |
183 | 12.6k | } |
184 | 12.6k | _counter++; |
185 | 12.6k | } |
186 | | |
187 | 12.6k | void sub() { |
188 | 12.6k | std::unique_lock<std::mutex> l(_mtx); |
189 | 12.6k | _counter--; |
190 | 12.6k | if (!_counter) { |
191 | 12.6k | set_ready(); |
192 | 12.6k | } |
193 | 12.6k | } |
194 | | |
195 | | std::string debug_string(int indentation_level = 0) override; |
196 | | |
197 | | private: |
198 | | std::mutex _mtx; |
199 | | uint32_t _counter = 0; |
200 | | }; |
201 | | |
202 | | struct RuntimeFilterTimerQueue; |
203 | | class RuntimeFilterTimer { |
204 | | public: |
205 | | RuntimeFilterTimer(int64_t registration_time, int32_t wait_time_ms, |
206 | | std::shared_ptr<Dependency> parent) |
207 | | : _parent(std::move(parent)), |
208 | | _registration_time(registration_time), |
209 | 60.4k | _wait_time_ms(wait_time_ms) {} |
210 | | |
211 | | // Called by runtime filter producer. |
212 | | void call_ready(); |
213 | | |
214 | | // Called by RuntimeFilterTimerQueue which is responsible for checking if this rf is timeout. |
215 | | void call_timeout(); |
216 | | |
217 | 3.92M | int64_t registration_time() const { return _registration_time; } |
218 | 3.92M | int32_t wait_time_ms() const { return _wait_time_ms; } |
219 | | |
220 | | void set_local_runtime_filter_dependencies( |
221 | 23.9k | const std::vector<std::shared_ptr<Dependency>>& deps) { |
222 | 23.9k | _local_runtime_filter_dependencies = deps; |
223 | 23.9k | } |
224 | | |
225 | | bool should_be_check_timeout(); |
226 | | |
227 | | private: |
228 | | friend struct RuntimeFilterTimerQueue; |
229 | | std::shared_ptr<Dependency> _parent = nullptr; |
230 | | std::vector<std::shared_ptr<Dependency>> _local_runtime_filter_dependencies; |
231 | | std::mutex _lock; |
232 | | int64_t _registration_time; |
233 | | const int32_t _wait_time_ms; |
234 | | }; |
235 | | |
236 | | struct RuntimeFilterTimerQueue { |
237 | | constexpr static int64_t interval = 10; |
238 | 5 | void run() { _thread.detach(); } |
239 | | void start(); |
240 | | |
241 | 2 | void stop() { |
242 | 2 | _stop = true; |
243 | 2 | cv.notify_all(); |
244 | 2 | wait_for_shutdown(); |
245 | 2 | } |
246 | | |
247 | 2 | void wait_for_shutdown() const { |
248 | 4 | while (!_shutdown) { |
249 | 2 | std::this_thread::sleep_for(std::chrono::milliseconds(interval)); |
250 | 2 | } |
251 | 2 | } |
252 | | |
253 | 2 | ~RuntimeFilterTimerQueue() = default; |
254 | 5 | RuntimeFilterTimerQueue() { _thread = std::thread(&RuntimeFilterTimerQueue::start, this); } |
255 | 38.5k | void push_filter_timer(std::vector<std::shared_ptr<pipeline::RuntimeFilterTimer>>&& filter) { |
256 | 38.5k | std::unique_lock<std::mutex> lc(_que_lock); |
257 | 38.5k | _que.insert(_que.end(), filter.begin(), filter.end()); |
258 | 38.5k | cv.notify_all(); |
259 | 38.5k | } |
260 | | |
261 | | std::thread _thread; |
262 | | std::condition_variable cv; |
263 | | std::mutex cv_m; |
264 | | std::mutex _que_lock; |
265 | | std::atomic_bool _stop = false; |
266 | | std::atomic_bool _shutdown = false; |
267 | | std::list<std::shared_ptr<pipeline::RuntimeFilterTimer>> _que; |
268 | | }; |
269 | | |
270 | | struct AggSharedState : public BasicSharedState { |
271 | | ENABLE_FACTORY_CREATOR(AggSharedState) |
272 | | public: |
273 | 347k | AggSharedState() { |
274 | 347k | agg_data = std::make_unique<AggregatedDataVariants>(); |
275 | 347k | agg_arena_pool = std::make_unique<vectorized::Arena>(); |
276 | 347k | } |
277 | 347k | ~AggSharedState() override { |
278 | 347k | if (!probe_expr_ctxs.empty()) { |
279 | 186k | _close_with_serialized_key(); |
280 | 186k | } else { |
281 | 161k | _close_without_key(); |
282 | 161k | } |
283 | 347k | } |
284 | | |
285 | | Status reset_hash_table(); |
286 | | |
287 | | bool do_limit_filter(vectorized::Block* block, size_t num_rows, |
288 | | const std::vector<int>* key_locs = nullptr); |
289 | | void build_limit_heap(size_t hash_table_size); |
290 | | |
291 | | // We should call this function only at 1st phase. |
292 | | // 1st phase: is_merge=true, only have one SlotRef. |
293 | | // 2nd phase: is_merge=false, maybe have multiple exprs. |
294 | | static int get_slot_column_id(const vectorized::AggFnEvaluator* evaluator); |
295 | | |
296 | | AggregatedDataVariantsUPtr agg_data = nullptr; |
297 | | std::unique_ptr<AggregateDataContainer> aggregate_data_container; |
298 | | ArenaUPtr agg_arena_pool; |
299 | | std::vector<vectorized::AggFnEvaluator*> aggregate_evaluators; |
300 | | // group by k1,k2 |
301 | | vectorized::VExprContextSPtrs probe_expr_ctxs; |
302 | | size_t input_num_rows = 0; |
303 | | std::vector<vectorized::AggregateDataPtr> values; |
304 | | /// The total size of the row from the aggregate functions. |
305 | | size_t total_size_of_aggregate_states = 0; |
306 | | size_t align_aggregate_states = 1; |
307 | | /// The offset to the n-th aggregate function in a row of aggregate functions. |
308 | | vectorized::Sizes offsets_of_aggregate_states; |
309 | | std::vector<size_t> make_nullable_keys; |
310 | | |
311 | | bool agg_data_created_without_key = false; |
312 | | bool enable_spill = false; |
313 | | bool reach_limit = false; |
314 | | |
315 | | int64_t limit = -1; |
316 | | bool do_sort_limit = false; |
317 | | vectorized::MutableColumns limit_columns; |
318 | | int limit_columns_min = -1; |
319 | | vectorized::PaddedPODArray<uint8_t> need_computes; |
320 | | std::vector<uint8_t> cmp_res; |
321 | | std::vector<int> order_directions; |
322 | | std::vector<int> null_directions; |
323 | | |
324 | | struct HeapLimitCursor { |
325 | | HeapLimitCursor(int row_id, vectorized::MutableColumns& limit_columns, |
326 | | std::vector<int>& order_directions, std::vector<int>& null_directions) |
327 | | : _row_id(row_id), |
328 | | _limit_columns(limit_columns), |
329 | | _order_directions(order_directions), |
330 | 89.7k | _null_directions(null_directions) {} |
331 | | |
332 | | HeapLimitCursor(const HeapLimitCursor& other) = default; |
333 | | |
334 | | HeapLimitCursor(HeapLimitCursor&& other) noexcept |
335 | | : _row_id(other._row_id), |
336 | | _limit_columns(other._limit_columns), |
337 | | _order_directions(other._order_directions), |
338 | 564k | _null_directions(other._null_directions) {} |
339 | | |
340 | 0 | HeapLimitCursor& operator=(const HeapLimitCursor& other) noexcept { |
341 | 0 | _row_id = other._row_id; |
342 | 0 | return *this; |
343 | 0 | } |
344 | | |
345 | 1.06M | HeapLimitCursor& operator=(HeapLimitCursor&& other) noexcept { |
346 | 1.06M | _row_id = other._row_id; |
347 | 1.06M | return *this; |
348 | 1.06M | } |
349 | | |
350 | 975k | bool operator<(const HeapLimitCursor& rhs) const { |
351 | 1.46M | for (int i = 0; i < _limit_columns.size(); ++i) { |
352 | 1.46M | const auto& _limit_column = _limit_columns[i]; |
353 | 1.46M | auto res = _limit_column->compare_at(_row_id, rhs._row_id, *_limit_column, |
354 | 1.46M | _null_directions[i]) * |
355 | 1.46M | _order_directions[i]; |
356 | 1.46M | if (res < 0) { |
357 | 503k | return true; |
358 | 966k | } else if (res > 0) { |
359 | 491k | return false; |
360 | 491k | } |
361 | 1.46M | } |
362 | 18.4E | return false; |
363 | 975k | } |
364 | | |
365 | | int _row_id; |
366 | | vectorized::MutableColumns& _limit_columns; |
367 | | std::vector<int>& _order_directions; |
368 | | std::vector<int>& _null_directions; |
369 | | }; |
370 | | |
371 | | std::priority_queue<HeapLimitCursor> limit_heap; |
372 | | |
373 | | // Refresh the top limit heap with a new row |
374 | | void refresh_top_limit(size_t row_id, const vectorized::ColumnRawPtrs& key_columns); |
375 | | |
376 | | private: |
377 | | vectorized::MutableColumns _get_keys_hash_table(); |
378 | | |
379 | 186k | void _close_with_serialized_key() { |
380 | 186k | std::visit(vectorized::Overload {[&](std::monostate& arg) -> void { |
381 | | // Do nothing |
382 | 0 | }, |
383 | 186k | [&](auto& agg_method) -> void { |
384 | 186k | auto& data = *agg_method.hash_table; |
385 | 22.5M | data.for_each_mapped([&](auto& mapped) { |
386 | 22.5M | if (mapped) { |
387 | 22.5M | static_cast<void>(_destroy_agg_status(mapped)); |
388 | 22.5M | mapped = nullptr; |
389 | 22.5M | } |
390 | 22.5M | }); _ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS9_vEEEEEEvS3_ENKUlS3_E_clISA_EEDaS3_ Line | Count | Source | 385 | 843k | data.for_each_mapped([&](auto& mapped) { | 386 | 843k | if (mapped) { | 387 | 843k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 843k | mapped = nullptr; | 389 | 843k | } | 390 | 843k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS3_ENKUlS3_E_clIS9_EEDaS3_ Line | Count | Source | 385 | 570 | data.for_each_mapped([&](auto& mapped) { | 386 | 570 | if (mapped) { | 387 | 570 | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 570 | mapped = nullptr; | 389 | 570 | } | 390 | 570 | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS3_ENKUlS3_E_clIS9_EEDaS3_ Line | Count | Source | 385 | 24 | data.for_each_mapped([&](auto& mapped) { | 386 | 24 | if (mapped) { | 387 | 24 | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 24 | mapped = nullptr; | 389 | 24 | } | 390 | 24 | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS3_ENKUlS3_E_clIS9_EEDaS3_ Line | Count | Source | 385 | 1.09M | data.for_each_mapped([&](auto& mapped) { | 386 | 1.09M | if (mapped) { | 387 | 1.09M | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 1.09M | mapped = nullptr; | 389 | 1.09M | } | 390 | 1.09M | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS3_ENKUlS3_E_clIS9_EEDaS3_ Line | Count | Source | 385 | 46.7k | data.for_each_mapped([&](auto& mapped) { | 386 | 46.7k | if (mapped) { | 387 | 46.7k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 46.7k | mapped = nullptr; | 389 | 46.7k | } | 390 | 46.7k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEEvS3_ENKUlS3_E_clIS9_EEDaS3_ Line | Count | Source | 385 | 2.24k | data.for_each_mapped([&](auto& mapped) { | 386 | 2.24k | if (mapped) { | 387 | 2.24k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 2.24k | mapped = nullptr; | 389 | 2.24k | } | 390 | 2.24k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapISA_Pc9HashCRC32ISA_EEEEEEvS3_ENKUlS3_E_clISC_EEDaS3_ Line | Count | Source | 385 | 126 | data.for_each_mapped([&](auto& mapped) { | 386 | 126 | if (mapped) { | 387 | 126 | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 126 | mapped = nullptr; | 389 | 126 | } | 390 | 126 | }); |
Unexecuted instantiation: _ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapISA_Pc9HashCRC32ISA_EEEEEEvS3_ENKUlS3_E_clISC_EEDaS3_ _ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS3_ENKUlS3_E_clIS9_EEDaS3_ Line | Count | Source | 385 | 75.2k | data.for_each_mapped([&](auto& mapped) { | 386 | 75.2k | if (mapped) { | 387 | 75.2k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 75.2k | mapped = nullptr; | 389 | 75.2k | } | 390 | 75.2k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS3_ENKUlS3_E_clIS9_EEDaS3_ Line | Count | Source | 385 | 45.7k | data.for_each_mapped([&](auto& mapped) { | 386 | 45.7k | if (mapped) { | 387 | 45.7k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 45.7k | mapped = nullptr; | 389 | 45.7k | } | 390 | 45.7k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIhNS6_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS3_ENKUlS3_E_clISB_EEDaS3_ Line | Count | Source | 385 | 3.15k | data.for_each_mapped([&](auto& mapped) { | 386 | 3.15k | if (mapped) { | 387 | 3.15k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 3.15k | mapped = nullptr; | 389 | 3.15k | } | 390 | 3.15k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberItNS6_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS3_ENKUlS3_E_clISB_EEDaS3_ Line | Count | Source | 385 | 1.68k | data.for_each_mapped([&](auto& mapped) { | 386 | 1.68k | if (mapped) { | 387 | 1.68k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 1.68k | mapped = nullptr; | 389 | 1.68k | } | 390 | 1.68k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIjNS6_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS3_ENKUlS3_E_clISB_EEDaS3_ Line | Count | Source | 385 | 1.84M | data.for_each_mapped([&](auto& mapped) { | 386 | 1.84M | if (mapped) { | 387 | 1.84M | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 1.84M | mapped = nullptr; | 389 | 1.84M | } | 390 | 1.84M | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberImNS6_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS3_ENKUlS3_E_clISB_EEDaS3_ Line | Count | Source | 385 | 23.9k | data.for_each_mapped([&](auto& mapped) { | 386 | 23.9k | if (mapped) { | 387 | 23.9k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 23.9k | mapped = nullptr; | 389 | 23.9k | } | 390 | 23.9k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIjNS6_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS3_ENKUlS3_E_clISB_EEDaS3_ Line | Count | Source | 385 | 12.0M | data.for_each_mapped([&](auto& mapped) { | 386 | 12.0M | if (mapped) { | 387 | 12.0M | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 12.0M | mapped = nullptr; | 389 | 12.0M | } | 390 | 12.0M | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberImNS6_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS3_ENKUlS3_E_clISB_EEDaS3_ Line | Count | Source | 385 | 95.3k | data.for_each_mapped([&](auto& mapped) { | 386 | 95.3k | if (mapped) { | 387 | 95.3k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 95.3k | mapped = nullptr; | 389 | 95.3k | } | 390 | 95.3k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIN4wide7integerILm128EjEENS6_15DataWithNullKeyI9PHHashMapISB_Pc9HashCRC32ISB_EEEEEEEEEEvS3_ENKUlS3_E_clISE_EEDaS3_ Line | Count | Source | 385 | 3.38k | data.for_each_mapped([&](auto& mapped) { | 386 | 3.38k | if (mapped) { | 387 | 3.38k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 3.38k | mapped = nullptr; | 389 | 3.38k | } | 390 | 3.38k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIN4wide7integerILm256EjEENS6_15DataWithNullKeyI9PHHashMapISB_Pc9HashCRC32ISB_EEEEEEEEEEvS3_ENKUlS3_E_clISE_EEDaS3_ Line | Count | Source | 385 | 12 | data.for_each_mapped([&](auto& mapped) { | 386 | 12 | if (mapped) { | 387 | 12 | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 12 | mapped = nullptr; | 389 | 12 | } | 390 | 12 | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_19MethodStringNoCacheINS6_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEEEEEEvS3_ENKUlS3_E_clISB_EEDaS3_ Line | Count | Source | 385 | 20.9k | data.for_each_mapped([&](auto& mapped) { | 386 | 20.9k | if (mapped) { | 387 | 20.9k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 20.9k | mapped = nullptr; | 389 | 20.9k | } | 390 | 20.9k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS3_ENKUlS3_E_clIS9_EEDaS3_ Line | Count | Source | 385 | 155k | data.for_each_mapped([&](auto& mapped) { | 386 | 155k | if (mapped) { | 387 | 155k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 155k | mapped = nullptr; | 389 | 155k | } | 390 | 155k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32ISB_EEEEEEvS3_ENKUlS3_E_clISC_EEDaS3_ Line | Count | Source | 385 | 6.26M | data.for_each_mapped([&](auto& mapped) { | 386 | 6.26M | if (mapped) { | 387 | 6.26M | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 6.26M | mapped = nullptr; | 389 | 6.26M | } | 390 | 6.26M | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32ISB_EEEEEEvS3_ENKUlS3_E_clISC_EEDaS3_ Line | Count | Source | 385 | 36.8k | data.for_each_mapped([&](auto& mapped) { | 386 | 36.8k | if (mapped) { | 387 | 36.8k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 36.8k | mapped = nullptr; | 389 | 36.8k | } | 390 | 36.8k | }); |
_ZZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodKeysFixedI9PHHashMapINS6_7UInt136EPc9HashCRC32IS9_EEEEEEvS3_ENKUlS3_E_clISA_EEDaS3_ Line | Count | Source | 385 | 6.55k | data.for_each_mapped([&](auto& mapped) { | 386 | 6.55k | if (mapped) { | 387 | 6.55k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 6.55k | mapped = nullptr; | 389 | 6.55k | } | 390 | 6.55k | }); |
|
391 | 186k | if (data.has_null_key_data()) { |
392 | 4.66k | auto st = _destroy_agg_status( |
393 | 4.66k | data.template get_null_key_data< |
394 | 4.66k | vectorized::AggregateDataPtr>()); |
395 | 4.66k | if (!st) { |
396 | 0 | throw Exception(st.code(), st.to_string()); |
397 | 0 | } |
398 | 4.66k | } |
399 | 186k | }}, _ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS9_vEEEEEEvS3_ Line | Count | Source | 383 | 20.4k | [&](auto& agg_method) -> void { | 384 | 20.4k | auto& data = *agg_method.hash_table; | 385 | 20.4k | data.for_each_mapped([&](auto& mapped) { | 386 | 20.4k | if (mapped) { | 387 | 20.4k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 20.4k | mapped = nullptr; | 389 | 20.4k | } | 390 | 20.4k | }); | 391 | 20.4k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 20.4k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS3_ Line | Count | Source | 383 | 4.08k | [&](auto& agg_method) -> void { | 384 | 4.08k | auto& data = *agg_method.hash_table; | 385 | 4.08k | data.for_each_mapped([&](auto& mapped) { | 386 | 4.08k | if (mapped) { | 387 | 4.08k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 4.08k | mapped = nullptr; | 389 | 4.08k | } | 390 | 4.08k | }); | 391 | 4.08k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 4.08k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS3_ Line | Count | Source | 383 | 98 | [&](auto& agg_method) -> void { | 384 | 98 | auto& data = *agg_method.hash_table; | 385 | 98 | data.for_each_mapped([&](auto& mapped) { | 386 | 98 | if (mapped) { | 387 | 98 | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 98 | mapped = nullptr; | 389 | 98 | } | 390 | 98 | }); | 391 | 98 | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 98 | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS3_ Line | Count | Source | 383 | 10.4k | [&](auto& agg_method) -> void { | 384 | 10.4k | auto& data = *agg_method.hash_table; | 385 | 10.4k | data.for_each_mapped([&](auto& mapped) { | 386 | 10.4k | if (mapped) { | 387 | 10.4k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 10.4k | mapped = nullptr; | 389 | 10.4k | } | 390 | 10.4k | }); | 391 | 10.4k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 10.4k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS3_ Line | Count | Source | 383 | 768 | [&](auto& agg_method) -> void { | 384 | 768 | auto& data = *agg_method.hash_table; | 385 | 768 | data.for_each_mapped([&](auto& mapped) { | 386 | 768 | if (mapped) { | 387 | 768 | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 768 | mapped = nullptr; | 389 | 768 | } | 390 | 768 | }); | 391 | 768 | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 768 | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEEvS3_ Line | Count | Source | 383 | 2.16k | [&](auto& agg_method) -> void { | 384 | 2.16k | auto& data = *agg_method.hash_table; | 385 | 2.16k | data.for_each_mapped([&](auto& mapped) { | 386 | 2.16k | if (mapped) { | 387 | 2.16k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 2.16k | mapped = nullptr; | 389 | 2.16k | } | 390 | 2.16k | }); | 391 | 2.16k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 2.16k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapISA_Pc9HashCRC32ISA_EEEEEEvS3_ Line | Count | Source | 383 | 152 | [&](auto& agg_method) -> void { | 384 | 152 | auto& data = *agg_method.hash_table; | 385 | 152 | data.for_each_mapped([&](auto& mapped) { | 386 | 152 | if (mapped) { | 387 | 152 | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 152 | mapped = nullptr; | 389 | 152 | } | 390 | 152 | }); | 391 | 152 | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 152 | }}, |
Unexecuted instantiation: _ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapISA_Pc9HashCRC32ISA_EEEEEEvS3_ _ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS3_ Line | Count | Source | 383 | 6.32k | [&](auto& agg_method) -> void { | 384 | 6.32k | auto& data = *agg_method.hash_table; | 385 | 6.32k | data.for_each_mapped([&](auto& mapped) { | 386 | 6.32k | if (mapped) { | 387 | 6.32k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 6.32k | mapped = nullptr; | 389 | 6.32k | } | 390 | 6.32k | }); | 391 | 6.32k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 6.32k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS3_ Line | Count | Source | 383 | 1.61k | [&](auto& agg_method) -> void { | 384 | 1.61k | auto& data = *agg_method.hash_table; | 385 | 1.61k | data.for_each_mapped([&](auto& mapped) { | 386 | 1.61k | if (mapped) { | 387 | 1.61k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 1.61k | mapped = nullptr; | 389 | 1.61k | } | 390 | 1.61k | }); | 391 | 1.61k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 1.61k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIhNS6_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS3_ Line | Count | Source | 383 | 13.3k | [&](auto& agg_method) -> void { | 384 | 13.3k | auto& data = *agg_method.hash_table; | 385 | 13.3k | data.for_each_mapped([&](auto& mapped) { | 386 | 13.3k | if (mapped) { | 387 | 13.3k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 13.3k | mapped = nullptr; | 389 | 13.3k | } | 390 | 13.3k | }); | 391 | 13.3k | if (data.has_null_key_data()) { | 392 | 802 | auto st = _destroy_agg_status( | 393 | 802 | data.template get_null_key_data< | 394 | 802 | vectorized::AggregateDataPtr>()); | 395 | 802 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 802 | } | 399 | 13.3k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberItNS6_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS3_ Line | Count | Source | 383 | 1.54k | [&](auto& agg_method) -> void { | 384 | 1.54k | auto& data = *agg_method.hash_table; | 385 | 1.54k | data.for_each_mapped([&](auto& mapped) { | 386 | 1.54k | if (mapped) { | 387 | 1.54k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 1.54k | mapped = nullptr; | 389 | 1.54k | } | 390 | 1.54k | }); | 391 | 1.54k | if (data.has_null_key_data()) { | 392 | 70 | auto st = _destroy_agg_status( | 393 | 70 | data.template get_null_key_data< | 394 | 70 | vectorized::AggregateDataPtr>()); | 395 | 70 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 70 | } | 399 | 1.54k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIjNS6_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS3_ Line | Count | Source | 383 | 25.0k | [&](auto& agg_method) -> void { | 384 | 25.0k | auto& data = *agg_method.hash_table; | 385 | 25.0k | data.for_each_mapped([&](auto& mapped) { | 386 | 25.0k | if (mapped) { | 387 | 25.0k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 25.0k | mapped = nullptr; | 389 | 25.0k | } | 390 | 25.0k | }); | 391 | 25.0k | if (data.has_null_key_data()) { | 392 | 1.30k | auto st = _destroy_agg_status( | 393 | 1.30k | data.template get_null_key_data< | 394 | 1.30k | vectorized::AggregateDataPtr>()); | 395 | 1.30k | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 1.30k | } | 399 | 25.0k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberImNS6_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS3_ Line | Count | Source | 383 | 5.74k | [&](auto& agg_method) -> void { | 384 | 5.74k | auto& data = *agg_method.hash_table; | 385 | 5.74k | data.for_each_mapped([&](auto& mapped) { | 386 | 5.74k | if (mapped) { | 387 | 5.74k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 5.74k | mapped = nullptr; | 389 | 5.74k | } | 390 | 5.74k | }); | 391 | 5.74k | if (data.has_null_key_data()) { | 392 | 280 | auto st = _destroy_agg_status( | 393 | 280 | data.template get_null_key_data< | 394 | 280 | vectorized::AggregateDataPtr>()); | 395 | 280 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 280 | } | 399 | 5.74k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIjNS6_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS3_ Line | Count | Source | 383 | 19.6k | [&](auto& agg_method) -> void { | 384 | 19.6k | auto& data = *agg_method.hash_table; | 385 | 19.6k | data.for_each_mapped([&](auto& mapped) { | 386 | 19.6k | if (mapped) { | 387 | 19.6k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 19.6k | mapped = nullptr; | 389 | 19.6k | } | 390 | 19.6k | }); | 391 | 19.6k | if (data.has_null_key_data()) { | 392 | 858 | auto st = _destroy_agg_status( | 393 | 858 | data.template get_null_key_data< | 394 | 858 | vectorized::AggregateDataPtr>()); | 395 | 858 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 858 | } | 399 | 19.6k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberImNS6_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS3_ Line | Count | Source | 383 | 4.90k | [&](auto& agg_method) -> void { | 384 | 4.90k | auto& data = *agg_method.hash_table; | 385 | 4.90k | data.for_each_mapped([&](auto& mapped) { | 386 | 4.90k | if (mapped) { | 387 | 4.90k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 4.90k | mapped = nullptr; | 389 | 4.90k | } | 390 | 4.90k | }); | 391 | 4.90k | if (data.has_null_key_data()) { | 392 | 387 | auto st = _destroy_agg_status( | 393 | 387 | data.template get_null_key_data< | 394 | 387 | vectorized::AggregateDataPtr>()); | 395 | 387 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 387 | } | 399 | 4.90k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIN4wide7integerILm128EjEENS6_15DataWithNullKeyI9PHHashMapISB_Pc9HashCRC32ISB_EEEEEEEEEEvS3_ Line | Count | Source | 383 | 6.98k | [&](auto& agg_method) -> void { | 384 | 6.98k | auto& data = *agg_method.hash_table; | 385 | 6.98k | data.for_each_mapped([&](auto& mapped) { | 386 | 6.98k | if (mapped) { | 387 | 6.98k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 6.98k | mapped = nullptr; | 389 | 6.98k | } | 390 | 6.98k | }); | 391 | 6.98k | if (data.has_null_key_data()) { | 392 | 346 | auto st = _destroy_agg_status( | 393 | 346 | data.template get_null_key_data< | 394 | 346 | vectorized::AggregateDataPtr>()); | 395 | 346 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 346 | } | 399 | 6.98k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_15MethodOneNumberIN4wide7integerILm256EjEENS6_15DataWithNullKeyI9PHHashMapISB_Pc9HashCRC32ISB_EEEEEEEEEEvS3_ Line | Count | Source | 383 | 64 | [&](auto& agg_method) -> void { | 384 | 64 | auto& data = *agg_method.hash_table; | 385 | 64 | data.for_each_mapped([&](auto& mapped) { | 386 | 64 | if (mapped) { | 387 | 64 | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 64 | mapped = nullptr; | 389 | 64 | } | 390 | 64 | }); | 391 | 64 | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 64 | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized26MethodSingleNullableColumnINS6_19MethodStringNoCacheINS6_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorEEEEEEEEEEEEEvS3_ Line | Count | Source | 383 | 10.2k | [&](auto& agg_method) -> void { | 384 | 10.2k | auto& data = *agg_method.hash_table; | 385 | 10.2k | data.for_each_mapped([&](auto& mapped) { | 386 | 10.2k | if (mapped) { | 387 | 10.2k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 10.2k | mapped = nullptr; | 389 | 10.2k | } | 390 | 10.2k | }); | 391 | 10.2k | if (data.has_null_key_data()) { | 392 | 616 | auto st = _destroy_agg_status( | 393 | 616 | data.template get_null_key_data< | 394 | 616 | vectorized::AggregateDataPtr>()); | 395 | 616 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 616 | } | 399 | 10.2k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS3_ Line | Count | Source | 383 | 1.65k | [&](auto& agg_method) -> void { | 384 | 1.65k | auto& data = *agg_method.hash_table; | 385 | 1.65k | data.for_each_mapped([&](auto& mapped) { | 386 | 1.65k | if (mapped) { | 387 | 1.65k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 1.65k | mapped = nullptr; | 389 | 1.65k | } | 390 | 1.65k | }); | 391 | 1.65k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 1.65k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32ISB_EEEEEEvS3_ Line | Count | Source | 383 | 19.7k | [&](auto& agg_method) -> void { | 384 | 19.7k | auto& data = *agg_method.hash_table; | 385 | 19.7k | data.for_each_mapped([&](auto& mapped) { | 386 | 19.7k | if (mapped) { | 387 | 19.7k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 19.7k | mapped = nullptr; | 389 | 19.7k | } | 390 | 19.7k | }); | 391 | 19.7k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 19.7k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32ISB_EEEEEEvS3_ Line | Count | Source | 383 | 21.6k | [&](auto& agg_method) -> void { | 384 | 21.6k | auto& data = *agg_method.hash_table; | 385 | 21.6k | data.for_each_mapped([&](auto& mapped) { | 386 | 21.6k | if (mapped) { | 387 | 21.6k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 21.6k | mapped = nullptr; | 389 | 21.6k | } | 390 | 21.6k | }); | 391 | 21.6k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 21.6k | }}, |
_ZZN5doris8pipeline14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_10vectorized15MethodKeysFixedI9PHHashMapINS6_7UInt136EPc9HashCRC32IS9_EEEEEEvS3_ Line | Count | Source | 383 | 9.61k | [&](auto& agg_method) -> void { | 384 | 9.61k | auto& data = *agg_method.hash_table; | 385 | 9.61k | data.for_each_mapped([&](auto& mapped) { | 386 | 9.61k | if (mapped) { | 387 | 9.61k | static_cast<void>(_destroy_agg_status(mapped)); | 388 | 9.61k | mapped = nullptr; | 389 | 9.61k | } | 390 | 9.61k | }); | 391 | 9.61k | if (data.has_null_key_data()) { | 392 | 0 | auto st = _destroy_agg_status( | 393 | 0 | data.template get_null_key_data< | 394 | 0 | vectorized::AggregateDataPtr>()); | 395 | 0 | if (!st) { | 396 | 0 | throw Exception(st.code(), st.to_string()); | 397 | 0 | } | 398 | 0 | } | 399 | 9.61k | }}, |
|
400 | 186k | agg_data->method_variant); |
401 | 186k | } |
402 | | |
403 | 161k | void _close_without_key() { |
404 | | //because prepare maybe failed, and couldn't create agg data. |
405 | | //but finally call close to destory agg data, if agg data has bitmapValue |
406 | | //will be core dump, it's not initialized |
407 | 161k | if (agg_data_created_without_key) { |
408 | 161k | static_cast<void>(_destroy_agg_status(agg_data->without_key)); |
409 | 161k | agg_data_created_without_key = false; |
410 | 161k | } |
411 | 161k | } |
412 | | Status _destroy_agg_status(vectorized::AggregateDataPtr data); |
413 | | }; |
414 | | |
415 | | struct BasicSpillSharedState { |
416 | 459k | virtual ~BasicSpillSharedState() = default; |
417 | | |
418 | | // These two counters are shared to spill source operators as the initial value |
419 | | // of 'SpillWriteFileCurrentBytes' and 'SpillWriteFileCurrentCount'. |
420 | | // Total bytes of spill data written to disk file(after serialized) |
421 | | RuntimeProfile::Counter* _spill_write_file_total_size = nullptr; |
422 | | RuntimeProfile::Counter* _spill_file_total_count = nullptr; |
423 | | |
424 | 458k | void setup_shared_profile(RuntimeProfile* sink_profile) { |
425 | 458k | _spill_file_total_count = |
426 | 458k | ADD_COUNTER_WITH_LEVEL(sink_profile, "SpillWriteFileTotalCount", TUnit::UNIT, 1); |
427 | 458k | _spill_write_file_total_size = |
428 | 458k | ADD_COUNTER_WITH_LEVEL(sink_profile, "SpillWriteFileBytes", TUnit::BYTES, 1); |
429 | 458k | } |
430 | | |
431 | | virtual void update_spill_stream_profiles(RuntimeProfile* source_profile) = 0; |
432 | | }; |
433 | | |
434 | | struct AggSpillPartition; |
435 | | struct PartitionedAggSharedState : public BasicSharedState, |
436 | | public BasicSpillSharedState, |
437 | | public std::enable_shared_from_this<PartitionedAggSharedState> { |
438 | | ENABLE_FACTORY_CREATOR(PartitionedAggSharedState) |
439 | | |
440 | 156k | PartitionedAggSharedState() = default; |
441 | 157k | ~PartitionedAggSharedState() override = default; |
442 | | |
443 | | void update_spill_stream_profiles(RuntimeProfile* source_profile) override; |
444 | | |
445 | | void init_spill_params(size_t spill_partition_count); |
446 | | |
447 | | void close(); |
448 | | |
449 | | AggSharedState* in_mem_shared_state = nullptr; |
450 | | std::shared_ptr<BasicSharedState> in_mem_shared_state_sptr; |
451 | | |
452 | | size_t partition_count; |
453 | | size_t max_partition_index; |
454 | | bool is_spilled = false; |
455 | | std::atomic_bool is_closed = false; |
456 | | std::deque<std::shared_ptr<AggSpillPartition>> spill_partitions; |
457 | | |
458 | 2.80M | size_t get_partition_index(size_t hash_value) const { return hash_value % partition_count; } |
459 | | }; |
460 | | |
461 | | struct AggSpillPartition { |
462 | | static constexpr int64_t AGG_SPILL_FILE_SIZE = 1024 * 1024 * 1024; // 1G |
463 | | |
464 | 5.02M | AggSpillPartition() = default; |
465 | | |
466 | | void close(); |
467 | | |
468 | | Status get_spill_stream(RuntimeState* state, int node_id, RuntimeProfile* profile, |
469 | | vectorized::SpillStreamSPtr& spilling_stream); |
470 | | |
471 | 206k | Status flush_if_full() { |
472 | 206k | DCHECK(spilling_stream_); |
473 | 206k | Status status; |
474 | | // avoid small spill files |
475 | 206k | if (spilling_stream_->get_written_bytes() >= AGG_SPILL_FILE_SIZE) { |
476 | 0 | status = spilling_stream_->spill_eof(); |
477 | 0 | spilling_stream_.reset(); |
478 | 0 | } |
479 | 206k | return status; |
480 | 206k | } |
481 | | |
482 | 1.22M | Status finish_current_spilling(bool eos = false) { |
483 | 1.22M | if (spilling_stream_) { |
484 | 273k | if (eos || spilling_stream_->get_written_bytes() >= AGG_SPILL_FILE_SIZE) { |
485 | 49.6k | auto status = spilling_stream_->spill_eof(); |
486 | 49.6k | spilling_stream_.reset(); |
487 | 49.6k | return status; |
488 | 49.6k | } |
489 | 273k | } |
490 | 1.17M | return Status::OK(); |
491 | 1.22M | } |
492 | | |
493 | | std::deque<vectorized::SpillStreamSPtr> spill_streams_; |
494 | | vectorized::SpillStreamSPtr spilling_stream_; |
495 | | }; |
496 | | using AggSpillPartitionSPtr = std::shared_ptr<AggSpillPartition>; |
497 | | struct SortSharedState : public BasicSharedState { |
498 | | ENABLE_FACTORY_CREATOR(SortSharedState) |
499 | | public: |
500 | | std::shared_ptr<vectorized::Sorter> sorter; |
501 | | }; |
502 | | |
503 | | struct SpillSortSharedState : public BasicSharedState, |
504 | | public BasicSpillSharedState, |
505 | | public std::enable_shared_from_this<SpillSortSharedState> { |
506 | | ENABLE_FACTORY_CREATOR(SpillSortSharedState) |
507 | | |
508 | 257k | SpillSortSharedState() = default; |
509 | 256k | ~SpillSortSharedState() override = default; |
510 | | |
511 | 189k | void update_spill_block_batch_row_count(RuntimeState* state, const vectorized::Block* block) { |
512 | 189k | auto rows = block->rows(); |
513 | 189k | if (rows > 0 && 0 == avg_row_bytes) { |
514 | 121k | avg_row_bytes = std::max((std::size_t)1, block->bytes() / rows); |
515 | 121k | spill_block_batch_row_count = |
516 | 121k | (state->spill_sort_batch_bytes() + avg_row_bytes - 1) / avg_row_bytes; |
517 | 121k | LOG(INFO) << "spill sort block batch row count: " << spill_block_batch_row_count; |
518 | 121k | } |
519 | 189k | } |
520 | | |
521 | | void update_spill_stream_profiles(RuntimeProfile* source_profile) override; |
522 | | |
523 | | void close(); |
524 | | |
525 | | SortSharedState* in_mem_shared_state = nullptr; |
526 | | bool enable_spill = false; |
527 | | bool is_spilled = false; |
528 | | std::atomic_bool is_closed = false; |
529 | | std::shared_ptr<BasicSharedState> in_mem_shared_state_sptr; |
530 | | |
531 | | std::deque<vectorized::SpillStreamSPtr> sorted_streams; |
532 | | size_t avg_row_bytes = 0; |
533 | | size_t spill_block_batch_row_count; |
534 | | }; |
535 | | |
536 | | struct UnionSharedState : public BasicSharedState { |
537 | | ENABLE_FACTORY_CREATOR(UnionSharedState) |
538 | | |
539 | | public: |
540 | 5.20k | UnionSharedState(int child_count = 1) : data_queue(child_count), _child_count(child_count) {}; |
541 | 0 | int child_count() const { return _child_count; } |
542 | | DataQueue data_queue; |
543 | | const int _child_count; |
544 | | }; |
545 | | |
546 | | struct CacheSharedState : public BasicSharedState { |
547 | | ENABLE_FACTORY_CREATOR(CacheSharedState) |
548 | | public: |
549 | | DataQueue data_queue; |
550 | | }; |
551 | | |
552 | | class MultiCastDataStreamer; |
553 | | |
554 | | struct MultiCastSharedState : public BasicSharedState, |
555 | | public BasicSpillSharedState, |
556 | | public std::enable_shared_from_this<MultiCastSharedState> { |
557 | | MultiCastSharedState(ObjectPool* pool, int cast_sender_count, int node_id); |
558 | | std::unique_ptr<pipeline::MultiCastDataStreamer> multi_cast_data_streamer; |
559 | | |
560 | | void update_spill_stream_profiles(RuntimeProfile* source_profile) override; |
561 | | }; |
562 | | |
563 | | struct AnalyticSharedState : public BasicSharedState { |
564 | | ENABLE_FACTORY_CREATOR(AnalyticSharedState) |
565 | | |
566 | | public: |
567 | 22.6k | AnalyticSharedState() = default; |
568 | | std::queue<vectorized::Block> blocks_buffer; |
569 | | std::mutex buffer_mutex; |
570 | | bool sink_eos = false; |
571 | | std::mutex sink_eos_lock; |
572 | | }; |
573 | | |
574 | | struct JoinSharedState : public BasicSharedState { |
575 | | // For some join case, we can apply a short circuit strategy |
576 | | // 1. _has_null_in_build_side = true |
577 | | // 2. build side rows is empty, Join op is: inner join/right outer join/left semi/right semi/right anti |
578 | | bool _has_null_in_build_side = false; |
579 | | bool short_circuit_for_probe = false; |
580 | | // for some join, when build side rows is empty, we could return directly by add some additional null data in probe table. |
581 | | bool empty_right_table_need_probe_dispose = false; |
582 | | JoinOpVariants join_op_variants; |
583 | | }; |
584 | | |
585 | | struct HashJoinSharedState : public JoinSharedState { |
586 | | ENABLE_FACTORY_CREATOR(HashJoinSharedState) |
587 | 197k | HashJoinSharedState() { |
588 | 197k | hash_table_variant_vector.push_back(std::make_shared<JoinDataVariants>()); |
589 | 197k | } |
590 | 10.1k | HashJoinSharedState(int num_instances) { |
591 | 10.1k | source_deps.resize(num_instances, nullptr); |
592 | 10.1k | hash_table_variant_vector.resize(num_instances, nullptr); |
593 | 46.9k | for (int i = 0; i < num_instances; i++) { |
594 | 36.8k | hash_table_variant_vector[i] = std::make_shared<JoinDataVariants>(); |
595 | 36.8k | } |
596 | 10.1k | } |
597 | | std::shared_ptr<vectorized::Arena> arena = std::make_shared<vectorized::Arena>(); |
598 | | |
599 | | const std::vector<TupleDescriptor*> build_side_child_desc; |
600 | | size_t build_exprs_size = 0; |
601 | | std::shared_ptr<vectorized::Block> build_block; |
602 | | std::shared_ptr<std::vector<uint32_t>> build_indexes_null; |
603 | | |
604 | | // Used by shared hash table |
605 | | // For probe operator, hash table in _hash_table_variants is read-only if visited flags is not |
606 | | // used. (visited flags will be used only in right / full outer join). |
607 | | // |
608 | | // For broadcast join, although hash table is read-only, some states in `_hash_table_variants` |
609 | | // are still could be written. For example, serialized keys will be written in a continuous |
610 | | // memory in `_hash_table_variants`. So before execution, we should use a local _hash_table_variants |
611 | | // which has a shared hash table in it. |
612 | | std::vector<std::shared_ptr<JoinDataVariants>> hash_table_variant_vector; |
613 | | }; |
614 | | |
615 | | struct PartitionedHashJoinSharedState |
616 | | : public HashJoinSharedState, |
617 | | public BasicSpillSharedState, |
618 | | public std::enable_shared_from_this<PartitionedHashJoinSharedState> { |
619 | | ENABLE_FACTORY_CREATOR(PartitionedHashJoinSharedState) |
620 | | |
621 | 41.8k | void update_spill_stream_profiles(RuntimeProfile* source_profile) override { |
622 | 1.33M | for (auto& stream : spilled_streams) { |
623 | 1.33M | if (stream) { |
624 | 1.33M | stream->update_shared_profiles(source_profile); |
625 | 1.33M | } |
626 | 1.33M | } |
627 | 41.8k | } |
628 | | |
629 | | std::unique_ptr<RuntimeState> inner_runtime_state; |
630 | | std::shared_ptr<HashJoinSharedState> inner_shared_state; |
631 | | std::vector<std::unique_ptr<vectorized::MutableBlock>> partitioned_build_blocks; |
632 | | std::vector<vectorized::SpillStreamSPtr> spilled_streams; |
633 | | bool need_to_spill = false; |
634 | | }; |
635 | | |
636 | | struct NestedLoopJoinSharedState : public JoinSharedState { |
637 | | ENABLE_FACTORY_CREATOR(NestedLoopJoinSharedState) |
638 | | // if true, left child has no more rows to process |
639 | | bool left_side_eos = false; |
640 | | // Visited flags for each row in build side. |
641 | | vectorized::MutableColumns build_side_visited_flags; |
642 | | // List of build blocks, constructed in prepare() |
643 | | vectorized::Blocks build_blocks; |
644 | | }; |
645 | | |
646 | | struct PartitionSortNodeSharedState : public BasicSharedState { |
647 | | ENABLE_FACTORY_CREATOR(PartitionSortNodeSharedState) |
648 | | public: |
649 | | std::queue<vectorized::Block> blocks_buffer; |
650 | | std::mutex buffer_mutex; |
651 | | std::vector<std::unique_ptr<vectorized::PartitionSorter>> partition_sorts; |
652 | | bool sink_eos = false; |
653 | | std::mutex sink_eos_lock; |
654 | | std::mutex prepared_finish_lock; |
655 | | }; |
656 | | |
657 | | struct SetSharedState : public BasicSharedState { |
658 | | ENABLE_FACTORY_CREATOR(SetSharedState) |
659 | | public: |
660 | | /// default init |
661 | | vectorized::Block build_block; // build to source |
662 | | //record element size in hashtable |
663 | | int64_t valid_element_in_hash_tbl = 0; |
664 | | //first: idx mapped to column types |
665 | | //second: column_id, could point to origin column or cast column |
666 | | std::unordered_map<int, int> build_col_idx; |
667 | | |
668 | | //// shared static states (shared, decided in prepare/open...) |
669 | | |
670 | | /// init in setup_local_state |
671 | | std::unique_ptr<SetDataVariants> hash_table_variants = |
672 | | std::make_unique<SetDataVariants>(); // the real data HERE. |
673 | | std::vector<bool> build_not_ignore_null; |
674 | | |
675 | | // The SET operator's child might have different nullable attributes. |
676 | | // If a calculation involves both nullable and non-nullable columns, the final output should be a nullable column |
677 | | Status update_build_not_ignore_null(const vectorized::VExprContextSPtrs& ctxs); |
678 | | |
679 | | size_t get_hash_table_size() const; |
680 | | /// init in both upstream side. |
681 | | //The i-th result expr list refers to the i-th child. |
682 | | std::vector<vectorized::VExprContextSPtrs> child_exprs_lists; |
683 | | |
684 | | /// init in build side |
685 | | size_t child_quantity; |
686 | | vectorized::VExprContextSPtrs build_child_exprs; |
687 | | std::vector<Dependency*> probe_finished_children_dependency; |
688 | | |
689 | | /// init in probe side |
690 | | std::vector<vectorized::VExprContextSPtrs> probe_child_exprs_lists; |
691 | | |
692 | | std::atomic<bool> ready_for_read = false; |
693 | | |
694 | | /// called in setup_local_state |
695 | | Status hash_table_init(); |
696 | | }; |
697 | | |
698 | | enum class ExchangeType : uint8_t { |
699 | | NOOP = 0, |
700 | | // Shuffle data by Crc32HashPartitioner<LocalExchangeChannelIds>. |
701 | | HASH_SHUFFLE = 1, |
702 | | // Round-robin passthrough data blocks. |
703 | | PASSTHROUGH = 2, |
704 | | // Shuffle data by Crc32HashPartitioner<ShuffleChannelIds> (e.g. same as storage engine). |
705 | | BUCKET_HASH_SHUFFLE = 3, |
706 | | // Passthrough data blocks to all channels. |
707 | | BROADCAST = 4, |
708 | | // Passthrough data to channels evenly in an adaptive way. |
709 | | ADAPTIVE_PASSTHROUGH = 5, |
710 | | // Send all data to the first channel. |
711 | | PASS_TO_ONE = 6, |
712 | | }; |
713 | | |
714 | 255k | inline std::string get_exchange_type_name(ExchangeType idx) { |
715 | 255k | switch (idx) { |
716 | 13 | case ExchangeType::NOOP: |
717 | 13 | return "NOOP"; |
718 | 9.50k | case ExchangeType::HASH_SHUFFLE: |
719 | 9.50k | return "HASH_SHUFFLE"; |
720 | 226k | case ExchangeType::PASSTHROUGH: |
721 | 226k | return "PASSTHROUGH"; |
722 | 7.21k | case ExchangeType::BUCKET_HASH_SHUFFLE: |
723 | 7.21k | return "BUCKET_HASH_SHUFFLE"; |
724 | 916 | case ExchangeType::BROADCAST: |
725 | 916 | return "BROADCAST"; |
726 | 5.15k | case ExchangeType::ADAPTIVE_PASSTHROUGH: |
727 | 5.15k | return "ADAPTIVE_PASSTHROUGH"; |
728 | 6.59k | case ExchangeType::PASS_TO_ONE: |
729 | 6.59k | return "PASS_TO_ONE"; |
730 | 255k | } |
731 | 0 | throw Exception(Status::FatalError("__builtin_unreachable")); |
732 | 255k | } |
733 | | |
734 | | struct DataDistribution { |
735 | 3.81M | DataDistribution(ExchangeType type) : distribution_type(type) {} |
736 | | DataDistribution(ExchangeType type, const std::vector<TExpr>& partition_exprs_) |
737 | 152k | : distribution_type(type), partition_exprs(partition_exprs_) {} |
738 | 282k | DataDistribution(const DataDistribution& other) = default; |
739 | 1.06M | bool need_local_exchange() const { return distribution_type != ExchangeType::NOOP; } |
740 | 1.20M | DataDistribution& operator=(const DataDistribution& other) = default; |
741 | | ExchangeType distribution_type; |
742 | | std::vector<TExpr> partition_exprs; |
743 | | }; |
744 | | |
745 | | class ExchangerBase; |
746 | | |
747 | | struct LocalExchangeSharedState : public BasicSharedState { |
748 | | public: |
749 | | ENABLE_FACTORY_CREATOR(LocalExchangeSharedState); |
750 | | LocalExchangeSharedState(int num_instances); |
751 | | ~LocalExchangeSharedState() override; |
752 | | std::unique_ptr<ExchangerBase> exchanger {}; |
753 | | std::vector<RuntimeProfile::Counter*> mem_counters; |
754 | | std::atomic<int64_t> mem_usage = 0; |
755 | | std::atomic<size_t> _buffer_mem_limit = config::local_exchange_buffer_mem_limit; |
756 | | // 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. |
757 | | std::mutex le_lock; |
758 | | void sub_running_sink_operators(); |
759 | | void sub_running_source_operators(); |
760 | 255k | void _set_always_ready() { |
761 | 1.76M | for (auto& dep : source_deps) { |
762 | 1.76M | DCHECK(dep); |
763 | 1.76M | dep->set_always_ready(); |
764 | 1.76M | } |
765 | 255k | for (auto& dep : sink_deps) { |
766 | 255k | DCHECK(dep); |
767 | 255k | dep->set_always_ready(); |
768 | 255k | } |
769 | 255k | } |
770 | | |
771 | 365k | Dependency* get_sink_dep_by_channel_id(int channel_id) { return nullptr; } |
772 | | |
773 | 696k | void set_ready_to_read(int channel_id) { |
774 | 696k | auto& dep = source_deps[channel_id]; |
775 | 18.4E | DCHECK(dep) << channel_id; |
776 | 696k | dep->set_ready(); |
777 | 696k | } |
778 | | |
779 | 696k | void add_mem_usage(int channel_id, size_t delta) { mem_counters[channel_id]->update(delta); } |
780 | | |
781 | 696k | void sub_mem_usage(int channel_id, size_t delta) { |
782 | 696k | mem_counters[channel_id]->update(-(int64_t)delta); |
783 | 696k | } |
784 | | |
785 | 571k | void add_total_mem_usage(size_t delta) { |
786 | 571k | if (cast_set<int64_t>(mem_usage.fetch_add(delta) + delta) > _buffer_mem_limit) { |
787 | 459 | sink_deps.front()->block(); |
788 | 459 | } |
789 | 571k | } |
790 | | |
791 | 571k | void sub_total_mem_usage(size_t delta) { |
792 | 571k | auto prev_usage = mem_usage.fetch_sub(delta); |
793 | 571k | DCHECK_GE(prev_usage - delta, 0) << "prev_usage: " << prev_usage << " delta: " << delta; |
794 | 571k | if (cast_set<int64_t>(prev_usage - delta) <= _buffer_mem_limit) { |
795 | 571k | sink_deps.front()->set_ready(); |
796 | 571k | } |
797 | 571k | } |
798 | | |
799 | 99.4k | void set_low_memory_mode(RuntimeState* state) { |
800 | 99.4k | _buffer_mem_limit = std::min<int64_t>(config::local_exchange_buffer_mem_limit, |
801 | 99.4k | state->low_memory_mode_buffer_limit()); |
802 | 99.4k | } |
803 | | }; |
804 | | |
805 | | #include "common/compile_check_end.h" |
806 | | } // namespace doris::pipeline |