Coverage Report

Created: 2026-05-14 10:10

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.65M
    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.65M
        return reinterpret_cast<TARGET*>(this);
78
2.65M
    }
_ZN5doris16BasicSharedState4castINS_19HashJoinSharedStateEEEPT_v
Line
Count
Source
73
248k
    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
248k
        return reinterpret_cast<TARGET*>(this);
78
248k
    }
_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
518k
    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
518k
        return reinterpret_cast<TARGET*>(this);
78
518k
    }
_ZN5doris16BasicSharedState4castINS_20SpillSortSharedStateEEEPT_v
Line
Count
Source
73
80
    TARGET* cast() {
74
80
        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
80
        return reinterpret_cast<TARGET*>(this);
78
80
    }
_ZN5doris16BasicSharedState4castINS_25NestedLoopJoinSharedStateEEEPT_v
Line
Count
Source
73
18.1k
    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
18.1k
        return reinterpret_cast<TARGET*>(this);
78
18.1k
    }
_ZN5doris16BasicSharedState4castINS_19AnalyticSharedStateEEEPT_v
Line
Count
Source
73
14.3k
    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.3k
        return reinterpret_cast<TARGET*>(this);
78
14.3k
    }
_ZN5doris16BasicSharedState4castINS_14AggSharedStateEEEPT_v
Line
Count
Source
73
268k
    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
268k
        return reinterpret_cast<TARGET*>(this);
78
268k
    }
_ZN5doris16BasicSharedState4castINS_22BucketedAggSharedStateEEEPT_v
Line
Count
Source
73
676
    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
676
        return reinterpret_cast<TARGET*>(this);
78
676
    }
_ZN5doris16BasicSharedState4castINS_25PartitionedAggSharedStateEEEPT_v
Line
Count
Source
73
445
    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
445
        return reinterpret_cast<TARGET*>(this);
78
445
    }
_ZN5doris16BasicSharedState4castINS_16UnionSharedStateEEEPT_v
Line
Count
Source
73
11.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
11.9k
        return reinterpret_cast<TARGET*>(this);
78
11.9k
    }
_ZN5doris16BasicSharedState4castINS_28PartitionSortNodeSharedStateEEEPT_v
Line
Count
Source
73
800
    TARGET* cast() {
74
800
        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
800
        return reinterpret_cast<TARGET*>(this);
78
800
    }
_ZN5doris16BasicSharedState4castINS_20MultiCastSharedStateEEEPT_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_14SetSharedStateEEEPT_v
Line
Count
Source
73
16.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
16.7k
        return reinterpret_cast<TARGET*>(this);
78
16.7k
    }
_ZN5doris16BasicSharedState4castINS_24LocalExchangeSharedStateEEEPT_v
Line
Count
Source
73
1.01M
    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.01M
        return reinterpret_cast<TARGET*>(this);
78
1.01M
    }
_ZN5doris16BasicSharedState4castIS0_EEPT_v
Line
Count
Source
73
524k
    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
524k
        return reinterpret_cast<TARGET*>(this);
78
524k
    }
_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
1.90M
    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
757k
    std::vector<DependencySPtr> get_dep_by_channel_id(int channel_id) {
99
757k
        DCHECK_LT(channel_id, source_deps.size());
100
757k
        return {source_deps[channel_id]};
101
757k
    }
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
6.86M
            : _id(id), _node_id(node_id), _name(std::move(name)), _ready(ready) {}
109
6.91M
    virtual ~Dependency() = default;
110
111
0
    [[nodiscard]] int id() const { return _id; }
112
8.32M
    [[nodiscard]] virtual std::string name() const { return _name; }
113
300k
    BasicSharedState* shared_state() { return _shared_state; }
114
2.55M
    void set_shared_state(BasicSharedState* shared_state) { _shared_state = shared_state; }
115
    virtual std::string debug_string(int indentation_level = 0);
116
1.03G
    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.21M
    void start_watcher() { _watcher.start(); }
