Coverage Report

Created: 2026-08-06 13:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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/Partitions_types.h>
27
#include <gen_cpp/internal_service.pb.h>
28
#include <sqltypes.h>
29
30
#include <atomic>
31
#include <condition_variable>
32
#include <functional>
33
#include <memory>
34
#include <mutex>
35
#include <thread>
36
#include <utility>
37
38
#include "common/config.h"
39
#include "common/logging.h"
40
#include "common/thread_safety_annotations.h"
41
#include "core/block/block.h"
42
#include "core/types.h"
43
#include "exec/common/agg_utils.h"
44
#include "exec/common/join_utils.h"
45
#include "exec/common/set_utils.h"
46
#include "exec/operator/data_queue.h"
47
#include "exec/operator/join/process_hash_table_probe.h"
48
#include "exec/sort/partition_sorter.h"
49
#include "exec/sort/sorter.h"
50
#include "exec/spill/spill_file.h"
51
#include "runtime/runtime_profile_counter_names.h"
52
#include "util/brpc_closure.h"
53
#include "util/stack_util.h"
54
55
namespace doris {
56
class AggFnEvaluator;
57
class VSlotRef;
58
} // namespace doris
59
60
namespace doris {
61
class Dependency;
62
class PipelineTask;
63
struct BasicSharedState;
64
using DependencySPtr = std::shared_ptr<Dependency>;
65
class LocalExchangeSourceLocalState;
66
67
static constexpr auto SLOW_DEPENDENCY_THRESHOLD = 60 * 1000L * 1000L * 1000L;
68
static constexpr auto TIME_UNIT_DEPENDENCY_LOG = 30 * 1000L * 1000L * 1000L;
69
static_assert(TIME_UNIT_DEPENDENCY_LOG < SLOW_DEPENDENCY_THRESHOLD);
70
71
struct BasicSharedState {
72
    ENABLE_FACTORY_CREATOR(BasicSharedState)
73
74
    template <class TARGET>
75
2.76M
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
2.76M
        return reinterpret_cast<TARGET*>(this);
80
2.76M
    }
_ZN5doris16BasicSharedState4castINS_19HashJoinSharedStateEEEPT_v
Line
Count
Source
75
183k
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
183k
        return reinterpret_cast<TARGET*>(this);
80
183k
    }
_ZN5doris16BasicSharedState4castINS_30PartitionedHashJoinSharedStateEEEPT_v
Line
Count
Source
75
3
    TARGET* cast() {
76
3
        DCHECK(dynamic_cast<TARGET*>(this))
77
0
                << " Mismatch type! Current type is " << typeid(*this).name()
78
0
                << " and expect type is" << typeid(TARGET).name();
79
3
        return reinterpret_cast<TARGET*>(this);
80
3
    }
_ZN5doris16BasicSharedState4castINS_15SortSharedStateEEEPT_v
Line
Count
Source
75
538k
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
538k
        return reinterpret_cast<TARGET*>(this);
80
538k
    }
_ZN5doris16BasicSharedState4castINS_20SpillSortSharedStateEEEPT_v
Line
Count
Source
75
49
    TARGET* cast() {
76
49
        DCHECK(dynamic_cast<TARGET*>(this))
77
0
                << " Mismatch type! Current type is " << typeid(*this).name()
78
0
                << " and expect type is" << typeid(TARGET).name();
79
49
        return reinterpret_cast<TARGET*>(this);
80
49
    }
_ZN5doris16BasicSharedState4castINS_25NestedLoopJoinSharedStateEEEPT_v
Line
Count
Source
75
18.1k
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
18.1k
        return reinterpret_cast<TARGET*>(this);
80
18.1k
    }
_ZN5doris16BasicSharedState4castINS_19AnalyticSharedStateEEEPT_v
Line
Count
Source
75
12.9k
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
12.9k
        return reinterpret_cast<TARGET*>(this);
80
12.9k
    }
_ZN5doris16BasicSharedState4castINS_14AggSharedStateEEEPT_v
Line
Count
Source
75
318k
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
318k
        return reinterpret_cast<TARGET*>(this);
80
318k
    }
_ZN5doris16BasicSharedState4castINS_22BucketedAggSharedStateEEEPT_v
Line
Count
Source
75
888
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
888
        return reinterpret_cast<TARGET*>(this);
80
888
    }
_ZN5doris16BasicSharedState4castINS_25PartitionedAggSharedStateEEEPT_v
Line
Count
Source
75
166
    TARGET* cast() {
76
166
        DCHECK(dynamic_cast<TARGET*>(this))
77
0
                << " Mismatch type! Current type is " << typeid(*this).name()
78
0
                << " and expect type is" << typeid(TARGET).name();
79
166
        return reinterpret_cast<TARGET*>(this);
80
166
    }
_ZN5doris16BasicSharedState4castINS_16UnionSharedStateEEEPT_v
Line
Count
Source
75
8.86k
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
8.86k
        return reinterpret_cast<TARGET*>(this);
80
8.86k
    }
_ZN5doris16BasicSharedState4castINS_28PartitionSortNodeSharedStateEEEPT_v
Line
Count
Source
75
716
    TARGET* cast() {
76
716
        DCHECK(dynamic_cast<TARGET*>(this))
77
0
                << " Mismatch type! Current type is " << typeid(*this).name()
78
0
                << " and expect type is" << typeid(TARGET).name();
79
716
        return reinterpret_cast<TARGET*>(this);
80
716
    }
_ZN5doris16BasicSharedState4castINS_20MultiCastSharedStateEEEPT_v
Line
Count
Source
75
15.0k
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
15.0k
        return reinterpret_cast<TARGET*>(this);
80
15.0k
    }
_ZN5doris16BasicSharedState4castINS_14SetSharedStateEEEPT_v
Line
Count
Source
75
18.0k
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
18.0k
        return reinterpret_cast<TARGET*>(this);
80
18.0k
    }
_ZN5doris16BasicSharedState4castINS_24LocalExchangeSharedStateEEEPT_v
Line
Count
Source
75
1.12M
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
1.12M
        return reinterpret_cast<TARGET*>(this);
80
1.12M
    }
_ZN5doris16BasicSharedState4castIS0_EEPT_v
Line
Count
Source
75
525k
    TARGET* cast() {
76
18.4E
        DCHECK(dynamic_cast<TARGET*>(this))
77
18.4E
                << " Mismatch type! Current type is " << typeid(*this).name()
78
18.4E
                << " and expect type is" << typeid(TARGET).name();
79
525k
        return reinterpret_cast<TARGET*>(this);
80
525k
    }
_ZN5doris16BasicSharedState4castINS_20DataQueueSharedStateEEEPT_v
Line
Count
Source
75
51
    TARGET* cast() {
76
51
        DCHECK(dynamic_cast<TARGET*>(this))
77
0
                << " Mismatch type! Current type is " << typeid(*this).name()
78
0
                << " and expect type is" << typeid(TARGET).name();
79
51
        return reinterpret_cast<TARGET*>(this);
80
51
    }
_ZN5doris16BasicSharedState4castINS_17RecCTESharedStateEEEPT_v
Line
Count
Source
75
492
    TARGET* cast() {
76
492
        DCHECK(dynamic_cast<TARGET*>(this))
77
0
                << " Mismatch type! Current type is " << typeid(*this).name()
78
0
                << " and expect type is" << typeid(TARGET).name();
79
492
        return reinterpret_cast<TARGET*>(this);
80
492
    }
81
    template <class TARGET>
82
    const TARGET* cast() const {
83
        DCHECK(dynamic_cast<const TARGET*>(this))
84
                << " Mismatch type! Current type is " << typeid(*this).name()
85
                << " and expect type is" << typeid(TARGET).name();
86
        return reinterpret_cast<const TARGET*>(this);
87
    }
88
    std::vector<DependencySPtr> source_deps;
89
    std::vector<DependencySPtr> sink_deps;
90
    int id = 0;
91
    std::set<int> related_op_ids;
92
93
1.93M
    virtual ~BasicSharedState() = default;
94
95
    void create_source_dependencies(int num_sources, int operator_id, int node_id,
96
                                    const std::string& name);
97
    Dependency* create_source_dependency(int operator_id, int node_id, const std::string& name);
98
99
    Dependency* create_sink_dependency(int dest_id, int node_id, const std::string& name);
100
817k
    std::vector<DependencySPtr> get_dep_by_channel_id(int channel_id) {
101
817k
        DCHECK_LT(channel_id, source_deps.size());
102
817k
        return {source_deps[channel_id]};
103
817k
    }
