Coverage Report

Created: 2026-05-23 07:40

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