120
8.95M
    [[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
551k
    void set_ready_to_read(int channel_id = 0) {
127
551k
        DCHECK_LT(channel_id, _shared_state->source_deps.size()) << debug_string();
128
551k
        _shared_state->source_deps[channel_id]->set_ready();
129
551k
    }
130
926
    void set_ready_to_write() {
131
926
        DCHECK_EQ(_shared_state->sink_deps.size(), 1) << debug_string();
132
926
        _shared_state->sink_deps.front()->set_ready();
133
926
    }
134
135
    // Notify downstream pipeline tasks this dependency is blocked.
136
1.70M
    void block() {
137
1.70M
        if (_always_ready) {
138
290k
            return;
139
290k
        }
140
1.41M
        std::unique_lock<std::mutex> lc(_always_ready_lock);
141
1.41M
        if (_always_ready) {
142
2
            return;
143
2
        }
144
1.41M
        _ready = false;
145
1.41M
    }
146
147
4.29M
    void set_always_ready() {
148
4.29M
        if (_always_ready) {
149
1.93M
            return;
150
1.93M
        }
151
2.36M
        std::unique_lock<std::mutex> lc(_always_ready_lock);
152
2.36M
        if (_always_ready) {
153
0
            return;
154
0
        }
155
2.36M
        _always_ready = true;
156
2.36M
        set_ready();
157
2.36M
    }
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
177k
            : Dependency(id, node_id, std::move(name), true) {}
187
188
17.3k
    void add(uint32_t count = 1) {
189
17.3k
        std::unique_lock<std::mutex> l(_mtx);
190
17.3k
        if (!_counter) {
191
17.3k
            block();
192
17.3k
        }
193
17.3k
        _counter += count;
194
17.3k
    }
195
196
17.3k
    void sub() {
197
17.3k
        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
17.3k
        if (_counter == 0) [[unlikely]] {
202
2
            throw Exception(ErrorCode::INTERNAL_ERROR,
203
2
                            "CountedFinishDependency::sub() underflow on {}", debug_string());
204
2
        }
205
17.3k
        _counter--;
206
17.3k
        if (!_counter) {
207
17.3k
            set_ready();
208
17.3k
        }
209
17.3k
    }
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
40.5k
            : _parent(std::move(parent)),
224
40.5k
              _registration_time(registration_time),
225
40.5k
              _wait_time_ms(wait_time_ms),
226
40.5k
              _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.65M
    int64_t registration_time() const { return _registration_time; }
235
6.65M
    int32_t wait_time_ms() const { return _wait_time_ms; }
236
237
    void set_local_runtime_filter_dependencies(
238
5.75k
            const std::vector<std::shared_ptr<Dependency>>& deps) {
239
5.75k
        _local_runtime_filter_dependencies = deps;
240
5.75k
    }
241
242
    bool should_be_check_timeout();
243
244
6.69M
    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
6
        while (!_shutdown) {
270
3
            std::this_thread::sleep_for(std::chrono::milliseconds(interval));
271
3
        }
272
3
    }
273
274
3
    ~RuntimeFilterTimerQueue() = default;
275
9
    RuntimeFilterTimerQueue() { _thread = std::thread(&RuntimeFilterTimerQueue::start, this); }
276
26.9k
    void push_filter_timer(std::vector<std::shared_ptr<RuntimeFilterTimer>>&& filter) {
277
26.9k
        std::unique_lock<std::mutex> lc(_que_lock);
278
26.9k
        _que.insert(_que.end(), filter.begin(), filter.end());
279
26.9k
        cv.notify_all();
280
26.9k
    }
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
135k
    AggSharedState() { agg_data = std::make_unique<AggregatedDataVariants>(); }
295
135k
    ~AggSharedState() override {
296
135k
        if (!probe_expr_ctxs.empty()) {
297
43.5k
            _close_with_serialized_key();
298
91.7k
        } else {
299
91.7k
            _close_without_key();
300
91.7k
        }
301
135k
    }
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
54.6k
                : _row_id(row_id),
345
54.6k
                  _limit_columns(limit_columns),
346
54.6k
                  _order_directions(order_directions),
347
54.6k
                  _null_directions(null_directions) {}
348
349
        HeapLimitCursor(const HeapLimitCursor& other) = default;
350
351
        HeapLimitCursor(HeapLimitCursor&& other) noexcept
352
347k
                : _row_id(other._row_id),
353
347k
                  _limit_columns(other._limit_columns),
354
347k
                  _order_directions(other._order_directions),
355
347k
                  _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
612k
        HeapLimitCursor& operator=(HeapLimitCursor&& other) noexcept {
363
612k
            _row_id = other._row_id;
364
612k
            return *this;
365
612k
        }
366
367
563k
        bool operator<(const HeapLimitCursor& rhs) const {
368
801k
            for (int i = 0; i < _limit_columns.size(); ++i) {
369
801k
                const auto& _limit_column = _limit_columns[i];
370
801k
                auto res = _limit_column->compare_at(_row_id, rhs._row_id, *_limit_column,
371
801k
                                                     _null_directions[i]) *
372
801k
                           _order_directions[i];
373
801k
                if (res < 0) {
374
275k
                    return true;
375
525k
                } else if (res > 0) {
376
295k
                    return false;
377
295k
                }
378
801k
            }
379
18.4E
            return false;
380
563k
        }
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
43.4k
    void _close_with_serialized_key() {
400
43.4k
        std::visit(Overload {[&](std::monostate& arg) -> void {
401
                                 // Do nothing
402
0
                             },
403
43.5k
                             [&](auto& agg_method) -> void {
404
43.5k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
4.28k
                                     return;
408
4.28k
                                 }
409
39.2k
                                 auto& data = *agg_method.hash_table;
410
1.04M
                                 data.for_each_mapped([&](auto& mapped) {
411
1.04M
                                     if (mapped) {
412
1.04M
                                         _destroy_agg_status(mapped);
413
1.04M
                                         mapped = nullptr;
414
1.04M
                                     }
415
1.04M
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_
Line
Count
Source
410
14.5k
                                 data.for_each_mapped([&](auto& mapped) {
411
14.5k
                                     if (mapped) {
412
14.5k
                                         _destroy_agg_status(mapped);
413
14.5k
                                         mapped = nullptr;
414
14.5k
                                     }
415
14.5k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
410
1.63k
                                 data.for_each_mapped([&](auto& mapped) {
411
1.63k
                                     if (mapped) {
412
1.63k
                                         _destroy_agg_status(mapped);
413
1.63k
                                         mapped = nullptr;
414
1.63k
                                     }
415
1.63k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEvS2_ENKUlS2_E_clISA_EEDaS2_
Line
Count
Source
410
10.7k
                                 data.for_each_mapped([&](auto& mapped) {
411
10.7k
                                     if (mapped) {
412
10.7k
                                         _destroy_agg_status(mapped);
413
10.7k
                                         mapped = nullptr;
414
10.7k
                                     }
415
10.7k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
410
465
                                 data.for_each_mapped([&](auto& mapped) {
411
465
                                     if (mapped) {
412
465
                                         _destroy_agg_status(mapped);
413
465
                                         mapped = nullptr;
414
465
                                     }
415
465
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
410
7.69k
                                 data.for_each_mapped([&](auto& mapped) {
411
7.69k
                                     if (mapped) {
412
7.69k
                                         _destroy_agg_status(mapped);
413
7.69k
                                         mapped = nullptr;
414
7.69k
                                     }
415
7.69k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS7_EEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
410
710
                                 data.for_each_mapped([&](auto& mapped) {
411
710
                                     if (mapped) {
412
710
                                         _destroy_agg_status(mapped);
413
710
                                         mapped = nullptr;
414
710
                                     }
415
710
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
410
71.8k
                                 data.for_each_mapped([&](auto& mapped) {
411
72.0k
                                     if (mapped) {
412
72.0k
                                         _destroy_agg_status(mapped);
413
72.0k
                                         mapped = nullptr;
414
72.0k
                                     }
415
71.8k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
410
3.98k
                                 data.for_each_mapped([&](auto& mapped) {
411
3.98k
                                     if (mapped) {
412
3.98k
                                         _destroy_agg_status(mapped);
413
3.98k
                                         mapped = nullptr;
414
3.98k
                                     }
415
3.98k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ENKUlS2_E_clISC_EEDaS2_
Line
Count
Source
410
6
                                 data.for_each_mapped([&](auto& mapped) {
411
6
                                     if (mapped) {
412
6
                                         _destroy_agg_status(mapped);
413
6
                                         mapped = nullptr;
414
6
                                     }
415
6
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_ENKUlS2_E_clISC_EEDaS2_
Line
Count
Source
410
416
                                 data.for_each_mapped([&](auto& mapped) {
411
416
                                     if (mapped) {
412
416
                                         _destroy_agg_status(mapped);
413
416
                                         mapped = nullptr;
414
416
                                     }
415
416
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
410
109k
                                 data.for_each_mapped([&](auto& mapped) {
411
109k
                                     if (mapped) {
412
109k
                                         _destroy_agg_status(mapped);
413
109k
                                         mapped = nullptr;
414
109k
                                     }
415
109k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
410
107k
                                 data.for_each_mapped([&](auto& mapped) {
411
107k
                                     if (mapped) {
412
107k
                                         _destroy_agg_status(mapped);
413
107k
                                         mapped = nullptr;
414
107k
                                     }
415
107k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
410
7.68k
                                 data.for_each_mapped([&](auto& mapped) {
411
7.68k
                                     if (mapped) {
412
7.68k
                                         _destroy_agg_status(mapped);
413
7.68k
                                         mapped = nullptr;
414
7.68k
                                     }
415
7.68k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
410
39.0k
                                 data.for_each_mapped([&](auto& mapped) {
411
39.0k
                                     if (mapped) {
412
39.0k
                                         _destroy_agg_status(mapped);
413
39.0k
                                         mapped = nullptr;
414
39.0k
                                     }
415
39.0k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
410
1.06k
                                 data.for_each_mapped([&](auto& mapped) {
411
1.06k
                                     if (mapped) {
412
1.06k
                                         _destroy_agg_status(mapped);
413
1.06k
                                         mapped = nullptr;
414
1.06k
                                     }
415
1.06k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS2_ENKUlS2_E_clIS9_EEDaS2_
Line
Count
Source
410
2.46k
                                 data.for_each_mapped([&](auto& mapped) {
411
2.46k
                                     if (mapped) {
412
2.46k
                                         _destroy_agg_status(mapped);
413
2.46k
                                         mapped = nullptr;
414
2.46k
                                     }
415
2.46k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
410
20.7k
                                 data.for_each_mapped([&](auto& mapped) {
411
20.7k
                                     if (mapped) {
412
20.7k
                                         _destroy_agg_status(mapped);
413
20.7k
                                         mapped = nullptr;
414
20.7k
                                     }
415
20.7k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
410
562k
                                 data.for_each_mapped([&](auto& mapped) {
411
564k
                                     if (mapped) {
412
564k
                                         _destroy_agg_status(mapped);
413
564k
                                         mapped = nullptr;
414
564k
                                     }
415
562k
                                 });
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
86
                                 data.for_each_mapped([&](auto& mapped) {
411
86
                                     if (mapped) {
412
86
                                         _destroy_agg_status(mapped);
413
86
                                         mapped = nullptr;
414
86
                                     }
415
86
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
410
1.00k
                                 data.for_each_mapped([&](auto& mapped) {
411
1.00k
                                     if (mapped) {
412
1.00k
                                         _destroy_agg_status(mapped);
413
1.00k
                                         mapped = nullptr;
414
1.00k
                                     }
415
1.00k
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
410
626
                                 data.for_each_mapped([&](auto& mapped) {
411
626
                                     if (mapped) {
412
626
                                         _destroy_agg_status(mapped);
413
626
                                         mapped = nullptr;
414
626
                                     }
415
626
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
410
143
                                 data.for_each_mapped([&](auto& mapped) {
411
143
                                     if (mapped) {
412
143
                                         _destroy_agg_status(mapped);
413
143
                                         mapped = nullptr;
414
143
                                     }
415
143
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
410
25
                                 data.for_each_mapped([&](auto& mapped) {
411
25
                                     if (mapped) {
412
25
                                         _destroy_agg_status(mapped);
413
25
                                         mapped = nullptr;
414
25
                                     }
415
25
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS2_ENKUlS2_E_clIS7_EEDaS2_
Line
Count
Source
410
709
                                 data.for_each_mapped([&](auto& mapped) {
411
709
                                     if (mapped) {
412
709
                                         _destroy_agg_status(mapped);
413
709
                                         mapped = nullptr;
414
709
                                     }
415
709
                                 });
_ZZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEvS2_ENKUlS2_E_clIS8_EEDaS2_
Line
Count
Source
410
82.5k
                                 data.for_each_mapped([&](auto& mapped) {
411
82.5k
                                     if (mapped) {
412
82.5k
                                         _destroy_agg_status(mapped);
413
82.5k
                                         mapped = nullptr;
414
82.5k
                                     }
415
82.5k
                                 });
416
39.2k
                                 if (data.has_null_key_data()) {
417
1.20k
                                     _destroy_agg_status(
418
1.20k
                                             data.template get_null_key_data<AggregateDataPtr>());
419
1.20k
                                 }
420
39.2k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32IS9_EEEEEEvS2_
Line
Count
Source
403
3.18k
                             [&](auto& agg_method) -> void {
404
3.18k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
53
                                     return;
408
53
                                 }
409
3.12k
                                 auto& data = *agg_method.hash_table;
410
3.12k
                                 data.for_each_mapped([&](auto& mapped) {
411
3.12k
                                     if (mapped) {
412
3.12k
                                         _destroy_agg_status(mapped);
413
3.12k
                                         mapped = nullptr;
414
3.12k
                                     }
415
3.12k
                                 });
416
3.12k
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
3.12k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS7_EEEEEEvS2_
Line
Count
Source
403
1.72k
                             [&](auto& agg_method) -> void {
404
1.72k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
109
                                     return;
408
109
                                 }
409
1.61k
                                 auto& data = *agg_method.hash_table;
410
1.61k
                                 data.for_each_mapped([&](auto& mapped) {
411
1.61k
                                     if (mapped) {
412
1.61k
                                         _destroy_agg_status(mapped);
413
1.61k
                                         mapped = nullptr;
414
1.61k
                                     }
415
1.61k
                                 });
416
1.61k
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
1.61k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm128EjEEPc9HashCRC32IS9_EEEEEEvS2_
Line
Count
Source
403
92
                             [&](auto& agg_method) -> void {
404
92
                                 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
81
                                 auto& data = *agg_method.hash_table;
410
81
                                 data.for_each_mapped([&](auto& mapped) {
411
81
                                     if (mapped) {
412
81
                                         _destroy_agg_status(mapped);
413
81
                                         mapped = nullptr;
414
81
                                     }
415
81
                                 });
416
81
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
81
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt104EPc9HashCRC32IS7_EEEEEEvS2_
Line
Count
Source
403
869
                             [&](auto& agg_method) -> void {
404
869
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
127
                                     return;
408
127
                                 }
409
742
                                 auto& data = *agg_method.hash_table;
410
742
                                 data.for_each_mapped([&](auto& mapped) {
411
742
                                     if (mapped) {
412
742
                                         _destroy_agg_status(mapped);
413
742
                                         mapped = nullptr;
414
742
                                     }
415
742
                                 });
416
742
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
742
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt96EPc9HashCRC32IS7_EEEEEEvS2_
Line
Count
Source
403
660
                             [&](auto& agg_method) -> void {
404
660
                                 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
659
                                 auto& data = *agg_method.hash_table;
410
659
                                 data.for_each_mapped([&](auto& mapped) {
411
659
                                     if (mapped) {
412
659
                                         _destroy_agg_status(mapped);
413
659
                                         mapped = nullptr;
414
659
                                     }
415
659
                                 });
416
659
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
659
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_6UInt72EPc9HashCRC32IS7_EEEEEEvS2_
Line
Count
Source
403
853
                             [&](auto& agg_method) -> void {
404
853
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
76
                                     return;
408
76
                                 }
409
777
                                 auto& data = *agg_method.hash_table;
410
777
                                 data.for_each_mapped([&](auto& mapped) {
411
777
                                     if (mapped) {
412
777
                                         _destroy_agg_status(mapped);
413
777
                                         mapped = nullptr;
414
777
                                     }
415
777
                                 });
416
777
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
777
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapImPc9HashCRC32ImEEEEEEvS2_
Line
Count
Source
403
836
                             [&](auto& agg_method) -> void {
404
836
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
37
                                     return;
408
37
                                 }
409
799
                                 auto& data = *agg_method.hash_table;
410
799
                                 data.for_each_mapped([&](auto& mapped) {
411
799
                                     if (mapped) {
412
799
                                         _destroy_agg_status(mapped);
413
799
                                         mapped = nullptr;
414
799
                                     }
415
799
                                 });
416
799
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
799
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_19MethodStringNoCacheINS_15DataWithNullKeyINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEEEEEvS2_
Line
Count
Source
403
2.81k
                             [&](auto& agg_method) -> void {
404
2.81k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
628
                                     return;
408
628
                                 }
409
2.18k
                                 auto& data = *agg_method.hash_table;
410
2.18k
                                 data.for_each_mapped([&](auto& mapped) {
411
2.18k
                                     if (mapped) {
412
2.18k
                                         _destroy_agg_status(mapped);
413
2.18k
                                         mapped = nullptr;
414
2.18k
                                     }
415
2.18k
                                 });
416
2.18k
                                 if (data.has_null_key_data()) {
417
41
                                     _destroy_agg_status(
418
41
                                             data.template get_null_key_data<AggregateDataPtr>());
419
41
                                 }
420
2.18k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm256EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_
Line
Count
Source
403
8
                             [&](auto& agg_method) -> void {
404
8
                                 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
8
                                 auto& data = *agg_method.hash_table;
410
8
                                 data.for_each_mapped([&](auto& mapped) {
411
8
                                     if (mapped) {
412
8
                                         _destroy_agg_status(mapped);
413
8
                                         mapped = nullptr;
414
8
                                     }
415
8
                                 });
416
8
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
8
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIN4wide7integerILm128EjEENS_15DataWithNullKeyI9PHHashMapIS9_Pc9HashCRC32IS9_EEEEEEEEEEvS2_
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
0
                                     return;
408
0
                                 }
409
416
                                 auto& data = *agg_method.hash_table;
410
416
                                 data.for_each_mapped([&](auto& mapped) {
411
416
                                     if (mapped) {
412
416
                                         _destroy_agg_status(mapped);
413
416
                                         mapped = nullptr;
414
416
                                     }
415
416
                                 });
416
416
                                 if (data.has_null_key_data()) {
417
5
                                     _destroy_agg_status(
418
5
                                             data.template get_null_key_data<AggregateDataPtr>());
419
5
                                 }
420
416
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEEEEEvS2_
Line
Count
Source
403
4.89k
                             [&](auto& agg_method) -> void {
404
4.89k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
652
                                     return;
408
652
                                 }
409
4.23k
                                 auto& data = *agg_method.hash_table;
410
4.23k
                                 data.for_each_mapped([&](auto& mapped) {
411
4.23k
                                     if (mapped) {
412
4.23k
                                         _destroy_agg_status(mapped);
413
4.23k
                                         mapped = nullptr;
414
4.23k
                                     }
415
4.23k
                                 });
416
4.23k
                                 if (data.has_null_key_data()) {
417
148
                                     _destroy_agg_status(
418
148
                                             data.template get_null_key_data<AggregateDataPtr>());
419
148
                                 }
420
4.23k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEEEEEvS2_
Line
Count
Source
403
9.32k
                             [&](auto& agg_method) -> void {
404
9.32k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
776
                                     return;
408
776
                                 }
409
8.54k
                                 auto& data = *agg_method.hash_table;
410
8.54k
                                 data.for_each_mapped([&](auto& mapped) {
411
8.54k
                                     if (mapped) {
412
8.54k
                                         _destroy_agg_status(mapped);
413
8.54k
                                         mapped = nullptr;
414
8.54k
                                     }
415
8.54k
                                 });
416
8.54k
                                 if (data.has_null_key_data()) {
417
410
                                     _destroy_agg_status(
418
410
                                             data.template get_null_key_data<AggregateDataPtr>());
419
410
                                 }
420
8.54k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberImNS_15DataWithNullKeyI9PHHashMapImPc9HashCRC32ImEEEEEEEEEEvS2_
Line
Count
Source
403
429
                             [&](auto& agg_method) -> void {
404
429
                                 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
418
                                 auto& data = *agg_method.hash_table;
410
418
                                 data.for_each_mapped([&](auto& mapped) {
411
418
                                     if (mapped) {
412
418
                                         _destroy_agg_status(mapped);
413
418
                                         mapped = nullptr;
414
418
                                     }
415
418
                                 });
416
418
                                 if (data.has_null_key_data()) {
417
43
                                     _destroy_agg_status(
418
43
                                             data.template get_null_key_data<AggregateDataPtr>());
419
43
                                 }
420
418
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS2_
Line
Count
Source
403
960
                             [&](auto& agg_method) -> void {
404
960
                                 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
934
                                 auto& data = *agg_method.hash_table;
410
934
                                 data.for_each_mapped([&](auto& mapped) {
411
934
                                     if (mapped) {
412
934
                                         _destroy_agg_status(mapped);
413
934
                                         mapped = nullptr;
414
934
                                     }
415
934
                                 });
416
934
                                 if (data.has_null_key_data()) {
417
30
                                     _destroy_agg_status(
418
30
                                             data.template get_null_key_data<AggregateDataPtr>());
419
30
                                 }
420
934
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS2_
Line
Count
Source
403
610
                             [&](auto& agg_method) -> void {
404
610
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
25
                                     return;
408
25
                                 }
409
585
                                 auto& data = *agg_method.hash_table;
410
585
                                 data.for_each_mapped([&](auto& mapped) {
411
585
                                     if (mapped) {
412
585
                                         _destroy_agg_status(mapped);
413
585
                                         mapped = nullptr;
414
585
                                     }
415
585
                                 });
416
585
                                 if (data.has_null_key_data()) {
417
22
                                     _destroy_agg_status(
418
22
                                             data.template get_null_key_data<AggregateDataPtr>());
419
22
                                 }
420
585
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIhNS_15DataWithNullKeyI9PHHashMapIhPc9HashCRC32IhEEEEEEEEEEvS2_
Line
Count
Source
403
2.44k
                             [&](auto& agg_method) -> void {
404
2.44k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
289
                                     return;
408
289
                                 }
409
2.15k
                                 auto& data = *agg_method.hash_table;
410
2.15k
                                 data.for_each_mapped([&](auto& mapped) {
411
2.15k
                                     if (mapped) {
412
2.15k
                                         _destroy_agg_status(mapped);
413
2.15k
                                         mapped = nullptr;
414
2.15k
                                     }
415
2.15k
                                 });
416
2.15k
                                 if (data.has_null_key_data()) {
417
505
                                     _destroy_agg_status(
418
505
                                             data.template get_null_key_data<AggregateDataPtr>());
419
505
                                 }
420
2.15k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc14HashMixWrapperIm9HashCRC32ImEEEEEEEvS2_
Line
Count
Source
403
1.53k
                             [&](auto& agg_method) -> void {
404
1.53k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
521
                                     return;
408
521
                                 }
409
1.00k
                                 auto& data = *agg_method.hash_table;
410
1.00k
                                 data.for_each_mapped([&](auto& mapped) {
411
1.00k
                                     if (mapped) {
412
1.00k
                                         _destroy_agg_status(mapped);
413
1.00k
                                         mapped = nullptr;
414
1.00k
                                     }
415
1.00k
                                 });
416
1.00k
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
1.00k
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc14HashMixWrapperIj9HashCRC32IjEEEEEEEvS2_
Line
Count
Source
403
2.31k
                             [&](auto& agg_method) -> void {
404
2.31k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
66
                                     return;
408
66
                                 }
409
2.24k
                                 auto& data = *agg_method.hash_table;
410
2.24k
                                 data.for_each_mapped([&](auto& mapped) {
411
2.24k
                                     if (mapped) {
412
2.24k
                                         _destroy_agg_status(mapped);
413
2.24k
                                         mapped = nullptr;
414
2.24k
                                     }
415
2.24k
                                 });
416
2.24k
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
2.24k
                             }},
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
111
                             [&](auto& agg_method) -> void {
404
111
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
8
                                     return;
408
8
                                 }
409
103
                                 auto& data = *agg_method.hash_table;
410
103
                                 data.for_each_mapped([&](auto& mapped) {
411
103
                                     if (mapped) {
412
103
                                         _destroy_agg_status(mapped);
413
103
                                         mapped = nullptr;
414
103
                                     }
415
103
                                 });
416
103
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
103
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_19MethodStringNoCacheINS_13StringHashMapIPcNS_9AllocatorILb1ELb1ELb0ENS_22DefaultMemoryAllocatorELb1EEEEEEEEEvS2_
Line
Count
Source
403
874
                             [&](auto& agg_method) -> void {
404
874
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
174
                                     return;
408
174
                                 }
409
700
                                 auto& data = *agg_method.hash_table;
410
700
                                 data.for_each_mapped([&](auto& mapped) {
411
700
                                     if (mapped) {
412
700
                                         _destroy_agg_status(mapped);
413
700
                                         mapped = nullptr;
414
700
                                     }
415
700
                                 });
416
700
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
700
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS2_
Line
Count
Source
403
234
                             [&](auto& agg_method) -> void {
404
234
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
82
                                     return;
408
82
                                 }
409
152
                                 auto& data = *agg_method.hash_table;
410
152
                                 data.for_each_mapped([&](auto& mapped) {
411
152
                                     if (mapped) {
412
152
                                         _destroy_agg_status(mapped);
413
152
                                         mapped = nullptr;
414
152
                                     }
415
152
                                 });
416
152
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
152
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS2_
Line
Count
Source
403
119
                             [&](auto& agg_method) -> void {
404
119
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
16
                                     return;
408
16
                                 }
409
103
                                 auto& data = *agg_method.hash_table;
410
103
                                 data.for_each_mapped([&](auto& mapped) {
411
103
                                     if (mapped) {
412
103
                                         _destroy_agg_status(mapped);
413
103
                                         mapped = nullptr;
414
103
                                     }
415
103
                                 });
416
103
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
103
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS2_
Line
Count
Source
403
15
                             [&](auto& agg_method) -> void {
404
15
                                 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
15
                                 auto& data = *agg_method.hash_table;
410
15
                                 data.for_each_mapped([&](auto& mapped) {
411
15
                                     if (mapped) {
412
15
                                         _destroy_agg_status(mapped);
413
15
                                         mapped = nullptr;
414
15
                                     }
415
15
                                 });
416
15
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
15
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS2_
Line
Count
Source
403
493
                             [&](auto& agg_method) -> void {
404
493
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
5
                                     return;
408
5
                                 }
409
488
                                 auto& data = *agg_method.hash_table;
410
488
                                 data.for_each_mapped([&](auto& mapped) {
411
488
                                     if (mapped) {
412
488
                                         _destroy_agg_status(mapped);
413
488
                                         mapped = nullptr;
414
488
                                     }
415
488
                                 });
416
488
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
488
                             }},
_ZZN5doris14AggSharedState26_close_with_serialized_keyEvENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS7_vEEEEEEvS2_
Line
Count
Source
403
7.73k
                             [&](auto& agg_method) -> void {
404
7.73k
                                 if (use_simple_count) {
405
                                     // Inline count: mapped slots hold UInt64,
406
                                     // not real agg state pointers. Skip destroy.
407
590
                                     return;
408
590
                                 }
409
7.14k
                                 auto& data = *agg_method.hash_table;
410
7.14k
                                 data.for_each_mapped([&](auto& mapped) {
411
7.14k
                                     if (mapped) {
412
7.14k
                                         _destroy_agg_status(mapped);
413
7.14k
                                         mapped = nullptr;
414
7.14k
                                     }
415
7.14k
                                 });
416
7.14k
                                 if (data.has_null_key_data()) {
417
0
                                     _destroy_agg_status(
418
0
                                             data.template get_null_key_data<AggregateDataPtr>());
419
0
                                 }
420
7.14k
                             }},
421
43.4k
                   agg_data->method_variant);
422
43.4k
    }
423
424
91.8k
    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
91.9k
        if (agg_data_created_without_key) {
429
91.9k
            _destroy_agg_status(agg_data->without_key);
430
91.9k
            agg_data_created_without_key = false;
431
91.9k
        }
432
91.8k
    }
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
65
    BucketedAggSharedState() = default;
461
65
    ~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
315
        PerInstanceData() : arena(std::make_unique<Arena>()) {
472
315
            bucket_agg_data.resize(BUCKETED_AGG_NUM_BUCKETS);
473
80.6k
            for (auto& p : bucket_agg_data) {
474
80.6k
                p = std::make_unique<BucketedAggDataVariants>();
475
80.6k
            }
476
315
        }
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
313
    Status init_instances(int num_instances, Func&& metadata_init) {
545
313
        std::call_once(_init_once, [&]() {
546
65
            num_sink_instances = num_instances;
547
65
            per_instance_data.resize(num_instances);
548
65
            sink_finished = std::make_unique<std::atomic<bool>[]>(num_instances);
549
380
            for (int i = 0; i < num_instances; ++i) {
550
315
                sink_finished[i].store(false, std::memory_order_relaxed);
551
315
            }
552
16.6k
            for (auto& bs : bucket_states) {
553
16.6k
                bs.merged_instances.resize(num_instances, false);
554
16.6k
            }
555
65
            _init_status = std::forward<Func>(metadata_init)();
556
65
        });
557
313
        return _init_status;
558
313
    }
559
560
private:
561
    std::once_flag _init_once;
562
    Status _init_status;
563
564
65
    void _close() {
565
315
        for (auto& inst : per_instance_data) {
566
80.6k
            for (auto& bucket_data : inst.bucket_agg_data) {
567
80.6k
                _close_one_agg_data(*bucket_data);
568
80.6k
            }
569
315
        }
570
65
    }
571
572
80.6k
    void _close_one_agg_data(BucketedAggDataVariants& agg_data) {
573
80.6k
        std::visit(
574
80.6k
                Overload {[&](std::monostate& arg) -> void {
575
                              // Do nothing
576
0
                          },
577
80.6k
                          [&](auto& agg_method) -> void {
578
80.6k
                              if (use_simple_count) {
579
                                  // simple_count: mapped slots hold UInt64 counters,
580
                                  // not real agg state pointers. Skip destroy.
581
6.14k
                                  return;
582
6.14k
                              }
583
74.4k
                              auto& data = *agg_method.hash_table;
584
74.4k
                              data.for_each_mapped([&](auto& mapped) {
585
58.1k
                                  if (mapped) {
586
31.3k
                                      _destroy_agg_status(mapped);
587
31.3k
                                      mapped = nullptr;
588
31.3k
                                  }
589
58.1k
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32ISB_EEEEEEvS4_ENKUlS4_E_clISC_EEDaS4_
Line
Count
Source
584
72
                              data.for_each_mapped([&](auto& mapped) {
585
72
                                  if (mapped) {
586
36
                                      _destroy_agg_status(mapped);
587
36
                                      mapped = nullptr;
588
36
                                  }
589
72
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS9_EEEEEEvS4_ENKUlS4_E_clISA_EEDaS4_
Line
Count
Source
584
61
                              data.for_each_mapped([&](auto& mapped) {
585
61
                                  if (mapped) {
586
34
                                      _destroy_agg_status(mapped);
587
34
                                      mapped = nullptr;
588
34
                                  }
589
61
                              });
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
443
                              data.for_each_mapped([&](auto& mapped) {
585
443
                                  if (mapped) {
586
443
                                      _destroy_agg_status(mapped);
587
443
                                      mapped = nullptr;
588
443
                                  }
589
443
                              });
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
28
                              data.for_each_mapped([&](auto& mapped) {
585
28
                                  if (mapped) {
586
18
                                      _destroy_agg_status(mapped);
587
18
                                      mapped = nullptr;
588
18
                                  }
589
28
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS4_ENKUlS4_E_clISB_EEDaS4_
Line
Count
Source
584
30
                              data.for_each_mapped([&](auto& mapped) {
585
30
                                  if (mapped) {
586
26
                                      _destroy_agg_status(mapped);
587
26
                                      mapped = nullptr;
588
26
                                  }
589
30
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS4_ENKUlS4_E_clISB_EEDaS4_
Line
Count
Source
584
10
                              data.for_each_mapped([&](auto& mapped) {
585
10
                                  if (mapped) {
586
2
                                      _destroy_agg_status(mapped);
587
2
                                      mapped = nullptr;
588
2
                                  }
589
10
                              });
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
167
                              data.for_each_mapped([&](auto& mapped) {
585
167
                                  if (mapped) {
586
22
                                      _destroy_agg_status(mapped);
587
22
                                      mapped = nullptr;
588
22
                                  }
589
167
                              });
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
54.0k
                              data.for_each_mapped([&](auto& mapped) {
585
54.0k
                                  if (mapped) {
586
30.0k
                                      _destroy_agg_status(mapped);
587
30.0k
                                      mapped = nullptr;
588
30.0k
                                  }
589
54.0k
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS4_ENKUlS4_E_clIS9_EEDaS4_
Line
Count
Source
584
34
                              data.for_each_mapped([&](auto& mapped) {
585
34
                                  if (mapped) {
586
6
                                      _destroy_agg_status(mapped);
587
6
                                      mapped = nullptr;
588
6
                                  }
589
34
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS4_ENKUlS4_E_clIS9_EEDaS4_
Line
Count
Source
584
6
                              data.for_each_mapped([&](auto& mapped) {
585
6
                                  if (mapped) {
586
2
                                      _destroy_agg_status(mapped);
587
2
                                      mapped = nullptr;
588
2
                                  }
589
6
                              });
_ZZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS9_vEEEEEEvS4_ENKUlS4_E_clISA_EEDaS4_
Line
Count
Source
584
3.24k
                              data.for_each_mapped([&](auto& mapped) {
585
3.24k
                                  if (mapped) {
586
724
                                      _destroy_agg_status(mapped);
587
724
                                      mapped = nullptr;
588
724
                                  }
589
3.24k
                              });
590
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
591
11.0k
                                                                 bool>) {
592
11.0k
                                  if (data.has_null_key_data()) {
593
3
                                      _destroy_agg_status(
594
3
                                              data.template get_null_key_data<AggregateDataPtr>());
595
3
                                  }
596
11.0k
                              }
597
74.4k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapIN4wide7integerILm256EjEEPc9HashCRC32ISB_EEEEEEvS4_
Line
Count
Source
577
2.56k
                          [&](auto& agg_method) -> void {
578
2.56k
                              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
2.56k
                              auto& data = *agg_method.hash_table;
584
2.56k
                              data.for_each_mapped([&](auto& mapped) {
585
2.56k
                                  if (mapped) {
586
2.56k
                                      _destroy_agg_status(mapped);
587
2.56k
                                      mapped = nullptr;
588
2.56k
                                  }
589
2.56k
                              });
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
2.56k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodKeysFixedI9PHHashMapINS_7UInt136EPc9HashCRC32IS9_EEEEEEvS4_
Line
Count
Source
577
12.5k
                          [&](auto& agg_method) -> void {
578
12.5k
                              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
12.5k
                              auto& data = *agg_method.hash_table;
584
12.5k
                              data.for_each_mapped([&](auto& mapped) {
585
12.5k
                                  if (mapped) {
586
12.5k
                                      _destroy_agg_status(mapped);
587
12.5k
                                      mapped = nullptr;
588
12.5k
                                  }
589
12.5k
                              });
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
12.5k
                          }},
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
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
256
                                                                 bool>) {
592
256
                                  if (data.has_null_key_data()) {
593
0
                                      _destroy_agg_status(
594
0
                                              data.template get_null_key_data<AggregateDataPtr>());
595
0
                                  }
596
256
                              }
597
256
                          }},
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
6.40k
                          [&](auto& agg_method) -> void {
578
6.40k
                              if (use_simple_count) {
579
                                  // simple_count: mapped slots hold UInt64 counters,
580
                                  // not real agg state pointers. Skip destroy.
581
1.53k
                                  return;
582
1.53k
                              }
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
4.86k
                                                                 bool>) {
592
4.86k
                                  if (data.has_null_key_data()) {
593
3
                                      _destroy_agg_status(
594
3
                                              data.template get_null_key_data<AggregateDataPtr>());
595
3
                                  }
596
4.86k
                              }
597
4.86k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberIjNS_15DataWithNullKeyI9PHHashMapIjPc9HashCRC32IjEEEEEEEEEEvS4_
Line
Count
Source
577
4.60k
                          [&](auto& agg_method) -> void {
578
4.60k
                              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.60k
                              auto& data = *agg_method.hash_table;
584
4.60k
                              data.for_each_mapped([&](auto& mapped) {
585
4.60k
                                  if (mapped) {
586
4.60k
                                      _destroy_agg_status(mapped);
587
4.60k
                                      mapped = nullptr;
588
4.60k
                                  }
589
4.60k
                              });
590
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
591
4.60k
                                                                 bool>) {
592
4.60k
                                  if (data.has_null_key_data()) {
593
0
                                      _destroy_agg_status(
594
0
                                              data.template get_null_key_data<AggregateDataPtr>());
595
0
                                  }
596
4.60k
                              }
597
4.60k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_26MethodSingleNullableColumnINS_15MethodOneNumberItNS_15DataWithNullKeyI9PHHashMapItPc9HashCRC32ItEEEEEEEEEEvS4_
Line
Count
Source
577
1.28k
                          [&](auto& agg_method) -> void {
578
1.28k
                              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.28k
                              auto& data = *agg_method.hash_table;
584
1.28k
                              data.for_each_mapped([&](auto& mapped) {
585
1.28k
                                  if (mapped) {
586
1.28k
                                      _destroy_agg_status(mapped);
587
1.28k
                                      mapped = nullptr;
588
1.28k
                                  }
589
1.28k
                              });
590
                              if constexpr (std::is_assignable_v<decltype(data.has_null_key_data()),
591
1.28k
                                                                 bool>) {
592
1.28k
                                  if (data.has_null_key_data()) {
593
0
                                      _destroy_agg_status(
594
0
                                              data.template get_null_key_data<AggregateDataPtr>());
595
0
                                  }
596
1.28k
                              }
597
1.28k
                          }},
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
21.2k
                          [&](auto& agg_method) -> void {
578
21.2k
                              if (use_simple_count) {
579
                                  // simple_count: mapped slots hold UInt64 counters,
580
                                  // not real agg state pointers. Skip destroy.
581
4.09k
                                  return;
582
4.09k
                              }
583
17.1k
                              auto& data = *agg_method.hash_table;
584
17.1k
                              data.for_each_mapped([&](auto& mapped) {
585
17.1k
                                  if (mapped) {
586
17.1k
                                      _destroy_agg_status(mapped);
587
17.1k
                                      mapped = nullptr;
588
17.1k
                                  }
589
17.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
17.1k
                          }},
Unexecuted instantiation: _ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIm9PHHashMapImPc9HashCRC32ImEEEEEEvS4_
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIj9PHHashMapIjPc9HashCRC32IjEEEEEEvS4_
Line
Count
Source
577
5.37k
                          [&](auto& agg_method) -> void {
578
5.37k
                              if (use_simple_count) {
579
                                  // simple_count: mapped slots hold UInt64 counters,
580
                                  // not real agg state pointers. Skip destroy.
581
512
                                  return;
582
512
                              }
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
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIt9PHHashMapItPc9HashCRC32ItEEEEEEvS4_
Line
Count
Source
577
7.68k
                          [&](auto& agg_method) -> void {
578
7.68k
                              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
7.68k
                              auto& data = *agg_method.hash_table;
584
7.68k
                              data.for_each_mapped([&](auto& mapped) {
585
7.68k
                                  if (mapped) {
586
7.68k
                                      _destroy_agg_status(mapped);
587
7.68k
                                      mapped = nullptr;
588
7.68k
                                  }
589
7.68k
                              });
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
7.68k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_15MethodOneNumberIh9PHHashMapIhPc9HashCRC32IhEEEEEEvS4_
Line
Count
Source
577
2.56k
                          [&](auto& agg_method) -> void {
578
2.56k
                              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
2.56k
                              auto& data = *agg_method.hash_table;
584
2.56k
                              data.for_each_mapped([&](auto& mapped) {
585
2.56k
                                  if (mapped) {
586
2.56k
                                      _destroy_agg_status(mapped);
587
2.56k
                                      mapped = nullptr;
588
2.56k
                                  }
589
2.56k
                              });
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
2.56k
                          }},
_ZZN5doris22BucketedAggSharedState19_close_one_agg_dataERNS_23BucketedAggDataVariantsEENKUlRT_E_clINS_16MethodSerializedI9PHHashMapINS_9StringRefEPc11DefaultHashIS9_vEEEEEEvS4_
Line
Count
Source
577
15.8k
                          [&](auto& agg_method) -> void {
578
15.8k
                              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
15.8k
                              auto& data = *agg_method.hash_table;
584
15.8k
                              data.for_each_mapped([&](auto& mapped) {
585
15.8k
                                  if (mapped) {
586
15.8k
                                      _destroy_agg_status(mapped);
587
15.8k
                                      mapped = nullptr;
588
15.8k
                                  }
589
15.8k
                              });
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
15.8k
                          }},
598
80.6k
                agg_data.method_variant);
599
80.6k
    }
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
248
    PartitionedAggSharedState() = default;
609
248
    ~PartitionedAggSharedState() override = default;
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
    std::deque<SpillFileSPtr> _spill_partitions;
619
};
620
621
struct SortSharedState : public BasicSharedState {
622
    ENABLE_FACTORY_CREATOR(SortSharedState)
623
public:
624
    std::shared_ptr<Sorter> sorter;
625
};
626
627
struct SpillSortSharedState : public BasicSharedState,
628
                              public std::enable_shared_from_this<SpillSortSharedState> {
629
    ENABLE_FACTORY_CREATOR(SpillSortSharedState)
630
631
45
    SpillSortSharedState() = default;
632
44
    ~SpillSortSharedState() override = default;
633
634
587
    void update_spill_block_batch_row_count(RuntimeState* state, const Block* block) {
635
587
        auto rows = block->rows();
636
587
        if (rows > 0 && 0 == avg_row_bytes) {
637
19
            avg_row_bytes = std::max((std::size_t)1, block->bytes() / rows);
638
19
            spill_block_batch_row_count =
639
19
                    (state->spill_buffer_size_bytes() + avg_row_bytes - 1) / avg_row_bytes;
640
19
            LOG(INFO) << "spill sort block batch row count: " << spill_block_batch_row_count;
641
19
        }
642
587
    }
643
644
    void close();
645
646
    SortSharedState* in_mem_shared_state = nullptr;
647
    bool enable_spill = false;
648
    bool is_spilled = false;
649
    int64_t limit = -1;
650
    int64_t offset = 0;
651
    std::atomic_bool is_closed = false;
652
    std::shared_ptr<BasicSharedState> in_mem_shared_state_sptr;
653
654
    std::deque<SpillFileSPtr> sorted_spill_groups;
655
    size_t avg_row_bytes = 0;
656
    size_t spill_block_batch_row_count;
657
};
658
659
struct UnionSharedState : public BasicSharedState {
660
    ENABLE_FACTORY_CREATOR(UnionSharedState)
661
662
public:
663
3.90k
    UnionSharedState(int child_count = 1) : data_queue(child_count), _child_count(child_count) {};
664
0
    int child_count() const { return _child_count; }
665
    DataQueue data_queue;
666
    const int _child_count;
667
};
668
669
struct DataQueueSharedState : public BasicSharedState {
670
    ENABLE_FACTORY_CREATOR(DataQueueSharedState)
671
public:
672
    DataQueue data_queue;
673
};
674
675
class MultiCastDataStreamer;
676
677
struct MultiCastSharedState : public BasicSharedState,
678
                              public std::enable_shared_from_this<MultiCastSharedState> {
679
    MultiCastSharedState(ObjectPool* pool, int cast_sender_count, int node_id);
680
681
    std::unique_ptr<MultiCastDataStreamer> multi_cast_data_streamer;
682
};
683
684
struct AnalyticSharedState : public BasicSharedState {
685
    ENABLE_FACTORY_CREATOR(AnalyticSharedState)
686
687
public:
688
7.49k
    AnalyticSharedState() = default;
689
    std::queue<Block> blocks_buffer GUARDED_BY(buffer_mutex);
690
    AnnotatedMutex buffer_mutex;
691
    bool sink_eos GUARDED_BY(sink_eos_lock) = false;
692
    AnnotatedMutex sink_eos_lock;
693
    Arena agg_arena_pool;
694
};
695
696
struct JoinSharedState : public BasicSharedState {
697
    // For some join case, we can apply a short circuit strategy
698
    // 1. _has_null_in_build_side = true
699
    // 2. build side rows is empty, Join op is: inner join/right outer join/left semi/right semi/right anti
700
    bool _has_null_in_build_side = false;
701
    bool short_circuit_for_probe = false;
702
    // for some join, when build side rows is empty, we could return directly by add some additional null data in probe table.
703
    bool empty_right_table_need_probe_dispose = false;
704
    JoinOpVariants join_op_variants;
705
};
706
707
struct HashJoinSharedState : public JoinSharedState {
708
    ENABLE_FACTORY_CREATOR(HashJoinSharedState)
709
132k
    HashJoinSharedState() {
710
132k
        hash_table_variant_vector.push_back(std::make_shared<JoinDataVariants>());
711
132k
    }
712
4.39k
    HashJoinSharedState(int num_instances) {
713
4.39k
        source_deps.resize(num_instances, nullptr);
714
4.39k
        hash_table_variant_vector.resize(num_instances, nullptr);
715
21.2k
        for (int i = 0; i < num_instances; i++) {
716
16.8k
            hash_table_variant_vector[i] = std::make_shared<JoinDataVariants>();
717
16.8k
        }
718
4.39k
    }
719
    std::shared_ptr<Arena> arena = std::make_shared<Arena>();
720
721
    const std::vector<TupleDescriptor*> build_side_child_desc;
722
    size_t build_exprs_size = 0;
723
    std::shared_ptr<Block> build_block;
724
    std::shared_ptr<std::vector<uint32_t>> build_indexes_null;
725
726
    // Used by shared hash table
727
    // For probe operator, hash table in _hash_table_variants is read-only if visited flags is not
728
    // used. (visited flags will be used only in right / full outer join).
729
    //
730
    // For broadcast join, although hash table is read-only, some states in `_hash_table_variants`
731
    // are still could be written. For example, serialized keys will be written in a continuous
732
    // memory in `_hash_table_variants`. So before execution, we should use a local _hash_table_variants
733
    // which has a shared hash table in it.
734
    std::vector<std::shared_ptr<JoinDataVariants>> hash_table_variant_vector;
735
736
    // whether left semi join could directly return
737
    // if runtime filters contains local in filter, we can make sure all input rows are matched
738
    // local filter will always be applied, and in filter could guarantee precise filtering
739
    // ATTN: we should disable always_true logic for in filter when we set this flag
740
    bool left_semi_direct_return = false;
741
742
    // ASOF JOIN specific fields
743
    // Whether the inequality is >= or > (true) vs <= or < (false)
744
    bool asof_inequality_is_greater = true;
745
    // Whether the inequality is strict (> or <) vs non-strict (>= or <=)
746
    bool asof_inequality_is_strict = false;
747
748
    // ASOF JOIN pre-sorted index with inline values for O(log K) branchless lookup
749
    // Typed AsofIndexGroups stored in a variant (uint32_t for DateV2, uint64_t for DateTimeV2/TimestampTZ)
750
    AsofIndexVariant asof_index_groups;
751
    // build_row_index -> bucket_id for O(1) reverse lookup
752
    std::vector<uint32_t> asof_build_row_to_bucket;
753
};
754
755
struct PartitionedHashJoinSharedState
756
        : public HashJoinSharedState,
757
          public std::enable_shared_from_this<PartitionedHashJoinSharedState> {
758
    ENABLE_FACTORY_CREATOR(PartitionedHashJoinSharedState)
759
760
    std::unique_ptr<RuntimeState> _inner_runtime_state;
761
    std::shared_ptr<HashJoinSharedState> _inner_shared_state;
762
    std::vector<std::unique_ptr<MutableBlock>> _partitioned_build_blocks;
763
    std::vector<SpillFileSPtr> _spilled_build_groups;
764
    std::atomic<bool> _is_spilled = false;
765
};
766
767
struct NestedLoopJoinSharedState : public JoinSharedState {
768
    ENABLE_FACTORY_CREATOR(NestedLoopJoinSharedState)
769
    // if true, probe child has no more rows to process
770
    bool probe_side_eos = false;
771
    // Visited flags for each row in build side.
772
    MutableColumns build_side_visited_flags;
773
    // List of build blocks, constructed in prepare()
774
    Blocks build_blocks;
775
};
776
777
struct PartitionSortNodeSharedState : public BasicSharedState {
778
    ENABLE_FACTORY_CREATOR(PartitionSortNodeSharedState)
779
public:
780
    std::queue<Block> blocks_buffer GUARDED_BY(buffer_mutex);
781
    AnnotatedMutex buffer_mutex;
782
    std::vector<std::unique_ptr<PartitionSorter>> partition_sorts;
783
    bool sink_eos GUARDED_BY(sink_eos_lock) = false;
784
    AnnotatedMutex sink_eos_lock;
785
    AnnotatedMutex prepared_finish_lock;
786
};
787
788
struct SetSharedState : public BasicSharedState {
789
    ENABLE_FACTORY_CREATOR(SetSharedState)
790
public:
791
    /// default init
792
    Block build_block; // build to source
793
    //record element size in hashtable
794
    int64_t valid_element_in_hash_tbl = 0;
795
    //first: idx mapped to column types
796
    //second: column_id, could point to origin column or cast column
797
    std::unordered_map<int, int> build_col_idx;
798
799
    //// shared static states (shared, decided in prepare/open...)
800
801
    /// init in setup_local_state
802
    std::unique_ptr<SetDataVariants> hash_table_variants =
803
            std::make_unique<SetDataVariants>(); // the real data HERE.
804
    std::vector<bool> build_not_ignore_null;
805
806
    // The SET operator's child might have different nullable attributes.
807
    // If a calculation involves both nullable and non-nullable columns, the final output should be a nullable column
808
    Status update_build_not_ignore_null(const VExprContextSPtrs& ctxs);
809
810
    size_t get_hash_table_size() const;
811
    /// init in both upstream side.
812
    //The i-th result expr list refers to the i-th child.
813
    std::vector<VExprContextSPtrs> child_exprs_lists;
814
815
    /// init in build side
816
    size_t child_quantity;
817
    VExprContextSPtrs build_child_exprs;
818
    std::vector<Dependency*> probe_finished_children_dependency;
819
820
    /// init in probe side
821
    std::vector<VExprContextSPtrs> probe_child_exprs_lists;
822
823
    std::atomic<bool> ready_for_read = false;
824
825
    Arena arena;
826
827
    /// called in setup_local_state
828
    Status hash_table_init();
829
};
830
831
enum class ExchangeType : uint8_t {
832
    NOOP = 0,
833
    // Shuffle data by Crc32CHashPartitioner
834
    HASH_SHUFFLE = 1,
835
    // Round-robin passthrough data blocks.
836
    PASSTHROUGH = 2,
837
    // Shuffle data by Crc32HashPartitioner<ShuffleChannelIds> (e.g. same as storage engine).
838
    BUCKET_HASH_SHUFFLE = 3,
839
    // Passthrough data blocks to all channels.
840
    BROADCAST = 4,
841
    // Passthrough data to channels evenly in an adaptive way.
842
    ADAPTIVE_PASSTHROUGH = 5,
843
    // Send all data to the first channel.
844
    PASS_TO_ONE = 6,
845
};
846
847
232k
inline std::string get_exchange_type_name(ExchangeType idx) {
848
232k
    switch (idx) {
849
14
    case ExchangeType::NOOP:
850
14
        return "NOOP";
851
28.9k
    case ExchangeType::HASH_SHUFFLE:
852
28.9k
        return "HASH_SHUFFLE";
853
194k
    case ExchangeType::PASSTHROUGH:
854
194k
        return "PASSTHROUGH";
855
980
    case ExchangeType::BUCKET_HASH_SHUFFLE:
856
980
        return "BUCKET_HASH_SHUFFLE";
857
740
    case ExchangeType::BROADCAST:
858
740
        return "BROADCAST";
859
1.81k
    case ExchangeType::ADAPTIVE_PASSTHROUGH:
860
1.81k
        return "ADAPTIVE_PASSTHROUGH";
861
5.42k
    case ExchangeType::PASS_TO_ONE:
862
5.42k
        return "PASS_TO_ONE";
863
232k
    }
864
0
    throw Exception(Status::FatalError("__builtin_unreachable"));
865
232k
}
866
867
struct DataDistribution {
868
2.70M
    DataDistribution(ExchangeType type) : distribution_type(type) {}
869
    DataDistribution(ExchangeType type, const std::vector<TExpr>& partition_exprs_)
870
225k
            : distribution_type(type), partition_exprs(partition_exprs_) {}
871
255k
    DataDistribution(const DataDistribution& other) = default;
872
825k
    bool need_local_exchange() const { return distribution_type != ExchangeType::NOOP; }
873
784k
    DataDistribution& operator=(const DataDistribution& other) = default;
874
    ExchangeType distribution_type;
875
    std::vector<TExpr> partition_exprs;
876
};
877
878
class ExchangerBase;
879
880
struct LocalExchangeSharedState : public BasicSharedState {
881
public:
882
    ENABLE_FACTORY_CREATOR(LocalExchangeSharedState);
883
    LocalExchangeSharedState(int num_instances);
884
    ~LocalExchangeSharedState() override;
885
    std::unique_ptr<ExchangerBase> exchanger {};
886
    std::vector<RuntimeProfile::Counter*> mem_counters;
887
    std::atomic<int64_t> mem_usage = 0;
888
    std::atomic<size_t> _buffer_mem_limit = config::local_exchange_buffer_mem_limit;
889
    // We need to make sure to add mem_usage first and then enqueue, otherwise sub mem_usage may cause negative mem_usage during concurrent dequeue.
890
    std::mutex le_lock;
891
    void sub_running_sink_operators();
892
    void sub_running_source_operators();
893
232k
    void _set_always_ready() {
894
1.50M
        for (auto& dep : source_deps) {
895
1.50M
            DCHECK(dep);
896
1.50M
            dep->set_always_ready();
897
1.50M
        }
898
232k
        for (auto& dep : sink_deps) {
899
232k
            DCHECK(dep);
900
232k
            dep->set_always_ready();
901
232k
        }
902
232k
    }
903
904
279k
    Dependency* get_sink_dep_by_channel_id(int channel_id) { return nullptr; }
905
906
263k
    void set_ready_to_read(int channel_id) {
907
263k
        auto& dep = source_deps[channel_id];
908
18.4E
        DCHECK(dep) << channel_id;
909
263k
        dep->set_ready();
910
263k
    }
911
912
263k
    void add_mem_usage(int channel_id, size_t delta) { mem_counters[channel_id]->update(delta); }
913
914
263k
    void sub_mem_usage(int channel_id, size_t delta) {
915
263k
        mem_counters[channel_id]->update(-(int64_t)delta);
916
263k
    }
917
918
220k
    void add_total_mem_usage(size_t delta) {
919
220k
        if (cast_set<int64_t>(mem_usage.fetch_add(delta) + delta) > _buffer_mem_limit) {
920
74
            sink_deps.front()->block();
921
74
        }
922
220k
    }
923
924
220k
    void sub_total_mem_usage(size_t delta) {
925
220k
        auto prev_usage = mem_usage.fetch_sub(delta);
926
220k
        DCHECK_GE(prev_usage - delta, 0) << "prev_usage: " << prev_usage << " delta: " << delta;
927
220k
        if (cast_set<int64_t>(prev_usage - delta) <= _buffer_mem_limit) {
928
220k
            sink_deps.front()->set_ready();
929
220k
        }
930
220k
    }
931
932
0
    void set_low_memory_mode(RuntimeState* state) {
933
0
        _buffer_mem_limit = std::min<int64_t>(config::local_exchange_buffer_mem_limit,
934
0
                                              state->low_memory_mode_buffer_limit());
935
0
    }
936
};
937
938
} // namespace doris