104
};
105
106
class Dependency : public std::enable_shared_from_this<Dependency> {
107
public:
108
    ENABLE_FACTORY_CREATOR(Dependency);
109
    Dependency(int id, int node_id, std::string name, bool ready = false)
110
6.88M
            : _id(id), _node_id(node_id), _name(std::move(name)), _ready(ready) {}
111
6.90M
    virtual ~Dependency() = default;
112
113
0
    [[nodiscard]] int id() const { return _id; }
114
8.92M
    [[nodiscard]] virtual std::string name() const { return _name; }
115
345k
    BasicSharedState* shared_state() { return _shared_state; }
116
2.62M
    void set_shared_state(BasicSharedState* shared_state) { _shared_state = shared_state; }
117
    virtual std::string debug_string(int indentation_level = 0);
118
1.04G
    bool ready() const { return _ready; }
119
120
    // Start the watcher. We use it to count how long this dependency block the current pipeline task.
121
5.67M
    void start_watcher() { _watcher.start(); }
122
8.43M
    [[nodiscard]] int64_t watcher_elapse_time() { return _watcher.elapsed_time(); }
123
124
    // Which dependency current pipeline task is blocked by. `nullptr` if this dependency is ready.
125
    [[nodiscard]] Dependency* is_blocked_by(std::shared_ptr<PipelineTask> task = nullptr);
126
    // Notify downstream pipeline tasks this dependency is ready.
127
    void set_ready();
128
552k
    void set_ready_to_read(int channel_id = 0) {
129
552k
        DCHECK_LT(channel_id, _shared_state->source_deps.size()) << debug_string();
130
552k
        _shared_state->source_deps[channel_id]->set_ready();
131
552k
    }
132
1.10k
    void set_ready_to_write() {
133
1.10k
        DCHECK_EQ(_shared_state->sink_deps.size(), 1) << debug_string();
134
1.10k
        _shared_state->sink_deps.front()->set_ready();
135
1.10k
    }
136
137
    // Notify downstream pipeline tasks this dependency is blocked.
138
2.04M
    void block() {
139
2.04M
        if (_always_ready) {
140
332k
            return;
141
332k
        }
142
1.70M
        std::unique_lock<std::mutex> lc(_always_ready_lock);
143
1.70M
        if (_always_ready) {
144
4
            return;
145
4
        }
146
1.70M
        _ready = false;
147
1.70M
    }
148
149
4.69M
    void set_always_ready() {
150
4.69M
        if (_always_ready) {
151
1.99M
            return;
152
1.99M
        }
153
2.70M
        std::unique_lock<std::mutex> lc(_always_ready_lock);
154
2.70M
        if (_always_ready) {
155
0
            return;
156
0
        }
157
2.70M
        _always_ready = true;
158
2.70M
        set_ready();
159
2.70M
    }
160
161
protected:
162
    void _add_block_task(std::shared_ptr<PipelineTask> task);
163
164
    const int _id;
165
    const int _node_id;
166
    const std::string _name;
167
    std::atomic<bool> _ready;
168
169
    BasicSharedState* _shared_state = nullptr;
170
    MonotonicStopWatch _watcher;
171
172
    std::mutex _task_lock;
173
    std::vector<std::weak_ptr<PipelineTask>> _blocked_task;
174
175
    // If `_always_ready` is true, `block()` will never block tasks.
176
    std::atomic<bool> _always_ready = false;
177
    std::mutex _always_ready_lock;
178
};
179
180
struct FakeSharedState final : public BasicSharedState {
181
    ENABLE_FACTORY_CREATOR(FakeSharedState)
182
};
183
184
class CountedFinishDependency final : public Dependency {
185
public:
186
    using SharedState = FakeSharedState;
187
    CountedFinishDependency(int id, int node_id, std::string name)
188
145k
            : Dependency(id, node_id, std::move(name), true) {}
189
190
3.00k
    void add(uint32_t count = 1) {
191
3.00k
        std::unique_lock<std::mutex> l(_mtx);
192
3.00k
        if (!_counter) {
193
3.00k
            block();
194
3.00k
        }
195
3.00k
        _counter += count;
196
3.00k
    }
197
198
3.00k
    void sub() {
199
3.00k
        std::unique_lock<std::mutex> l(_mtx);
200
        // _counter is unsigned: a stray sub() when counter is already 0 would
201
        // underflow to UINT32_MAX and the dependency would never become ready,
202
        // hanging the query forever. Fail loudly instead.
203
3.00k
        if (_counter == 0) [[unlikely]] {
204
2
            throw Exception(ErrorCode::INTERNAL_ERROR,
205
2
                            "CountedFinishDependency::sub() underflow on {}", debug_string());
206
2
        }
207
3.00k
        _counter--;
208
3.00k
        if (!_counter) {
209
3.00k
            set_ready();
210
3.00k
        }
211
3.00k
    }
212
213
    std::string debug_string(int indentation_level = 0) override;
214
215
private:
216
    std::mutex _mtx;
217
    uint32_t _counter = 0;
218
};
219
220
struct RuntimeFilterTimerQueue;
221
class RuntimeFilterTimer {
222
public:
223
    RuntimeFilterTimer(int64_t registration_time, int32_t wait_time_ms,
224
                       std::shared_ptr<Dependency> parent, bool force_wait_timeout = false)
225
16.5k
            : _parent(std::move(parent)),
226
16.5k
              _registration_time(registration_time),
227
16.5k
              _wait_time_ms(wait_time_ms),
228
16.5k
              _force_wait_timeout(force_wait_timeout) {}
229
230
    // Called by runtime filter producer.
231
    void call_ready();
232
233
    // Called by RuntimeFilterTimerQueue which is responsible for checking if this rf is timeout.
234
    void call_timeout();
235
236
781k
    int64_t registration_time() const { return _registration_time; }
237
781k
    int32_t wait_time_ms() const { return _wait_time_ms; }
238
239
    void set_local_runtime_filter_dependencies(
240
5.89k
            const std::vector<std::shared_ptr<Dependency>>& deps) {
241
5.89k
        _local_runtime_filter_dependencies = deps;
242
5.89k
    }
243
244
    bool should_be_check_timeout();
245
246
797k
    bool force_wait_timeout() { return _force_wait_timeout; }
247
248
private:
249
    friend struct RuntimeFilterTimerQueue;
250
    std::shared_ptr<Dependency> _parent = nullptr;
251
    std::vector<std::shared_ptr<Dependency>> _local_runtime_filter_dependencies;
252
    std::mutex _lock;
253
    int64_t _registration_time;
254
    const int32_t _wait_time_ms;
255
    // true only for group_commit_scan_operator
256
    bool _force_wait_timeout;
257
};
258
259
struct RuntimeFilterTimerQueue {
260
    constexpr static int64_t interval = 10;
261
9
    void run() { _thread.detach(); }
262
    void start();
263
264
3
    void stop() {
265
3
        _stop = true;
266
3
        cv.notify_all();
267
3
        wait_for_shutdown();
268
3
    }
269
270
3
    void wait_for_shutdown() const {
271
6
        while (!_shutdown) {
272
3
            std::this_thread::sleep_for(std::chrono::milliseconds(interval));
273
3
        }
274
3
    }
275
276
3
    ~RuntimeFilterTimerQueue() = default;
277
9
    RuntimeFilterTimerQueue() { _thread = std::thread(&RuntimeFilterTimerQueue::start, this); }
278
8.91k
    void push_filter_timer(std::vector<std::shared_ptr<RuntimeFilterTimer>>&& filter) {
279
8.91k
        std::unique_lock<std::mutex> lc(_que_lock);
280
8.91k
        _que.insert(_que.end(), filter.begin(), filter.end());
281
8.91k
        cv.notify_all();
282
8.91k
    }
283
284
    std::thread _thread;
285
    std::condition_variable cv;
286
    std::mutex cv_m;
287
    std::mutex _que_lock;
288
    std::atomic_bool _stop = false;
289
    std::atomic_bool _shutdown = false;
290
    std::list<std::shared_ptr<RuntimeFilterTimer>> _que;
291
};
292
293
struct AggSharedState : public BasicSharedState {
294
    ENABLE_FACTORY_CREATOR(AggSharedState)
295
public:
296
160k
    AggSharedState() { agg_data = std::make_unique<AggregatedDataVariants>(); }
297
159k
    ~AggSharedState() override {
298
159k
        if (!probe_expr_ctxs.empty()) {
299
44.9k
            _close_with_serialized_key();
300
115k
        } else {
301
115k
            _close_without_key();
302
115k
        }
303
159k
    }
304
305
    Status reset_hash_table();
306
307
    bool do_limit_filter(Block* block, size_t num_rows, const std::vector<int>* key_locs = nullptr);
308
    void build_limit_heap(size_t hash_table_size);
309
310
    // We should call this function only at 1st phase.
311
    // 1st phase: is_merge=true, only have one SlotRef.
312
    // 2nd phase: is_merge=false, maybe have multiple exprs.
313
    static int get_slot_column_id(const AggFnEvaluator* evaluator);
314
315
    AggregatedDataVariantsUPtr agg_data = nullptr;
316
    std::unique_ptr<AggregateDataContainer> aggregate_data_container;
317
    std::vector<AggFnEvaluator*> aggregate_evaluators;
318
    // group by k1,k2
319
    VExprContextSPtrs probe_expr_ctxs;
320
    size_t input_num_rows = 0;
321
    std::vector<AggregateDataPtr> values;
322
    /// The total size of the row from the aggregate functions.
323
    size_t total_size_of_aggregate_states = 0;
324
    size_t align_aggregate_states = 1;
325
    /// The offset to the n-th aggregate function in a row of aggregate functions.
326
    Sizes offsets_of_aggregate_states;
327
    std::vector<size_t> make_nullable_keys;
328
329
    bool agg_data_created_without_key = false;
330
    bool enable_spill = false;
331
    bool reach_limit = false;
332
333
    bool use_simple_count = false;
334
    int64_t limit = -1;
335
    bool do_sort_limit = false;
336
    MutableColumns limit_columns;
337
    int limit_columns_min = -1;
338
    PaddedPODArray<uint8_t> need_computes;
339
    std::vector<uint8_t> cmp_res;
340
    std::vector<int> order_directions;
341
    std::vector<int> null_directions;
342
343
    struct HeapLimitCursor {
344
        HeapLimitCursor(int row_id, MutableColumns& limit_columns,
345
                        std::vector<int>& order_directions, std::vector<int>& null_directions)
346
35.5k
                : _row_id(row_id),
347
35.5k
                  _limit_columns(limit_columns),
348
35.5k
                  _order_directions(order_directions),
349
35.5k
                  _null_directions(null_directions) {}
350
351
        HeapLimitCursor(const HeapLimitCursor& other) = default;
352
353
        HeapLimitCursor(HeapLimitCursor&& other) noexcept
354
229k
                : _row_id(other._row_id),
355
229k
                  _limit_columns(other._limit_columns),
356
229k
                  _order_directions(other._order_directions),
357
229k
                  _null_directions(other._null_directions) {}
358
359
0
        HeapLimitCursor& operator=(const HeapLimitCursor& other) noexcept {
360
0
            _row_id = other._row_id;
361
0
            return *this;
362
0
        }
363
364
353k
        HeapLimitCursor& operator=(HeapLimitCursor&& other) noexcept {
365
353k
            _row_id = other._row_id;
366
353k
            return *this;
367
353k
        }
368
369
326k
        bool operator<(const HeapLimitCursor& rhs) const {
370
459k
            for (int i = 0; i < _limit_columns.size(); ++i) {
371
459k
                const auto& _limit_column = _limit_columns[i];
372
459k
                auto res = _limit_column->compare_at(_row_id, rhs._row_id, *_limit_column,
373
459k
                                                     _null_directions[i]) *
374
459k
                           _order_directions[i];
375
459k
                if (res < 0) {
376
162k
                    return true;
377
297k
                } else if (res > 0) {
378
176k
                    return false;
379
176k
                }
380
459k
            }
381
18.4E
            return false;
382
326k
        }
383
384
        int _row_id;
385
        MutableColumns& _limit_columns;
386
        std::vector<int>& _order_directions;
387
        std::vector<int>& _null_directions;
388
    };
389
390
    std::priority_queue<HeapLimitCursor> limit_heap;
391
392
    // Refresh the top limit heap with a new row
393
    void refresh_top_limit(size_t row_id, const ColumnRawPtrs& key_columns);
394
395
    Arena agg_arena_pool;
396
    Arena agg_profile_arena;
397
398
private:
399
    MutableColumns _get_keys_hash_table();
400
401
44.8k
    void _close_with_serialized_key() {
402
44.8k
        std::visit(Overload {[&](std::monostate& arg) -> void {
403
                                 // Do nothing
404
0
                             },
405
44.8k
                             [&](auto& agg_method) -> void {
406
44.8k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
4.25k
                                     return;
410
4.25k
                                 }
411
40.5k
                                 auto& data = *agg_method.hash_table;
412
1.43M
                                 data.for_each_mapped([&](auto& mapped) {
413
1.43M
                                     if (mapped) {
414
1.43M
                                         _destroy_agg_status(mapped);
415
1.43M
                                         mapped = nullptr;
416
1.43M
                                     }
417
1.43M
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_
Line
Count
Source
412
5.30k
                                 data.for_each_mapped([&](auto& mapped) {
413
5.30k
                                     if (mapped) {
414
5.30k
                                         _destroy_agg_status(mapped);
415
5.30k
                                         mapped = nullptr;
416
5.30k
                                     }
417
5.30k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
412
2.11k
                                 data.for_each_mapped([&](auto& mapped) {
413
2.11k
                                     if (mapped) {
414
2.11k
                                         _destroy_agg_status(mapped);
415
2.11k
                                         mapped = nullptr;
416
2.11k
                                     }
417
2.11k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_
Line
Count
Source
412
11.6k
                                 data.for_each_mapped([&](auto& mapped) {
413
11.6k
                                     if (mapped) {
414
11.6k
                                         _destroy_agg_status(mapped);
415
11.6k
                                         mapped = nullptr;
416
11.6k
                                     }
417
11.6k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
412
603
                                 data.for_each_mapped([&](auto& mapped) {
413
603
                                     if (mapped) {
414
603
                                         _destroy_agg_status(mapped);
415
603
                                         mapped = nullptr;
416
603
                                     }
417
603
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
412
7.69k
                                 data.for_each_mapped([&](auto& mapped) {
413
7.69k
                                     if (mapped) {
414
7.69k
                                         _destroy_agg_status(mapped);
415
7.69k
                                         mapped = nullptr;
416
7.69k
                                     }
417
7.69k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
412
864
                                 data.for_each_mapped([&](auto& mapped) {
413
864
                                     if (mapped) {
414
864
                                         _destroy_agg_status(mapped);
415
864
                                         mapped = nullptr;
416
864
                                     }
417
864
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
412
60.3k
                                 data.for_each_mapped([&](auto& mapped) {
413
60.4k
                                     if (mapped) {
414
60.4k
                                         _destroy_agg_status(mapped);
415
60.4k
                                         mapped = nullptr;
416
60.4k
                                     }
417
60.3k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
412
4.87k
                                 data.for_each_mapped([&](auto& mapped) {
413
4.87k
                                     if (mapped) {
414
4.87k
                                         _destroy_agg_status(mapped);
415
4.87k
                                         mapped = nullptr;
416
4.87k
                                     }
417
4.87k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ENKUlS2_E_clISC_EEDaS2_
Line
Count
Source
412
3
                                 data.for_each_mapped([&](auto& mapped) {
413
3
                                     if (mapped) {
414
3
                                         _destroy_agg_status(mapped);
415
3
                                         mapped = nullptr;
416
3
                                     }
417
3
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ENKUlS2_E_clISC_EEDaS2_
Line
Count
Source
412
216
                                 data.for_each_mapped([&](auto& mapped) {
413
216
                                     if (mapped) {
414
216
                                         _destroy_agg_status(mapped);
415
216
                                         mapped = nullptr;
416
216
                                     }
417
216
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
412
126k
                                 data.for_each_mapped([&](auto& mapped) {
413
126k
                                     if (mapped) {
414
126k
                                         _destroy_agg_status(mapped);
415
126k
                                         mapped = nullptr;
416
126k
                                     }
417
126k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
412
139k
                                 data.for_each_mapped([&](auto& mapped) {
413
139k
                                     if (mapped) {
414
139k
                                         _destroy_agg_status(mapped);
415
139k
                                         mapped = nullptr;
416
139k
                                     }
417
139k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
412
16.8k
                                 data.for_each_mapped([&](auto& mapped) {
413
16.8k
                                     if (mapped) {
414
16.6k
                                         _destroy_agg_status(mapped);
415
16.6k
                                         mapped = nullptr;
416
16.6k
                                     }
417
16.8k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
412
17.9k
                                 data.for_each_mapped([&](auto& mapped) {
413
17.9k
                                     if (mapped) {
414
17.9k
                                         _destroy_agg_status(mapped);
415
17.9k
                                         mapped = nullptr;
416
17.9k
                                     }
417
17.9k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
412
599
                                 data.for_each_mapped([&](auto& mapped) {
413
599
                                     if (mapped) {
414
599
                                         _destroy_agg_status(mapped);
415
599
                                         mapped = nullptr;
416
599
                                     }
417
599
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
412
1.77k
                                 data.for_each_mapped([&](auto& mapped) {
413
1.77k
                                     if (mapped) {
414
1.77k
                                         _destroy_agg_status(mapped);
415
1.77k
                                         mapped = nullptr;
416
1.77k
                                     }
417
1.77k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
412
50.7k
                                 data.for_each_mapped([&](auto& mapped) {
413
50.7k
                                     if (mapped) {
414
50.7k
                                         _destroy_agg_status(mapped);
415
50.7k
                                         mapped = nullptr;
416
50.7k
                                     }
417
50.7k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
412
896k
                                 data.for_each_mapped([&](auto& mapped) {
413
897k
                                     if (mapped) {
414
897k
                                         _destroy_agg_status(mapped);
415
897k
                                         mapped = nullptr;
416
897k
                                     }
417
896k
                                 });
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
412
79
                                 data.for_each_mapped([&](auto& mapped) {
413
79
                                     if (mapped) {
414
79
                                         _destroy_agg_status(mapped);
415
79
                                         mapped = nullptr;
416
79
                                     }
417
79
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
412
1.77k
                                 data.for_each_mapped([&](auto& mapped) {
413
1.77k
                                     if (mapped) {
414
1.77k
                                         _destroy_agg_status(mapped);
415
1.77k
                                         mapped = nullptr;
416
1.77k
                                     }
417
1.77k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
412
10.4k
                                 data.for_each_mapped([&](auto& mapped) {
413
10.4k
                                     if (mapped) {
414
10.4k
                                         _destroy_agg_status(mapped);
415
10.4k
                                         mapped = nullptr;
416
10.4k
                                     }
417
10.4k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
412
542
                                 data.for_each_mapped([&](auto& mapped) {
413
542
                                     if (mapped) {
414
542
                                         _destroy_agg_status(mapped);
415
542
                                         mapped = nullptr;
416
542
                                     }
417
542
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
412
21
                                 data.for_each_mapped([&](auto& mapped) {
413
21
                                     if (mapped) {
414
21
                                         _destroy_agg_status(mapped);
415
21
                                         mapped = nullptr;
416
21
                                     }
417
21
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
412
251
                                 data.for_each_mapped([&](auto& mapped) {
413
251
                                     if (mapped) {
414
251
                                         _destroy_agg_status(mapped);
415
251
                                         mapped = nullptr;
416
251
                                     }
417
251
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
412
78.5k
                                 data.for_each_mapped([&](auto& mapped) {
413
78.5k
                                     if (mapped) {
414
78.4k
                                         _destroy_agg_status(mapped);
415
78.4k
                                         mapped = nullptr;
416
78.4k
                                     }
417
78.5k
                                 });
418
40.5k
                                 if (data.has_null_key_data()) {
419
1.05k
                                     _destroy_agg_status(
420
1.05k
                                             data.template get_null_key_data<AggregateDataPtr>());
421
1.05k
                                 }
422
40.5k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEvS2_
Line
Count
Source
405
2.76k
                             [&](auto& agg_method) -> void {
406
2.76k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
27
                                     return;
410
27
                                 }
411
2.74k
                                 auto& data = *agg_method.hash_table;
412
2.74k
                                 data.for_each_mapped([&](auto& mapped) {
413
2.74k
                                     if (mapped) {
414
2.74k
                                         _destroy_agg_status(mapped);
415
2.74k
                                         mapped = nullptr;
416
2.74k
                                     }
417
2.74k
                                 });
418
2.74k
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
2.74k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS7_EEEEEEvS2_
Line
Count
Source
405
1.49k
                             [&](auto& agg_method) -> void {
406
1.49k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
56
                                     return;
410
56
                                 }
411
1.43k
                                 auto& data = *agg_method.hash_table;
412
1.43k
                                 data.for_each_mapped([&](auto& mapped) {
413
1.43k
                                     if (mapped) {
414
1.43k
                                         _destroy_agg_status(mapped);
415
1.43k
                                         mapped = nullptr;
416
1.43k
                                     }
417
1.43k
                                 });
418
1.43k
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
1.43k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEvS2_
Line
Count
Source
405
206
                             [&](auto& agg_method) -> void {
406
206
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
69
                                     return;
410
69
                                 }
411
137
                                 auto& data = *agg_method.hash_table;
412
137
                                 data.for_each_mapped([&](auto& mapped) {
413
137
                                     if (mapped) {
414
137
                                         _destroy_agg_status(mapped);
415
137
                                         mapped = nullptr;
416
137
                                     }
417
137
                                 });
418
137
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
137
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS7_EEEEEEvS2_
Line
Count
Source
405
682
                             [&](auto& agg_method) -> void {
406
682
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
10
                                     return;
410
10
                                 }
411
672
                                 auto& data = *agg_method.hash_table;
412
672
                                 data.for_each_mapped([&](auto& mapped) {
413
672
                                     if (mapped) {
414
672
                                         _destroy_agg_status(mapped);
415
672
                                         mapped = nullptr;
416
672
                                     }
417
672
                                 });
418
672
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
672
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS7_EEEEEEvS2_
Line
Count
Source
405
610
                             [&](auto& agg_method) -> void {
406
610
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
2
                                     return;
410
2
                                 }
411
608
                                 auto& data = *agg_method.hash_table;
412
608
                                 data.for_each_mapped([&](auto& mapped) {
413
608
                                     if (mapped) {
414
608
                                         _destroy_agg_status(mapped);
415
608
                                         mapped = nullptr;
416
608
                                     }
417
608
                                 });
418
608
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
608
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS7_EEEEEEvS2_
Line
Count
Source
405
1.00k
                             [&](auto& agg_method) -> void {
406
1.00k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
81
                                     return;
410
81
                                 }
411
926
                                 auto& data = *agg_method.hash_table;
412
926
                                 data.for_each_mapped([&](auto& mapped) {
413
926
                                     if (mapped) {
414
926
                                         _destroy_agg_status(mapped);
415
926
                                         mapped = nullptr;
416
926
                                     }
417
926
                                 });
418
926
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
926
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS2_
Line
Count
Source
405
782
                             [&](auto& agg_method) -> void {
406
782
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
69
                                     return;
410
69
                                 }
411
713
                                 auto& data = *agg_method.hash_table;
412
713
                                 data.for_each_mapped([&](auto& mapped) {
413
713
                                     if (mapped) {
414
713
                                         _destroy_agg_status(mapped);
415
713
                                         mapped = nullptr;
416
713
                                     }
417
713
                                 });
418
713
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
713
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEvS2_
Line
Count
Source
405
3.04k
                             [&](auto& agg_method) -> void {
406
3.04k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
669
                                     return;
410
669
                                 }
411
2.38k
                                 auto& data = *agg_method.hash_table;
412
2.38k
                                 data.for_each_mapped([&](auto& mapped) {
413
2.38k
                                     if (mapped) {
414
2.38k
                                         _destroy_agg_status(mapped);
415
2.38k
                                         mapped = nullptr;
416
2.38k
                                     }
417
2.38k
                                 });
418
2.38k
                                 if (data.has_null_key_data()) {
419
61
                                     _destroy_agg_status(
420
61
                                             data.template get_null_key_data<AggregateDataPtr>());
421
61
                                 }
422
2.38k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_
Line
Count
Source
405
6
                             [&](auto& agg_method) -> void {
406
6
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
0
                                     return;
410
0
                                 }
411
6
                                 auto& data = *agg_method.hash_table;
412
6
                                 data.for_each_mapped([&](auto& mapped) {
413
6
                                     if (mapped) {
414
6
                                         _destroy_agg_status(mapped);
415
6
                                         mapped = nullptr;
416
6
                                     }
417
6
                                 });
418
6
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
6
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_
Line
Count
Source
405
636
                             [&](auto& agg_method) -> void {
406
636
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
12
                                     return;
410
12
                                 }
411
624
                                 auto& data = *agg_method.hash_table;
412
624
                                 data.for_each_mapped([&](auto& mapped) {
413
624
                                     if (mapped) {
414
624
                                         _destroy_agg_status(mapped);
415
624
                                         mapped = nullptr;
416
624
                                     }
417
624
                                 });
418
624
                                 if (data.has_null_key_data()) {
419
6
                                     _destroy_agg_status(
420
6
                                             data.template get_null_key_data<AggregateDataPtr>());
421
6
                                 }
422
624
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS2_
Line
Count
Source
405
4.70k
                             [&](auto& agg_method) -> void {
406
4.70k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
800
                                     return;
410
800
                                 }
411
3.90k
                                 auto& data = *agg_method.hash_table;
412
3.90k
                                 data.for_each_mapped([&](auto& mapped) {
413
3.90k
                                     if (mapped) {
414
3.90k
                                         _destroy_agg_status(mapped);
415
3.90k
                                         mapped = nullptr;
416
3.90k
                                     }
417
3.90k
                                 });
418
3.90k
                                 if (data.has_null_key_data()) {
419
158
                                     _destroy_agg_status(
420
158
                                             data.template get_null_key_data<AggregateDataPtr>());
421
158
                                 }
422
3.90k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS2_
Line
Count
Source
405
13.2k
                             [&](auto& agg_method) -> void {
406
13.2k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
880
                                     return;
410
880
                                 }
411
12.3k
                                 auto& data = *agg_method.hash_table;
412
12.3k
                                 data.for_each_mapped([&](auto& mapped) {
413
12.3k
                                     if (mapped) {
414
12.3k
                                         _destroy_agg_status(mapped);
415
12.3k
                                         mapped = nullptr;
416
12.3k
                                     }
417
12.3k
                                 });
418
12.3k
                                 if (data.has_null_key_data()) {
419
423
                                     _destroy_agg_status(
420
423
                                             data.template get_null_key_data<AggregateDataPtr>());
421
423
                                 }
422
12.3k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS2_
Line
Count
Source
405
379
                             [&](auto& agg_method) -> void {
406
379
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
5
                                     return;
410
5
                                 }
411
374
                                 auto& data = *agg_method.hash_table;
412
374
                                 data.for_each_mapped([&](auto& mapped) {
413
374
                                     if (mapped) {
414
374
                                         _destroy_agg_status(mapped);
415
374
                                         mapped = nullptr;
416
374
                                     }
417
374
                                 });
418
374
                                 if (data.has_null_key_data()) {
419
18
                                     _destroy_agg_status(
420
18
                                             data.template get_null_key_data<AggregateDataPtr>());
421
18
                                 }
422
374
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS2_
Line
Count
Source
405
934
                             [&](auto& agg_method) -> void {
406
934
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
58
                                     return;
410
58
                                 }
411
876
                                 auto& data = *agg_method.hash_table;
412
876
                                 data.for_each_mapped([&](auto& mapped) {
413
876
                                     if (mapped) {
414
876
                                         _destroy_agg_status(mapped);
415
876
                                         mapped = nullptr;
416
876
                                     }
417
876
                                 });
418
876
                                 if (data.has_null_key_data()) {
419
15
                                     _destroy_agg_status(
420
15
                                             data.template get_null_key_data<AggregateDataPtr>());
421
15
                                 }
422
876
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS2_
Line
Count
Source
405
294
                             [&](auto& agg_method) -> void {
406
294
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
10
                                     return;
410
10
                                 }
411
284
                                 auto& data = *agg_method.hash_table;
412
284
                                 data.for_each_mapped([&](auto& mapped) {
413
284
                                     if (mapped) {
414
284
                                         _destroy_agg_status(mapped);
415
284
                                         mapped = nullptr;
416
284
                                     }
417
284
                                 });
418
284
                                 if (data.has_null_key_data()) {
419
13
                                     _destroy_agg_status(
420
13
                                             data.template get_null_key_data<AggregateDataPtr>());
421
13
                                 }
422
284
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS2_
Line
Count
Source
405
2.06k
                             [&](auto& agg_method) -> void {
406
2.06k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
304
                                     return;
410
304
                                 }
411
1.75k
                                 auto& data = *agg_method.hash_table;
412
1.75k
                                 data.for_each_mapped([&](auto& mapped) {
413
1.75k
                                     if (mapped) {
414
1.75k
                                         _destroy_agg_status(mapped);
415
1.75k
                                         mapped = nullptr;
416
1.75k
                                     }
417
1.75k
                                 });
418
1.75k
                                 if (data.has_null_key_data()) {
419
359
                                     _destroy_agg_status(
420
359
                                             data.template get_null_key_data<AggregateDataPtr>());
421
359
                                 }
422
1.75k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS2_
Line
Count
Source
405
899
                             [&](auto& agg_method) -> void {
406
899
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
223
                                     return;
410
223
                                 }
411
676
                                 auto& data = *agg_method.hash_table;
412
676
                                 data.for_each_mapped([&](auto& mapped) {
413
676
                                     if (mapped) {
414
676
                                         _destroy_agg_status(mapped);
415
676
                                         mapped = nullptr;
416
676
                                     }
417
676
                                 });
418
676
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
676
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS2_
Line
Count
Source
405
3.28k
                             [&](auto& agg_method) -> void {
406
3.28k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
145
                                     return;
410
145
                                 }
411
3.14k
                                 auto& data = *agg_method.hash_table;
412
3.14k
                                 data.for_each_mapped([&](auto& mapped) {
413
3.14k
                                     if (mapped) {
414
3.14k
                                         _destroy_agg_status(mapped);
415
3.14k
                                         mapped = nullptr;
416
3.14k
                                     }
417
3.14k
                                 });
418
3.14k
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
3.14k
                             }},
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
405
140
                             [&](auto& agg_method) -> void {
406
140
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
7
                                     return;
410
7
                                 }
411
133
                                 auto& data = *agg_method.hash_table;
412
133
                                 data.for_each_mapped([&](auto& mapped) {
413
133
                                     if (mapped) {
414
133
                                         _destroy_agg_status(mapped);
415
133
                                         mapped = nullptr;
416
133
                                     }
417
133
                                 });
418
133
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
133
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEvS2_
Line
Count
Source
405
652
                             [&](auto& agg_method) -> void {
406
652
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
45
                                     return;
410
45
                                 }
411
607
                                 auto& data = *agg_method.hash_table;
412
607
                                 data.for_each_mapped([&](auto& mapped) {
413
607
                                     if (mapped) {
414
607
                                         _destroy_agg_status(mapped);
415
607
                                         mapped = nullptr;
416
607
                                     }
417
607
                                 });
418
607
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
607
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS2_
Line
Count
Source
405
129
                             [&](auto& agg_method) -> void {
406
129
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
28
                                     return;
410
28
                                 }
411
101
                                 auto& data = *agg_method.hash_table;
412
101
                                 data.for_each_mapped([&](auto& mapped) {
413
101
                                     if (mapped) {
414
101
                                         _destroy_agg_status(mapped);
415
101
                                         mapped = nullptr;
416
101
                                     }
417
101
                                 });
418
101
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
101
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS2_
Line
Count
Source
405
308
                             [&](auto& agg_method) -> void {
406
308
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
14
                                     return;
410
14
                                 }
411
294
                                 auto& data = *agg_method.hash_table;
412
294
                                 data.for_each_mapped([&](auto& mapped) {
413
294
                                     if (mapped) {
414
294
                                         _destroy_agg_status(mapped);
415
294
                                         mapped = nullptr;
416
294
                                     }
417
294
                                 });
418
294
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
294
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS2_
Line
Count
Source
405
41
                             [&](auto& agg_method) -> void {
406
41
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
0
                                     return;
410
0
                                 }
411
41
                                 auto& data = *agg_method.hash_table;
412
41
                                 data.for_each_mapped([&](auto& mapped) {
413
41
                                     if (mapped) {
414
41
                                         _destroy_agg_status(mapped);
415
41
                                         mapped = nullptr;
416
41
                                     }
417
41
                                 });
418
41
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
41
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS2_
Line
Count
Source
405
301
                             [&](auto& agg_method) -> void {
406
301
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
5
                                     return;
410
5
                                 }
411
296
                                 auto& data = *agg_method.hash_table;
412
296
                                 data.for_each_mapped([&](auto& mapped) {
413
296
                                     if (mapped) {
414
296
                                         _destroy_agg_status(mapped);
415
296
                                         mapped = nullptr;
416
296
                                     }
417
296
                                 });
418
296
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
296
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEvS2_
Line
Count
Source
405
6.25k
                             [&](auto& agg_method) -> void {
406
6.25k
                                 if (use_simple_count) {
407
                                     // Inline count: mapped slots hold UInt64,
408
                                     // not real agg state pointers. Skip destroy.
409
737
                                     return;
410
737
                                 }
411
5.52k
                                 auto& data = *agg_method.hash_table;
412
5.52k
                                 data.for_each_mapped([&](auto& mapped) {
413
5.52k
                                     if (mapped) {
414
5.52k
                                         _destroy_agg_status(mapped);
415
5.52k
                                         mapped = nullptr;
416
5.52k
                                     }
417
5.52k
                                 });
418
5.52k
                                 if (data.has_null_key_data()) {
419
0
                                     _destroy_agg_status(
420
0
                                             data.template get_null_key_data<AggregateDataPtr>());
421
0
                                 }
422
5.52k
                             }},
423
44.8k
                   agg_data->method_variant);
424
44.8k
    }
425
426
115k
    void _close_without_key() {
427
        //because prepare maybe failed, and couldn't create agg data.
428
        //but finally call close to destory agg data, if agg data has bitmapValue
429
        //will be core dump, it's not initialized
430
115k
        if (agg_data_created_without_key) {
431
115k
            _destroy_agg_status(agg_data->without_key);
432
115k
            agg_data_created_without_key = false;
433
115k
        }
434
115k
    }
435
    void _destroy_agg_status(AggregateDataPtr data);
436
};
437
438
static constexpr int BUCKETED_AGG_NUM_BUCKETS = 256;
439
440
/// Shared state for BucketedAggSinkOperatorX / BucketedAggSourceOperatorX.
441
///
442
/// Each sink pipeline instance owns 256 per-bucket hash tables (two-level hash table
443
/// approach, inspired by ClickHouse). During sink, each row is routed to bucket
444
/// (hash >> 24) & 0xFF.
445
///
446
/// Source-side merge is pipelined with sink completion: as each sink instance finishes,
447
/// it unblocks all source dependencies. Source instances scan buckets and merge data
448
/// from finished sink instances into the merge target (the first sink to finish).
449
/// Each bucket has a CAS lock so only one source works on a bucket at a time.
450
/// After all sinks finish and all buckets are merged + output, one source handles
451
/// null key merge and the pipeline completes.
452
///
453
/// Thread safety model:
454
///  - Sink phase: each instance writes only to its own per_instance_data[task_idx]. No locking.
455
///  - Source phase: per-bucket CAS lock (merge_in_progress). Under the lock, a source
456
///    scans all finished sink instances and merges their bucket data into the merge
457
///    target's bucket. Already-merged entries are nulled out to prevent re-processing.
458
///    Output is only done when all sinks have finished and the bucket is fully merged.
459
struct BucketedAggSharedState : public BasicSharedState {
460
    ENABLE_FACTORY_CREATOR(BucketedAggSharedState)
461
public:
462
98
    BucketedAggSharedState() = default;
463
98
    ~BucketedAggSharedState() override { _close(); }
464
465
    /// Per-instance data. One per sink pipeline instance.
466
    /// Each instance has 256 bucket hash tables + 1 shared arena.
467
    struct PerInstanceData {
468
        /// 256 per-bucket hash tables. Each bucket has its own BucketedAggDataVariants.
469
        /// Uses PHHashMap<StringRef> for string keys instead of StringHashMap.
470
        std::vector<BucketedAggDataVariantsUPtr> bucket_agg_data;
471
        ArenaUPtr arena;
472
473
475
        PerInstanceData() : arena(std::make_unique<Arena>()) {
474
475
            bucket_agg_data.resize(BUCKETED_AGG_NUM_BUCKETS);
475
121k
            for (auto& p : bucket_agg_data) {
476
121k
                p = std::make_unique<BucketedAggDataVariants>();
477
121k
            }
478
475
        }
479
    };
480
481
    /// Per-bucket merge state for pipelined source-side processing.
482
    struct BucketMergeState {
483
        /// CAS lock: only one source instance can merge/output this bucket at a time.
484
        std::atomic<bool> merge_in_progress {false};
485
        /// Set to true once the bucket is fully merged and all rows have been output.
486
        std::atomic<bool> output_done {false};
487
        /// Tracks which sink instances have been merged into the merge target
488
        /// for this bucket. Accessed only under merge_in_progress CAS lock.
489
        /// Element i is true when instance i's data for this bucket has been merged.
490
        /// Sized to num_sink_instances in init_instances().
491
        std::vector<bool> merged_instances;
492
    };
493
494
    std::vector<PerInstanceData> per_instance_data;
495
    int num_sink_instances = 0;
496
497
    /// Tracks how many sinks have finished. Incremented by each sink on EOS.
498
    std::atomic<int> num_sinks_finished = 0;
499
500
    /// Per-sink completion flags. Set to true when each sink instance finishes.
501
    /// Source instances read these to know which sinks' data is safe to merge.
502
    std::unique_ptr<std::atomic<bool>[]> sink_finished;
503
504
    /// Index of the first sink instance to finish. Its bucket hash tables serve
505
    /// as the merge target — all other sinks' data is merged into it.
506
    /// Initialized to -1; the first sink to finish CAS-sets it to its instance idx.
507
    std::atomic<int> merge_target_instance = -1;
508
509
    /// Per-bucket merge state. Indexed by bucket id [0, 256).
510
    std::array<BucketMergeState, BUCKETED_AGG_NUM_BUCKETS> bucket_states;
511
512
    // Aggregate function metadata (shared, read-only after init).
513
    std::vector<AggFnEvaluator*> aggregate_evaluators;
514
    VExprContextSPtrs probe_expr_ctxs;
515
    size_t total_size_of_aggregate_states = 0;
516
    size_t align_aggregate_states = 1;
517
    Sizes offsets_of_aggregate_states;
518
    std::vector<size_t> make_nullable_keys;
519
520
    std::atomic<size_t> input_num_rows {0};
521
522
    /// When true, the aggregate has exactly one COUNT(*) function with no args.
523
    /// In this case, mapped values in the hash table store a UInt64 counter
524
    /// directly (reinterpret_cast<AggregateDataPtr>) instead of a pointer to
525
    /// allocated aggregate state. This eliminates create/merge/destroy overhead.
526
    bool use_simple_count = false;
527
528
    // ---- Source-side fields ----
529
530
    // Null key handling: null keys are stored separately (not in any bucket).
531
    // After all buckets are processed, one source instance merges and outputs
532
    // all null key data. This atomic ensures exactly one source instance does it.
533
    std::atomic<bool> null_key_output_claimed {false};
534
535
    /// Monotonically increasing counter bumped on every state change (bucket lock
536
    /// release, sink finish). Used by source instances to detect missed wakeups:
537
    /// if the generation changed between scan start and post-block() re-check,
538
    /// something happened and the source should unblock immediately.
539
    std::atomic<uint64_t> state_generation {0};
540
541
    /// Initialize per-instance data and optionally run a metadata init callback.
542
    /// The callback runs exactly once (under std::call_once), must return Status,
543
    /// and should populate shared metadata like probe_expr_ctxs, aggregate_evaluators, etc.
544
    /// All threads observe the same init status via _init_status.
545
    template <typename Func>
546
471
    Status init_instances(int num_instances, Func&& metadata_init) {
547
471
        std::call_once(_init_once, [&]() {
548
98
            num_sink_instances = num_instances;
549
98
            per_instance_data.resize(num_instances);
550
98
            sink_finished = std::make_unique<std::atomic<bool>[]>(num_instances);
551
573
            for (int i = 0; i < num_instances; ++i) {
552
475
                sink_finished[i].store(false, std::memory_order_relaxed);
553
475
            }
554
25.0k
            for (auto& bs : bucket_states) {
555
25.0k
                bs.merged_instances.resize(num_instances, false);
556
25.0k
            }
557
98
            _init_status = std::forward<Func>(metadata_init)();
558
98
        });
559
471
        return _init_status;
560
471
    }
561
562
private:
563
    std::once_flag _init_once;
564
    Status _init_status;
565
566
98
    void _close() {
567
475
        for (auto& inst : per_instance_data) {
568
121k
            for (auto& bucket_data : inst.bucket_agg_data) {
569
121k
                _close_one_agg_data(*bucket_data);
570
121k
            }
571
475
        }
572
98
    }
573
574
121k
    void _close_one_agg_data(BucketedAggDataVariants& agg_data) {
575
121k
        std::visit(
576
121k
                Overload {[&](std::monostate& arg) -> void {
577
                              // Do nothing
578
0
                          },
579
121k
                          [&](auto& agg_method) -> void {
580
121k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
14.0k
                                  return;
584
14.0k
                              }
585
107k
                              auto& data = *agg_method.hash_table;
586
107k
                              data.for_each_mapped([&](auto& mapped) {
587
30.3k
                                  if (mapped) {
588
15.7k
                                      _destroy_agg_status(mapped);
589
15.7k
                                      mapped = nullptr;
590
15.7k
                                  }
591
30.3k
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32ISB_EEEEEEvS4_ENKUlS4_E_clISC_EEDaS4_
Line
Count
Source
586
28
                              data.for_each_mapped([&](auto& mapped) {
587
28
                                  if (mapped) {
588
17
                                      _destroy_agg_status(mapped);
589
17
                                      mapped = nullptr;
590
17
                                  }
591
28
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS9_EEEEEEvS4_ENKUlS4_E_clISA_EEDaS4_
Line
Count
Source
586
48
                              data.for_each_mapped([&](auto& mapped) {
587
48
                                  if (mapped) {
588
26
                                      _destroy_agg_status(mapped);
589
26
                                      mapped = nullptr;
590
26
                                  }
591
48
                              });
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32ISB_EEEEEEvS4_ENKUlS4_E_clISC_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS9_EEEEEEvS4_ENKUlS4_E_clISA_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS9_EEEEEEvS4_ENKUlS4_E_clISA_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS9_EEEEEEvS4_ENKUlS4_E_clISA_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS4_ENKUlS4_E_clIS9_EEDaS4_
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyI9PHHashMapINS_9StringRefEPc11DefaultHashISB_vEEEEEEEEEEvS4_ENKUlS4_E_clISC_EEDaS4_
Line
Count
Source
586
9
                              data.for_each_mapped([&](auto& mapped) {
587
9
                                  if (mapped) {
588
2
                                      _destroy_agg_status(mapped);
589
2
                                      mapped = nullptr;
590
2
                                  }
591
9
                              });
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapISB_Pc9HashCRC32ISB_EEEEEEEEEEvS4_ENKUlS4_E_clISE_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapISB_Pc9HashCRC32ISB_EEEEEEEEEEvS4_ENKUlS4_E_clISE_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS4_ENKUlS4_E_clISB_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS4_ENKUlS4_E_clISB_EEDaS4_
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS4_ENKUlS4_E_clISB_EEDaS4_
Line
Count
Source
586
250
                              data.for_each_mapped([&](auto& mapped) {
587
250
                                  if (mapped) {
588
125
                                      _destroy_agg_status(mapped);
589
125
                                      mapped = nullptr;
590
125
                                  }
591
250
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS4_ENKUlS4_E_clISB_EEDaS4_
Line
Count
Source
586
22
                              data.for_each_mapped([&](auto& mapped) {
587
22
                                  if (mapped) {
588
12
                                      _destroy_agg_status(mapped);
589
12
                                      mapped = nullptr;
590
12
                                  }
591
22
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS4_ENKUlS4_E_clISB_EEDaS4_
Line
Count
Source
586
4
                              data.for_each_mapped([&](auto& mapped) {
587
4
                                  if (mapped) {
588
2
                                      _destroy_agg_status(mapped);
589
2
                                      mapped = nullptr;
590
2
                                  }
591
4
                              });
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS4_ENKUlS4_E_clISB_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS4_ENKUlS4_E_clIS9_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS4_ENKUlS4_E_clIS9_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapISA_Pc9HashCRC32ISA_EEEEEEvS4_ENKUlS4_E_clISC_EEDaS4_
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapISA_Pc9HashCRC32ISA_EEEEEEvS4_ENKUlS4_E_clISC_EEDaS4_
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_19MethodStringNoCacheI9PHHashMapINS_9StringRefEPc11DefaultHashIS9_vEEEEEEvS4_ENKUlS4_E_clISA_EEDaS4_
Line
Count
Source
586
42
                              data.for_each_mapped([&](auto& mapped) {
587
42
                                  if (mapped) {
588
7
                                      _destroy_agg_status(mapped);
589
7
                                      mapped = nullptr;
590
7
                                  }
591
42
                              });
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS4_ENKUlS4_E_clIS9_EEDaS4_
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS4_ENKUlS4_E_clIS9_EEDaS4_
Line
Count
Source
586
27.5k
                              data.for_each_mapped([&](auto& mapped) {
587
27.5k
                                  if (mapped) {
588
15.0k
                                      _destroy_agg_status(mapped);
589
15.0k
                                      mapped = nullptr;
590
15.0k
                                  }
591
27.5k
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS4_ENKUlS4_E_clIS9_EEDaS4_
Line
Count
Source
586
28
                              data.for_each_mapped([&](auto& mapped) {
587
28
                                  if (mapped) {
588
6
                                      _destroy_agg_status(mapped);
589
6
                                      mapped = nullptr;
590
6
                                  }
591
28
                              });
Unexecuted instantiation: _ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS4_ENKUlS4_E_clIS9_EEDaS4_
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS9_vEEEEEEvS4_ENKUlS4_E_clISA_EEDaS4_
Line
Count
Source
586
2.37k
                              data.for_each_mapped([&](auto& mapped) {
587
2.37k
                                  if (mapped) {
588
557
                                      _destroy_agg_status(mapped);
589
557
                                      mapped = nullptr;
590
557
                                  }
591
2.37k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
51.7k
                                                                 bool>) {
594
51.7k
                                  if (data.has_null_key_data()) {
595
2
                                      _destroy_agg_status(
596
2
                                              data.template get_null_key_data<AggregateDataPtr>());
597
2
                                  }
598
51.7k
                              }
599
107k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32ISB_EEEEEEvS4_
Line
Count
Source
579
5.63k
                          [&](auto& agg_method) -> void {
580
5.63k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
0
                                  return;
584
0
                              }
585
5.63k
                              auto& data = *agg_method.hash_table;
586
5.63k
                              data.for_each_mapped([&](auto& mapped) {
587
5.63k
                                  if (mapped) {
588
5.63k
                                      _destroy_agg_status(mapped);
589
5.63k
                                      mapped = nullptr;
590
5.63k
                                  }
591
5.63k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
                                                                 bool>) {
594
                                  if (data.has_null_key_data()) {
595
                                      _destroy_agg_status(
596
                                              data.template get_null_key_data<AggregateDataPtr>());
597
                                  }
598
                              }
599
5.63k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS9_EEEEEEvS4_
Line
Count
Source
579
19.4k
                          [&](auto& agg_method) -> void {
580
19.4k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
0
                                  return;
584
0
                              }
585
19.4k
                              auto& data = *agg_method.hash_table;
586
19.4k
                              data.for_each_mapped([&](auto& mapped) {
587
19.4k
                                  if (mapped) {
588
19.4k
                                      _destroy_agg_status(mapped);
589
19.4k
                                      mapped = nullptr;
590
19.4k
                                  }
591
19.4k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
                                                                 bool>) {
594
                                  if (data.has_null_key_data()) {
595
                                      _destroy_agg_status(
596
                                              data.template get_null_key_data<AggregateDataPtr>());
597
                                  }
598
                              }
599
19.4k
                          }},
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32ISB_EEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS9_EEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS9_EEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS9_EEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS4_
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyI9PHHashMapINS_9StringRefEPc11DefaultHashISB_vEEEEEEEEEEvS4_
Line
Count
Source
579
2.81k
                          [&](auto& agg_method) -> void {
580
2.81k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
1.02k
                                  return;
584
1.02k
                              }
585
1.79k
                              auto& data = *agg_method.hash_table;
586
1.79k
                              data.for_each_mapped([&](auto& mapped) {
587
1.79k
                                  if (mapped) {
588
1.79k
                                      _destroy_agg_status(mapped);
589
1.79k
                                      mapped = nullptr;
590
1.79k
                                  }
591
1.79k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
1.79k
                                                                 bool>) {
594
1.79k
                                  if (data.has_null_key_data()) {
595
0
                                      _destroy_agg_status(
596
0
                                              data.template get_null_key_data<AggregateDataPtr>());
597
0
                                  }
598
1.79k
                              }
599
1.79k
                          }},
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapISB_Pc9HashCRC32ISB_EEEEEEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapISB_Pc9HashCRC32ISB_EEEEEEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS4_
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS4_
Line
Count
Source
579
34.3k
                          [&](auto& agg_method) -> void {
580
34.3k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
3.32k
                                  return;
584
3.32k
                              }
585
30.9k
                              auto& data = *agg_method.hash_table;
586
30.9k
                              data.for_each_mapped([&](auto& mapped) {
587
30.9k
                                  if (mapped) {
588
30.9k
                                      _destroy_agg_status(mapped);
589
30.9k
                                      mapped = nullptr;
590
30.9k
                                  }
591
30.9k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
30.9k
                                                                 bool>) {
594
30.9k
                                  if (data.has_null_key_data()) {
595
2
                                      _destroy_agg_status(
596
2
                                              data.template get_null_key_data<AggregateDataPtr>());
597
2
                                  }
598
30.9k
                              }
599
30.9k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS4_
Line
Count
Source
579
18.4k
                          [&](auto& agg_method) -> void {
580
18.4k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
0
                                  return;
584
0
                              }
585
18.4k
                              auto& data = *agg_method.hash_table;
586
18.4k
                              data.for_each_mapped([&](auto& mapped) {
587
18.4k
                                  if (mapped) {
588
18.4k
                                      _destroy_agg_status(mapped);
589
18.4k
                                      mapped = nullptr;
590
18.4k
                                  }
591
18.4k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
18.4k
                                                                 bool>) {
594
18.4k
                                  if (data.has_null_key_data()) {
595
0
                                      _destroy_agg_status(
596
0
                                              data.template get_null_key_data<AggregateDataPtr>());
597
0
                                  }
598
18.4k
                              }
599
18.4k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS4_
Line
Count
Source
579
512
                          [&](auto& agg_method) -> void {
580
512
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
0
                                  return;
584
0
                              }
585
512
                              auto& data = *agg_method.hash_table;
586
512
                              data.for_each_mapped([&](auto& mapped) {
587
512
                                  if (mapped) {
588
512
                                      _destroy_agg_status(mapped);
589
512
                                      mapped = nullptr;
590
512
                                  }
591
512
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
512
                                                                 bool>) {
594
512
                                  if (data.has_null_key_data()) {
595
0
                                      _destroy_agg_status(
596
0
                                              data.template get_null_key_data<AggregateDataPtr>());
597
0
                                  }
598
512
                              }
599
512
                          }},
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIN4wide7integerILm256EjEE9PHHashMapISA_Pc9HashCRC32ISA_EEEEEEvS4_
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIN4wide7integerILm128EjEE9PHHashMapISA_Pc9HashCRC32ISA_EEEEEEvS4_
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_19MethodStringNoCacheI9PHHashMapINS_9StringRefEPc11DefaultHashIS9_vEEEEEEvS4_
Line
Count
Source
579
12.8k
                          [&](auto& agg_method) -> void {
580
12.8k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
9.72k
                                  return;
584
9.72k
                              }
585
3.07k
                              auto& data = *agg_method.hash_table;
586
3.07k
                              data.for_each_mapped([&](auto& mapped) {
587
3.07k
                                  if (mapped) {
588
3.07k
                                      _destroy_agg_status(mapped);
589
3.07k
                                      mapped = nullptr;
590
3.07k
                                  }
591
3.07k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
                                                                 bool>) {
594
                                  if (data.has_null_key_data()) {
595
                                      _destroy_agg_status(
596
                                              data.template get_null_key_data<AggregateDataPtr>());
597
                                  }
598
                              }
599
3.07k
                          }},
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS4_
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS4_
Line
Count
Source
579
5.63k
                          [&](auto& agg_method) -> void {
580
5.63k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
0
                                  return;
584
0
                              }
585
5.63k
                              auto& data = *agg_method.hash_table;
586
5.63k
                              data.for_each_mapped([&](auto& mapped) {
587
5.63k
                                  if (mapped) {
588
5.63k
                                      _destroy_agg_status(mapped);
589
5.63k
                                      mapped = nullptr;
590
5.63k
                                  }
591
5.63k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
                                                                 bool>) {
594
                                  if (data.has_null_key_data()) {
595
                                      _destroy_agg_status(
596
                                              data.template get_null_key_data<AggregateDataPtr>());
597
                                  }
598
                              }
599
5.63k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS4_
Line
Count
Source
579
7.68k
                          [&](auto& agg_method) -> void {
580
7.68k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
0
                                  return;
584
0
                              }
585
7.68k
                              auto& data = *agg_method.hash_table;
586
7.68k
                              data.for_each_mapped([&](auto& mapped) {
587
7.68k
                                  if (mapped) {
588
7.68k
                                      _destroy_agg_status(mapped);
589
7.68k
                                      mapped = nullptr;
590
7.68k
                                  }
591
7.68k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
                                                                 bool>) {
594
                                  if (data.has_null_key_data()) {
595
                                      _destroy_agg_status(
596
                                              data.template get_null_key_data<AggregateDataPtr>());
597
                                  }
598
                              }
599
7.68k
                          }},
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS4_
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS9_vEEEEEEvS4_
Line
Count
Source
579
14.3k
                          [&](auto& agg_method) -> void {
580
14.3k
                              if (use_simple_count) {
581
                                  // simple_count: mapped slots hold UInt64 counters,
582
                                  // not real agg state pointers. Skip destroy.
583
0
                                  return;
584
0
                              }
585
14.3k
                              auto& data = *agg_method.hash_table;
586
14.3k
                              data.for_each_mapped([&](auto& mapped) {
587
14.3k
                                  if (mapped) {
588
14.3k
                                      _destroy_agg_status(mapped);
589
14.3k
                                      mapped = nullptr;
590
14.3k
                                  }
591
14.3k
                              });
592
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
593
                                                                 bool>) {
594
                                  if (data.has_null_key_data()) {
595
                                      _destroy_agg_status(
596
                                              data.template get_null_key_data<AggregateDataPtr>());
597
                                  }
598
                              }
599
14.3k
                          }},
600
121k
                agg_data.method_variant);
601
121k
    }
602
603
    void _destroy_agg_status(AggregateDataPtr data);
604
};
605
606
struct PartitionedAggSharedState : public BasicSharedState,
607
                                   public std::enable_shared_from_this<PartitionedAggSharedState> {
608
    ENABLE_FACTORY_CREATOR(PartitionedAggSharedState)
609
610
112
    PartitionedAggSharedState() = default;
611
112
    ~PartitionedAggSharedState() override { close(); }
612
613
    void close();
614
615
    AggSharedState* _in_mem_shared_state = nullptr;
616
    std::shared_ptr<BasicSharedState> _in_mem_shared_state_sptr;
617
618
    // partition count is no longer stored in shared state; operators maintain their own
619
    std::atomic<bool> _is_spilled = false;
620
    // This state is shared by the partitioned agg sink and source pipelines. Spill files left
621
    // here are owned by the shared state until the source moves them into its local queue, so the
622
    // cleanup must be tied to the shared state's lifetime and must be idempotent.
623
    std::atomic_bool is_closed = false;
624
    std::deque<SpillFileSPtr> _spill_partitions;
625
};
626
627
struct SortSharedState : public BasicSharedState {
628
    ENABLE_FACTORY_CREATOR(SortSharedState)
629
public:
630
    std::shared_ptr<Sorter> sorter;
631
};
632
633
struct SpillSortSharedState : public BasicSharedState,
634
                              public std::enable_shared_from_this<SpillSortSharedState> {
635
    ENABLE_FACTORY_CREATOR(SpillSortSharedState)
636
637
30
    SpillSortSharedState() = default;
638
30
    ~SpillSortSharedState() override = default;
639
640
443
    void update_spill_block_batch_row_count(RuntimeState* state, const Block* block) {
641
443
        auto rows = block->rows();
642
443
        if (rows > 0 && 0 == avg_row_bytes) {
643
17
            avg_row_bytes = std::max((std::size_t)1, block->bytes() / rows);
644
17
            spill_block_batch_row_count =
645
17
                    (state->spill_buffer_size_bytes() + avg_row_bytes - 1) / avg_row_bytes;
646
17
            LOG(INFO) << "spill sort block batch row count: " << spill_block_batch_row_count;
647
17
        }
648
443
    }
649
650
    void close();
651
652
    SortSharedState* in_mem_shared_state = nullptr;
653
    bool enable_spill = false;
654
    bool is_spilled = false;
655
    int64_t limit = -1;
656
    int64_t offset = 0;
657
    std::atomic_bool is_closed = false;
658
    std::shared_ptr<BasicSharedState> in_mem_shared_state_sptr;
659
660
    std::deque<SpillFileSPtr> sorted_spill_groups;
661
    size_t avg_row_bytes = 0;
662
    size_t spill_block_batch_row_count;
663
};
664
665
struct UnionSharedState : public BasicSharedState {
666
    ENABLE_FACTORY_CREATOR(UnionSharedState)
667
668
public:
669
2.88k
    UnionSharedState(int child_count = 1) : data_queue(child_count), _child_count(child_count) {};
670
0
    int child_count() const { return _child_count; }
671
    DataQueue data_queue;
672
    const int _child_count;
673
};
674
675
struct DataQueueSharedState : public BasicSharedState {
676
    ENABLE_FACTORY_CREATOR(DataQueueSharedState)
677
public:
678
    DataQueue data_queue;
679
};
680
681
class MultiCastDataStreamer;
682
683
struct MultiCastSharedState : public BasicSharedState,
684
                              public std::enable_shared_from_this<MultiCastSharedState> {
685
    MultiCastSharedState(ObjectPool* pool, int cast_sender_count, int node_id);
686
687
    std::unique_ptr<MultiCastDataStreamer> multi_cast_data_streamer;
688
};
689
690
struct AnalyticSharedState : public BasicSharedState {
691
    ENABLE_FACTORY_CREATOR(AnalyticSharedState)
692
693
public:
694
6.58k
    AnalyticSharedState() = default;
695
    std::queue<Block> blocks_buffer GUARDED_BY(buffer_mutex);
696
    AnnotatedMutex buffer_mutex;
697
    bool sink_eos GUARDED_BY(sink_eos_lock) = false;
698
    AnnotatedMutex sink_eos_lock;
699
    Arena agg_arena_pool;
700
};
701
702
struct JoinSharedState : public BasicSharedState {
703
    // For some join case, we can apply a short circuit strategy
704
    // 1. _has_null_in_build_side = true
705
    // 2. build side rows is empty, Join op is: inner join/right outer join/left semi/right semi/right anti
706
    bool _has_null_in_build_side = false;
707
    bool short_circuit_for_probe = false;
708
    // for some join, when build side rows is empty, we could return directly by add some additional null data in probe table.
709
    bool empty_right_table_need_probe_dispose = false;
710
    JoinOpVariants join_op_variants;
711
};
712
713
struct HashJoinSharedState : public JoinSharedState {
714
    ENABLE_FACTORY_CREATOR(HashJoinSharedState)
715
99.5k
    HashJoinSharedState() {
716
99.5k
        hash_table_variant_vector.push_back(std::make_shared<JoinDataVariants>());
717
99.5k
    }
718
2.91k
    HashJoinSharedState(int num_instances) {
719
2.91k
        source_deps.resize(num_instances, nullptr);
720
2.91k
        hash_table_variant_vector.resize(num_instances, nullptr);
721
19.7k
        for (int i = 0; i < num_instances; i++) {
722
16.8k
            hash_table_variant_vector[i] = std::make_shared<JoinDataVariants>();
723
16.8k
        }
724
2.91k
    }
725
    std::shared_ptr<Arena> arena = std::make_shared<Arena>();
726
727
    const std::vector<TupleDescriptor*> build_side_child_desc;
728
    size_t build_exprs_size = 0;
729
    std::shared_ptr<Block> build_block;
730
    std::shared_ptr<std::vector<uint32_t>> build_indexes_null;
731
732
    // Used by shared hash table
733
    // For probe operator, hash table in _hash_table_variants is read-only if visited flags is not
734
    // used. (visited flags will be used only in right / full outer join).
735
    //
736
    // For broadcast join, although hash table is read-only, some states in `_hash_table_variants`
737
    // are still could be written. For example, serialized keys will be written in a continuous
738
    // memory in `_hash_table_variants`. So before execution, we should use a local _hash_table_variants
739
    // which has a shared hash table in it.
740
    std::vector<std::shared_ptr<JoinDataVariants>> hash_table_variant_vector;
741
742
    // whether left semi join could directly return
743
    // if runtime filters contains local in filter, we can make sure all input rows are matched
744
    // local filter will always be applied, and in filter could guarantee precise filtering
745
    // ATTN: we should disable always_true logic for in filter when we set this flag
746
    bool left_semi_direct_return = false;
747
748
    // ASOF JOIN specific fields
749
    // Whether the inequality is >= or > (true) vs <= or < (false)
750
    bool asof_inequality_is_greater = true;
751
    // Whether the inequality is strict (> or <) vs non-strict (>= or <=)
752
    bool asof_inequality_is_strict = false;
753
754
    // ASOF JOIN pre-sorted index with inline values for O(log K) branchless lookup
755
    // Typed AsofIndexGroups stored in a variant (uint32_t for DateV2, uint64_t for DateTimeV2/TimestampTZ)
756
    AsofIndexVariant asof_index_groups;
757
    // build_row_index -> bucket_id for O(1) reverse lookup
758
    std::vector<uint32_t> asof_build_row_to_bucket;
759
};
760
761
struct PartitionedHashJoinSharedState
762
        : public HashJoinSharedState,
763
          public std::enable_shared_from_this<PartitionedHashJoinSharedState> {
764
    ENABLE_FACTORY_CREATOR(PartitionedHashJoinSharedState)
765
766
    std::unique_ptr<RuntimeState> _inner_runtime_state;
767
    std::shared_ptr<HashJoinSharedState> _inner_shared_state;
768
    std::vector<std::unique_ptr<MutableBlock>> _partitioned_build_blocks;
769
    std::vector<SpillFileSPtr> _spilled_build_groups;
770
    std::atomic<bool> _is_spilled = false;
771
};
772
773
struct NestedLoopJoinSharedState : public JoinSharedState {
774
    ENABLE_FACTORY_CREATOR(NestedLoopJoinSharedState)
775
    // if true, probe child has no more rows to process
776
    bool probe_side_eos = false;
777
    // Visited flags for each row in build side.
778
    MutableColumns build_side_visited_flags;
779
    // List of build blocks, constructed in prepare()
780
    Blocks build_blocks;
781
};
782
783
struct PartitionSortNodeSharedState : public BasicSharedState {
784
    ENABLE_FACTORY_CREATOR(PartitionSortNodeSharedState)
785
public:
786
    std::queue<Block> blocks_buffer GUARDED_BY(buffer_mutex);
787
    AnnotatedMutex buffer_mutex;
788
    std::vector<std::unique_ptr<PartitionSorter>> partition_sorts;
789
    bool sink_eos GUARDED_BY(sink_eos_lock) = false;
790
    AnnotatedMutex sink_eos_lock;
791
    AnnotatedMutex prepared_finish_lock;
792
};
793
794
struct SetSharedState : public BasicSharedState {
795
    ENABLE_FACTORY_CREATOR(SetSharedState)
796
public:
797
    /// default init
798
    Block build_block; // build to source
799
    //record element size in hashtable
800
    int64_t valid_element_in_hash_tbl = 0;
801
    //first: idx mapped to column types
802
    //second: column_id, could point to origin column or cast column
803
    std::unordered_map<int, int> build_col_idx;
804
805
    //// shared static states (shared, decided in prepare/open...)
806
807
    /// init in setup_local_state
808
    std::unique_ptr<SetDataVariants> hash_table_variants =
809
            std::make_unique<SetDataVariants>(); // the real data HERE.
810
    std::vector<bool> build_not_ignore_null;
811
812
    // The SET operator's child might have different nullable attributes.
813
    // If a calculation involves both nullable and non-nullable columns, the final output should be a nullable column
814
    Status update_build_not_ignore_null(const VExprContextSPtrs& ctxs);
815
816
    size_t get_hash_table_size() const;
817
    /// init in both upstream side.
818
    //The i-th result expr list refers to the i-th child.
819
    std::vector<VExprContextSPtrs> child_exprs_lists;
820
821
    /// init in build side
822
    size_t child_quantity;
823
    VExprContextSPtrs build_child_exprs;
824
    std::vector<Dependency*> probe_finished_children_dependency;
825
826
    /// init in probe side
827
    std::vector<VExprContextSPtrs> probe_child_exprs_lists;
828
829
    std::atomic<bool> ready_for_read = false;
830
831
    Arena arena;
832
833
    /// called in setup_local_state
834
    Status hash_table_init();
835
};
836
837
1.41M
inline bool is_shuffled_exchange(TLocalPartitionType::type idx) {
838
1.41M
    return idx == TLocalPartitionType::GLOBAL_EXECUTION_HASH_SHUFFLE ||
839
1.41M
           idx == TLocalPartitionType::LOCAL_EXECUTION_HASH_SHUFFLE ||
840
1.41M
           idx == TLocalPartitionType::BUCKET_HASH_SHUFFLE;
841
1.41M
}
842
843
242k
inline std::string get_exchange_type_name(TLocalPartitionType::type idx) {
844
242k
    switch (idx) {
845
14
    case TLocalPartitionType::NOOP:
846
14
        return "NOOP";
847
59
    case TLocalPartitionType::GLOBAL_EXECUTION_HASH_SHUFFLE:
848
59
        return "GLOBAL_HASH_SHUFFLE";
849
46.3k
    case TLocalPartitionType::LOCAL_EXECUTION_HASH_SHUFFLE:
850
46.3k
        return "LOCAL_HASH_SHUFFLE";
851
187k
    case TLocalPartitionType::PASSTHROUGH:
852
187k
        return "PASSTHROUGH";
853
196
    case TLocalPartitionType::BUCKET_HASH_SHUFFLE:
854
196
        return "BUCKET_HASH_SHUFFLE";
855
638
    case TLocalPartitionType::BROADCAST:
856
638
        return "BROADCAST";
857
1.59k
    case TLocalPartitionType::ADAPTIVE_PASSTHROUGH:
858
1.59k
        return "ADAPTIVE_PASSTHROUGH";
859
5.52k
    case TLocalPartitionType::PASS_TO_ONE:
860
5.52k
        return "PASS_TO_ONE";
861
0
    case TLocalPartitionType::LOCAL_MERGE_SORT:
862
0
        return "LOCAL_MERGE_SORT";
863
242k
    }
864
0
    throw Exception(Status::FatalError("__builtin_unreachable"));
865
242k
}
866
867
struct DataDistribution {
868
2.02M
    DataDistribution(TLocalPartitionType::type type) : distribution_type(type) {}
869
    DataDistribution(TLocalPartitionType::type type, const std::vector<TExpr>& partition_exprs_)
870
82.6k
            : distribution_type(type), partition_exprs(partition_exprs_) {}
871
8.15k
    DataDistribution(const DataDistribution& other) = default;
872
212k
    bool need_local_exchange() const { return distribution_type != TLocalPartitionType::NOOP; }
873
224k
    DataDistribution& operator=(const DataDistribution& other) = default;
874
    TLocalPartitionType::type distribution_type;
875
    std::vector<TExpr> partition_exprs;
876
};
877
878
class ExchangerBase;
879
880
struct LocalExchangeSharedState : public BasicSharedState {
881
public:
882
    ENABLE_FACTORY_CREATOR(LocalExchangeSharedState);
883
    LocalExchangeSharedState(int num_instances);
884
    ~LocalExchangeSharedState() override;
885
    std::unique_ptr<ExchangerBase> exchanger {};
886
    std::vector<RuntimeProfile::Counter*> mem_counters;
887
    std::atomic<int64_t> mem_usage = 0;
888
    std::atomic<size_t> _buffer_mem_limit = config::local_exchange_buffer_mem_limit;
889
    // 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.
890
    std::mutex le_lock;
891
    void sub_running_sink_operators();
892
    void sub_running_source_operators();
893
242k
    void _set_always_ready() {
894
1.62M
        for (auto& dep : source_deps) {
895
1.62M
            DCHECK(dep);
896
1.62M
            dep->set_always_ready();
897
1.62M
        }
898
242k
        for (auto& dep : sink_deps) {
899
242k
            DCHECK(dep);
900
242k
            dep->set_always_ready();
901
242k
        }
902
242k
    }
903
904
324k
    Dependency* get_sink_dep_by_channel_id(int channel_id) { return nullptr; }
905
906
300k
    void set_ready_to_read(int channel_id) {
907
300k
        auto& dep = source_deps[channel_id];
908
18.4E
        DCHECK(dep) << channel_id;
909
300k
        dep->set_ready();
910
300k
    }
911
912
300k
    void add_mem_usage(int channel_id, size_t delta) { mem_counters[channel_id]->update(delta); }
913
914
300k
    void sub_mem_usage(int channel_id, size_t delta) {
915
300k
        mem_counters[channel_id]->update(-(int64_t)delta);
916
300k
    }
917
918
243k
    void add_total_mem_usage(size_t delta) {
919
243k
        if (cast_set<int64_t>(mem_usage.fetch_add(delta) + delta) > _buffer_mem_limit) {
920
103
            sink_deps.front()->block();
921
103
        }
922
243k
    }
923
924
243k
    void sub_total_mem_usage(size_t delta) {
925
243k
        auto prev_usage = mem_usage.fetch_sub(delta);
926
243k
        DCHECK_GE(prev_usage, cast_set<int64_t>(delta))
927
0
                << "prev_usage: " << prev_usage << " delta: " << delta;
928
243k
        if (cast_set<int64_t>(prev_usage - delta) <= _buffer_mem_limit) {
929
243k
            sink_deps.front()->set_ready();
930
243k
        }
931
243k
    }
932
933
0
    void set_low_memory_mode(RuntimeState* state) {
934
0
        _buffer_mem_limit = std::min<int64_t>(config::local_exchange_buffer_mem_limit,
935
0
                                              state->low_memory_mode_buffer_limit());
936
0
    }
937
};
938
939
} // namespace doris