Coverage Report

Created: 2025-09-21 10:23

/root/doris/be/src/olap/memtable.cpp
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "olap/memtable.h"
19
20
#include <fmt/format.h>
21
#include <gen_cpp/olap_file.pb.h>
22
#include <pdqsort.h>
23
24
#include <algorithm>
25
#include <limits>
26
#include <string>
27
#include <vector>
28
29
#include "bvar/bvar.h"
30
#include "common/config.h"
31
#include "olap/memtable_memory_limiter.h"
32
#include "olap/olap_define.h"
33
#include "olap/tablet_schema.h"
34
#include "runtime/descriptors.h"
35
#include "runtime/exec_env.h"
36
#include "runtime/thread_context.h"
37
#include "util/debug_points.h"
38
#include "util/runtime_profile.h"
39
#include "util/stopwatch.hpp"
40
#include "vec/aggregate_functions/aggregate_function_reader.h"
41
#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
42
#include "vec/columns/column.h"
43
44
namespace doris {
45
46
bvar::Adder<int64_t> g_memtable_cnt("memtable_cnt");
47
48
using namespace ErrorCode;
49
50
MemTable::MemTable(int64_t tablet_id, std::shared_ptr<TabletSchema> tablet_schema,
51
                   const std::vector<SlotDescriptor*>* slot_descs, TupleDescriptor* tuple_desc,
52
                   bool enable_unique_key_mow, PartialUpdateInfo* partial_update_info)
53
        : _mem_type(MemType::ACTIVE),
54
          _tablet_id(tablet_id),
55
          _enable_unique_key_mow(enable_unique_key_mow),
56
          _keys_type(tablet_schema->keys_type()),
57
          _tablet_schema(tablet_schema),
58
          _is_first_insertion(true),
59
          _agg_functions(tablet_schema->num_columns()),
60
          _offsets_of_aggregate_states(tablet_schema->num_columns()),
61
27.0k
          _total_size_of_aggregate_states(0) {
62
27.0k
    g_memtable_cnt << 1;
63
27.0k
    _query_thread_context.init_unlocked();
64
27.0k
    _arena = std::make_unique<vectorized::Arena>();
65
27.0k
    _vec_row_comparator = std::make_shared<RowInBlockComparator>(_tablet_schema);
66
27.0k
    _num_columns = _tablet_schema->num_columns();
67
27.0k
    if (partial_update_info != nullptr) {
68
26.9k
        _partial_update_mode = partial_update_info->update_mode();
69
26.9k
        if (_partial_update_mode == UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS) {
70
416
            _num_columns = partial_update_info->partial_update_input_columns.size();
71
416
            if (partial_update_info->is_schema_contains_auto_inc_column &&
72
416
                !partial_update_info->is_input_columns_contains_auto_inc_column) {
73
0
                _is_partial_update_and_auto_inc = true;
74
0
                _num_columns += 1;
75
0
            }
76
416
        }
77
26.9k
    }
78
    // TODO: Support ZOrderComparator in the future
79
27.0k
    _init_columns_offset_by_slot_descs(slot_descs, tuple_desc);
80
27.0k
    _mem_tracker = std::make_shared<MemTracker>();
81
27.0k
}
82
83
void MemTable::_init_columns_offset_by_slot_descs(const std::vector<SlotDescriptor*>* slot_descs,
84
26.9k
                                                  const TupleDescriptor* tuple_desc) {
85
352k
    for (auto slot_desc : *slot_descs) {
86
352k
        const auto& slots = tuple_desc->slots();
87
23.3M
        for (int j = 0; j < slots.size(); ++j) {
88
23.3M
            if (slot_desc->id() == slots[j]->id()) {
89
351k
                _column_offset.emplace_back(j);
90
351k
                break;
91
351k
            }
92
23.3M
        }
93
352k
    }
94
26.9k
    if (_is_partial_update_and_auto_inc) {
95
0
        _column_offset.emplace_back(_column_offset.size());
96
0
    }
97
26.9k
}
98
99
4.27k
void MemTable::_init_agg_functions(const vectorized::Block* block) {
100
46.4k
    for (uint32_t cid = _tablet_schema->num_key_columns(); cid < _num_columns; ++cid) {
101
42.1k
        vectorized::AggregateFunctionPtr function;
102
42.1k
        if (_keys_type == KeysType::UNIQUE_KEYS && _enable_unique_key_mow) {
103
            // In such table, non-key column's aggregation type is NONE, so we need to construct
104
            // the aggregate function manually.
105
39.0k
            if (_skip_bitmap_col_idx != cid) {
106
39.0k
                function = vectorized::AggregateFunctionSimpleFactory::instance().get(
107
39.0k
                        "replace_load", {block->get_data_type(cid)},
108
39.0k
                        block->get_data_type(cid)->is_nullable(),
109
39.0k
                        BeExecVersionManager::get_newest_version());
110
39.0k
            } else {
111
0
                function = vectorized::AggregateFunctionSimpleFactory::instance().get(
112
0
                        "bitmap_intersect", {block->get_data_type(cid)}, false,
113
0
                        BeExecVersionManager::get_newest_version());
114
0
            }
115
39.0k
        } else {
116
3.16k
            function = _tablet_schema->column(cid).get_aggregate_function(
117
3.16k
                    vectorized::AGG_LOAD_SUFFIX, _tablet_schema->column(cid).get_be_exec_version());
118
3.16k
            if (function == nullptr) {
119
0
                LOG(WARNING) << "column get aggregate function failed, column="
120
0
                             << _tablet_schema->column(cid).name();
121
0
            }
122
3.16k
        }
123
124
42.1k
        DCHECK(function != nullptr);
125
42.1k
        _agg_functions[cid] = function;
126
42.1k
    }
127
128
46.4k
    for (uint32_t cid = _tablet_schema->num_key_columns(); cid < _num_columns; ++cid) {
129
42.1k
        _offsets_of_aggregate_states[cid] = _total_size_of_aggregate_states;
130
42.1k
        _total_size_of_aggregate_states += _agg_functions[cid]->size_of_data();
131
132
        // If not the last aggregate_state, we need pad it so that next aggregate_state will be aligned.
133
42.1k
        if (cid + 1 < _num_columns) {
134
37.9k
            size_t alignment_of_next_state = _agg_functions[cid + 1]->align_of_data();
135
136
            /// Extend total_size to next alignment requirement
137
            /// Add padding by rounding up 'total_size_of_aggregate_states' to be a multiplier of alignment_of_next_state.
138
37.9k
            _total_size_of_aggregate_states =
139
37.9k
                    (_total_size_of_aggregate_states + alignment_of_next_state - 1) /
140
37.9k
                    alignment_of_next_state * alignment_of_next_state;
141
37.9k
        }
142
42.1k
    }
143
4.27k
}
144
145
27.1k
MemTable::~MemTable() {
146
27.1k
    SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(_query_thread_context.query_mem_tracker);
147
27.1k
    {
148
27.1k
        SCOPED_CONSUME_MEM_TRACKER(_mem_tracker);
149
27.1k
        g_memtable_cnt << -1;
150
27.1k
        if (_keys_type != KeysType::DUP_KEYS) {
151
3.28M
            for (auto it = _row_in_blocks.begin(); it != _row_in_blocks.end(); it++) {
152
3.26M
                if (!(*it)->has_init_agg()) {
153
3.26M
                    continue;
154
3.26M
                }
155
                // We should release agg_places here, because they are not released when a
156
                // load is canceled.
157
18.4E
                for (size_t i = _tablet_schema->num_key_columns(); i < _num_columns; ++i) {
158
0
                    auto function = _agg_functions[i];
159
0
                    DCHECK(function != nullptr);
160
0
                    function->destroy((*it)->agg_places(i));
161
0
                }
162
18.4E
            }
163
15.6k
        }
164
        // Arena has to be destroyed after agg state, because some agg state's memory may be
165
        // allocated in arena.
166
27.1k
        _arena.reset();
167
27.1k
        _vec_row_comparator.reset();
168
27.1k
        _row_in_blocks.clear();
169
27.1k
        _agg_functions.clear();
170
27.1k
        _input_mutable_block.clear();
171
27.1k
        _output_mutable_block.clear();
172
27.1k
    }
173
27.1k
    if (_is_flush_success) {
174
        // If the memtable is flush success, then its memtracker's consumption should be 0
175
7.68k
        if (_mem_tracker->consumption() != 0 && config::crash_in_memory_tracker_inaccurate) {
176
0
            LOG(FATAL) << "memtable flush success but cosumption is not 0, it is "
177
0
                       << _mem_tracker->consumption();
178
0
        }
179
7.68k
    }
180
27.1k
}
181
182
201k
int RowInBlockComparator::operator()(const RowInBlock* left, const RowInBlock* right) const {
183
201k
    return _pblock->compare_at(left->_row_pos, right->_row_pos, _tablet_schema->num_key_columns(),
184
201k
                               *_pblock, -1);
185
201k
}
186
187
Status MemTable::insert(const vectorized::Block* input_block,
188
42.6k
                        const std::vector<uint32_t>& row_idxs) {
189
42.6k
    SCOPED_CONSUME_MEM_TRACKER(_mem_tracker);
190
191
42.6k
    if (_is_first_insertion) {
192
7.68k
        _is_first_insertion = false;
193
7.68k
        auto clone_block = input_block->clone_without_columns(&_column_offset);
194
7.68k
        _input_mutable_block = vectorized::MutableBlock::build_mutable_block(&clone_block);
195
7.68k
        _vec_row_comparator->set_block(&_input_mutable_block);
196
7.68k
        _output_mutable_block = vectorized::MutableBlock::build_mutable_block(&clone_block);
197
7.68k
        if (_tablet_schema->has_sequence_col()) {
198
104
            if (_partial_update_mode == UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS) {
199
                // for unique key fixed partial update, sequence column index in block
200
                // may be different with the index in `_tablet_schema`
201
0
                for (size_t i = 0; i < clone_block.columns(); i++) {
202
0
                    if (clone_block.get_by_position(i).name == SEQUENCE_COL) {
203
0
                        _seq_col_idx_in_block = i;
204
0
                        break;
205
0
                    }
206
0
                }
207
104
            } else {
208
104
                _seq_col_idx_in_block = _tablet_schema->sequence_col_idx();
209
104
            }
210
104
        }
211
7.68k
        if (_partial_update_mode == UniqueKeyUpdateModePB::UPDATE_FLEXIBLE_COLUMNS &&
212
7.68k
            _tablet_schema->has_skip_bitmap_col()) {
213
            // init of _skip_bitmap_col_idx and _delete_sign_col_idx must be before _init_agg_functions()
214
0
            _skip_bitmap_col_idx = _tablet_schema->skip_bitmap_col_idx();
215
0
            _delete_sign_col_idx = _tablet_schema->delete_sign_idx();
216
0
            _delete_sign_col_unique_id = _tablet_schema->column(_delete_sign_col_idx).unique_id();
217
0
            if (_seq_col_idx_in_block != -1) {
218
0
                _seq_col_unique_id = _tablet_schema->column(_seq_col_idx_in_block).unique_id();
219
0
            }
220
0
        }
221
7.68k
        if (_keys_type != KeysType::DUP_KEYS) {
222
            // there may be additional intermediate columns in input_block
223
            // we only need columns indicated by column offset in the output
224
4.27k
            RETURN_IF_CATCH_EXCEPTION(_init_agg_functions(&clone_block));
225
4.27k
        }
226
7.68k
    }
227
228
42.6k
    auto num_rows = row_idxs.size();
229
42.6k
    size_t cursor_in_mutableblock = _input_mutable_block.rows();
230
42.6k
    RETURN_IF_ERROR(_input_mutable_block.add_rows(input_block, row_idxs.data(),
231
42.6k
                                                  row_idxs.data() + num_rows, &_column_offset));
232
17.2M
    for (int i = 0; i < num_rows; i++) {
233
17.2M
        _row_in_blocks.emplace_back(std::make_shared<RowInBlock>(cursor_in_mutableblock + i));
234
17.2M
    }
235
236
42.6k
    _stat.raw_rows += num_rows;
237
42.6k
    return Status::OK();
238
42.6k
}
239
240
template <bool has_skip_bitmap_col>
241
void MemTable::_aggregate_two_row_in_block(vectorized::MutableBlock& mutable_block,
242
84
                                           RowInBlock* src_row, RowInBlock* dst_row) {
243
    // for flexible partial update, the caller must guarantees that either src_row and dst_row
244
    // both specify the sequence column, or src_row and dst_row both don't specify the
245
    // sequence column
246
84
    if (_tablet_schema->has_sequence_col() && _seq_col_idx_in_block >= 0) {
247
3
        DCHECK_LT(_seq_col_idx_in_block, mutable_block.columns());
248
3
        auto col_ptr = mutable_block.mutable_columns()[_seq_col_idx_in_block].get();
249
3
        auto res = col_ptr->compare_at(dst_row->_row_pos, src_row->_row_pos, *col_ptr, -1);
250
        // dst sequence column larger than src, don't need to update
251
3
        if (res > 0) {
252
3
            return;
253
3
        }
254
        // need to update the row pos in dst row to the src row pos when has
255
        // sequence column
256
0
        dst_row->_row_pos = src_row->_row_pos;
257
0
    }
258
    // dst is non-sequence row, or dst sequence is smaller
259
81
    if constexpr (!has_skip_bitmap_col) {
260
0
        DCHECK(_skip_bitmap_col_idx == -1);
261
637
        for (uint32_t cid = _tablet_schema->num_key_columns(); cid < _num_columns; ++cid) {
262
556
            auto* col_ptr = mutable_block.mutable_columns()[cid].get();
263
556
            _agg_functions[cid]->add(dst_row->agg_places(cid),
264
556
                                     const_cast<const doris::vectorized::IColumn**>(&col_ptr),
265
556
                                     src_row->_row_pos, _arena.get());
266
556
        }
267
81
    } else {
268
0
        DCHECK(_skip_bitmap_col_idx != -1);
269
0
        DCHECK_LT(_skip_bitmap_col_idx, mutable_block.columns());
270
0
        const BitmapValue& skip_bitmap =
271
0
                assert_cast<vectorized::ColumnBitmap*, TypeCheckOnRelease::DISABLE>(
272
0
                        mutable_block.mutable_columns()[_skip_bitmap_col_idx].get())
273
0
                        ->get_data()[src_row->_row_pos];
274
0
        for (uint32_t cid = _tablet_schema->num_key_columns(); cid < _num_columns; ++cid) {
275
0
            const auto& col = _tablet_schema->column(cid);
276
0
            if (cid != _skip_bitmap_col_idx && skip_bitmap.contains(col.unique_id())) {
277
0
                continue;
278
0
            }
279
0
            auto* col_ptr = mutable_block.mutable_columns()[cid].get();
280
0
            _agg_functions[cid]->add(dst_row->agg_places(cid),
281
0
                                     const_cast<const doris::vectorized::IColumn**>(&col_ptr),
282
0
                                     src_row->_row_pos, _arena.get());
283
0
        }
284
0
    }
285
81
}
_ZN5doris8MemTable27_aggregate_two_row_in_blockILb0EEEvRNS_10vectorized12MutableBlockEPNS_10RowInBlockES6_
Line
Count
Source
242
84
                                           RowInBlock* src_row, RowInBlock* dst_row) {
243
    // for flexible partial update, the caller must guarantees that either src_row and dst_row
244
    // both specify the sequence column, or src_row and dst_row both don't specify the
245
    // sequence column
246
84
    if (_tablet_schema->has_sequence_col() && _seq_col_idx_in_block >= 0) {
247
3
        DCHECK_LT(_seq_col_idx_in_block, mutable_block.columns());
248
3
        auto col_ptr = mutable_block.mutable_columns()[_seq_col_idx_in_block].get();
249
3
        auto res = col_ptr->compare_at(dst_row->_row_pos, src_row->_row_pos, *col_ptr, -1);
250
        // dst sequence column larger than src, don't need to update
251
3
        if (res > 0) {
252
3
            return;
253
3
        }
254
        // need to update the row pos in dst row to the src row pos when has
255
        // sequence column
256
0
        dst_row->_row_pos = src_row->_row_pos;
257
0
    }
258
    // dst is non-sequence row, or dst sequence is smaller
259
81
    if constexpr (!has_skip_bitmap_col) {
260
81
        DCHECK(_skip_bitmap_col_idx == -1);
261
637
        for (uint32_t cid = _tablet_schema->num_key_columns(); cid < _num_columns; ++cid) {
262
556
            auto* col_ptr = mutable_block.mutable_columns()[cid].get();
263
556
            _agg_functions[cid]->add(dst_row->agg_places(cid),
264
556
                                     const_cast<const doris::vectorized::IColumn**>(&col_ptr),
265
556
                                     src_row->_row_pos, _arena.get());
266
556
        }
267
81
    } else {
268
81
        DCHECK(_skip_bitmap_col_idx != -1);
269
81
        DCHECK_LT(_skip_bitmap_col_idx, mutable_block.columns());
270
81
        const BitmapValue& skip_bitmap =
271
81
                assert_cast<vectorized::ColumnBitmap*, TypeCheckOnRelease::DISABLE>(
272
81
                        mutable_block.mutable_columns()[_skip_bitmap_col_idx].get())
273
81
                        ->get_data()[src_row->_row_pos];
274
81
        for (uint32_t cid = _tablet_schema->num_key_columns(); cid < _num_columns; ++cid) {
275
81
            const auto& col = _tablet_schema->column(cid);
276
81
            if (cid != _skip_bitmap_col_idx && skip_bitmap.contains(col.unique_id())) {
277
81
                continue;
278
81
            }
279
81
            auto* col_ptr = mutable_block.mutable_columns()[cid].get();
280
81
            _agg_functions[cid]->add(dst_row->agg_places(cid),
281
81
                                     const_cast<const doris::vectorized::IColumn**>(&col_ptr),
282
81
                                     src_row->_row_pos, _arena.get());
283
81
        }
284
81
    }
285
81
}
Unexecuted instantiation: _ZN5doris8MemTable27_aggregate_two_row_in_blockILb1EEEvRNS_10vectorized12MutableBlockEPNS_10RowInBlockES6_
286
7.62k
Status MemTable::_put_into_output(vectorized::Block& in_block) {
287
7.62k
    SCOPED_RAW_TIMER(&_stat.put_into_output_ns);
288
7.62k
    std::vector<uint32_t> row_pos_vec;
289
7.62k
    DCHECK(in_block.rows() <= std::numeric_limits<int>::max());
290
7.62k
    row_pos_vec.reserve(in_block.rows());
291
17.0M
    for (int i = 0; i < _row_in_blocks.size(); i++) {
292
17.0M
        row_pos_vec.emplace_back(_row_in_blocks[i]->_row_pos);
293
17.0M
    }
294
7.62k
    return _output_mutable_block.add_rows(&in_block, row_pos_vec.data(),
295
7.62k
                                          row_pos_vec.data() + in_block.rows());
296
7.62k
}
297
298
7.68k
size_t MemTable::_sort() {
299
7.68k
    SCOPED_RAW_TIMER(&_stat.sort_ns);
300
7.68k
    _stat.sort_times++;
301
7.68k
    size_t same_keys_num = 0;
302
    // sort new rows
303
7.68k
    Tie tie = Tie(_last_sorted_pos, _row_in_blocks.size());
304
34.8k
    for (size_t i = 0; i < _tablet_schema->num_key_columns(); i++) {
305
122M
        auto cmp = [&](RowInBlock* lhs, RowInBlock* rhs) -> int {
306
122M
            return _input_mutable_block.compare_one_column(lhs->_row_pos, rhs->_row_pos, i, -1);
307
122M
        };
308
27.1k
        _sort_one_column(_row_in_blocks, tie, cmp);
309
27.1k
    }
310
7.68k
    bool is_dup = (_keys_type == KeysType::DUP_KEYS);
311
    // sort extra round by _row_pos to make the sort stable
312
7.68k
    auto iter = tie.iter();
313
184k
    while (iter.next()) {
314
176k
        pdqsort(std::next(_row_in_blocks.begin(), iter.left()),
315
176k
                std::next(_row_in_blocks.begin(), iter.right()),
316
176k
                [&is_dup](const std::shared_ptr<RowInBlock>& lhs,
317
47.9M
                          const std::shared_ptr<RowInBlock>& rhs) -> bool {
318
47.9M
                    return is_dup ? lhs->_row_pos > rhs->_row_pos : lhs->_row_pos < rhs->_row_pos;
319
47.9M
                });
320
176k
        same_keys_num += iter.right() - iter.left();
321
176k
    }
322
    // merge new rows and old rows
323
7.68k
    _vec_row_comparator->set_block(&_input_mutable_block);
324
7.68k
    auto cmp_func = [this, is_dup, &same_keys_num](const std::shared_ptr<RowInBlock>& l,
325
7.68k
                                                   const std::shared_ptr<RowInBlock>& r) -> bool {
326
0
        auto value = (*(this->_vec_row_comparator))(l.get(), r.get());
327
0
        if (value == 0) {
328
0
            same_keys_num++;
329
0
            return is_dup ? l->_row_pos > r->_row_pos : l->_row_pos < r->_row_pos;
330
0
        } else {
331
0
            return value < 0;
332
0
        }
333
0
    };
334
7.68k
    auto new_row_it = std::next(_row_in_blocks.begin(), _last_sorted_pos);
335
7.68k
    std::inplace_merge(_row_in_blocks.begin(), new_row_it, _row_in_blocks.end(), cmp_func);
336
7.68k
    _last_sorted_pos = _row_in_blocks.size();
337
7.68k
    return same_keys_num;
338
7.68k
}
339
340
1
Status MemTable::_sort_by_cluster_keys() {
341
1
    SCOPED_RAW_TIMER(&_stat.sort_ns);
342
1
    _stat.sort_times++;
343
    // sort all rows
344
1
    vectorized::Block in_block = _output_mutable_block.to_block();
345
1
    vectorized::MutableBlock mutable_block =
346
1
            vectorized::MutableBlock::build_mutable_block(&in_block);
347
1
    auto clone_block = in_block.clone_without_columns();
348
1
    _output_mutable_block = vectorized::MutableBlock::build_mutable_block(&clone_block);
349
350
1
    std::vector<std::shared_ptr<RowInBlock>> row_in_blocks;
351
1
    row_in_blocks.reserve(mutable_block.rows());
352
5
    for (size_t i = 0; i < mutable_block.rows(); i++) {
353
4
        row_in_blocks.emplace_back(std::make_shared<RowInBlock>(i));
354
4
    }
355
1
    Tie tie = Tie(0, mutable_block.rows());
356
357
2
    for (auto cid : _tablet_schema->cluster_key_idxes()) {
358
2
        auto index = _tablet_schema->field_index(cid);
359
2
        if (index == -1) {
360
0
            return Status::InternalError("could not find cluster key column with unique_id=" +
361
0
                                         std::to_string(cid) + " in tablet schema");
362
0
        }
363
8
        auto cmp = [&](const RowInBlock* lhs, const RowInBlock* rhs) -> int {
364
8
            return mutable_block.compare_one_column(lhs->_row_pos, rhs->_row_pos, index, -1);
365
8
        };
366
2
        _sort_one_column(row_in_blocks, tie, cmp);
367
2
    }
368
369
    // sort extra round by _row_pos to make the sort stable
370
1
    auto iter = tie.iter();
371
1
    while (iter.next()) {
372
0
        pdqsort(std::next(row_in_blocks.begin(), iter.left()),
373
0
                std::next(row_in_blocks.begin(), iter.right()),
374
0
                [](const std::shared_ptr<RowInBlock>& lhs, const std::shared_ptr<RowInBlock>& rhs)
375
0
                        -> bool { return lhs->_row_pos < rhs->_row_pos; });
376
0
    }
377
378
1
    in_block = mutable_block.to_block();
379
1
    SCOPED_RAW_TIMER(&_stat.put_into_output_ns);
380
1
    std::vector<uint32_t> row_pos_vec;
381
1
    DCHECK(in_block.rows() <= std::numeric_limits<int>::max());
382
1
    row_pos_vec.reserve(in_block.rows());
383
5
    for (int i = 0; i < row_in_blocks.size(); i++) {
384
4
        row_pos_vec.emplace_back(row_in_blocks[i]->_row_pos);
385
4
    }
386
1
    return _output_mutable_block.add_rows(&in_block, row_pos_vec.data(),
387
1
                                          row_pos_vec.data() + in_block.rows(), &_column_offset);
388
1
}
389
390
void MemTable::_sort_one_column(std::vector<std::shared_ptr<RowInBlock>>& row_in_blocks, Tie& tie,
391
27.1k
                                std::function<int(RowInBlock*, RowInBlock*)> cmp) {
392
27.1k
    auto iter = tie.iter();
393
758k
    while (iter.next()) {
394
731k
        pdqsort(std::next(row_in_blocks.begin(), static_cast<int>(iter.left())),
395
731k
                std::next(row_in_blocks.begin(), static_cast<int>(iter.right())),
396
105M
                [&cmp](auto lhs, auto rhs) -> bool { return cmp(lhs.get(), rhs.get()) < 0; });
397
731k
        tie[iter.left()] = 0;
398
20.9M
        for (auto i = iter.left() + 1; i < iter.right(); i++) {
399
20.1M
            tie[i] = (cmp(row_in_blocks[i - 1].get(), row_in_blocks[i].get()) == 0);
400
20.1M
        }
401
731k
    }
402
27.1k
}
403
404
template <bool is_final>
405
void MemTable::_finalize_one_row(RowInBlock* row,
406
                                 const vectorized::ColumnsWithTypeAndName& block_data,
407
201k
                                 int row_pos) {
408
    // move key columns
409
604k
    for (size_t i = 0; i < _tablet_schema->num_key_columns(); ++i) {
410
403k
        _output_mutable_block.get_column_by_position(i)->insert_from(*block_data[i].column.get(),
411
403k
                                                                     row->_row_pos);
412
403k
    }
413
201k
    if (row->has_init_agg()) {
414
        // get value columns from agg_places
415
539
        for (size_t i = _tablet_schema->num_key_columns(); i < _num_columns; ++i) {
416
466
            auto function = _agg_functions[i];
417
466
            auto* agg_place = row->agg_places(i);
418
466
            auto* col_ptr = _output_mutable_block.get_column_by_position(i).get();
419
466
            function->insert_result_into(agg_place, *col_ptr);
420
421
466
            if constexpr (is_final) {
422
0
                function->destroy(agg_place);
423
0
            } else {
424
0
                function->reset(agg_place);
425
0
            }
426
466
        }
427
428
73
        if constexpr (is_final) {
429
0
            row->remove_init_agg();
430
0
        } else {
431
0
            for (size_t i = _tablet_schema->num_key_columns(); i < _num_columns; ++i) {
432
0
                auto function = _agg_functions[i];
433
0
                auto* agg_place = row->agg_places(i);
434
0
                auto* col_ptr = _output_mutable_block.get_column_by_position(i).get();
435
0
                function->add(agg_place, const_cast<const doris::vectorized::IColumn**>(&col_ptr),
436
0
                              row_pos, _arena.get());
437
0
            }
438
0
        }
439
200k
    } else {
440
        // move columns for rows do not need agg
441
3.67M
        for (size_t i = _tablet_schema->num_key_columns(); i < _num_columns; ++i) {
442
3.47M
            _output_mutable_block.get_column_by_position(i)->insert_from(
443
3.47M
                    *block_data[i].column.get(), row->_row_pos);
444
3.47M
        }
445
200k
    }
446
201k
    if constexpr (!is_final) {
447
0
        row->_row_pos = row_pos;
448
0
    }
449
201k
}
Unexecuted instantiation: _ZN5doris8MemTable17_finalize_one_rowILb0EEEvPNS_10RowInBlockERKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS6_EEi
_ZN5doris8MemTable17_finalize_one_rowILb1EEEvPNS_10RowInBlockERKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS6_EEi
Line
Count
Source
407
201k
                                 int row_pos) {
408
    // move key columns
409
604k
    for (size_t i = 0; i < _tablet_schema->num_key_columns(); ++i) {
410
403k
        _output_mutable_block.get_column_by_position(i)->insert_from(*block_data[i].column.get(),
411
403k
                                                                     row->_row_pos);
412
403k
    }
413
201k
    if (row->has_init_agg()) {
414
        // get value columns from agg_places
415
539
        for (size_t i = _tablet_schema->num_key_columns(); i < _num_columns; ++i) {
416
466
            auto function = _agg_functions[i];
417
466
            auto* agg_place = row->agg_places(i);
418
466
            auto* col_ptr = _output_mutable_block.get_column_by_position(i).get();
419
466
            function->insert_result_into(agg_place, *col_ptr);
420
421
466
            if constexpr (is_final) {
422
466
                function->destroy(agg_place);
423
466
            } else {
424
466
                function->reset(agg_place);
425
466
            }
426
466
        }
427
428
73
        if constexpr (is_final) {
429
73
            row->remove_init_agg();
430
73
        } else {
431
73
            for (size_t i = _tablet_schema->num_key_columns(); i < _num_columns; ++i) {
432
73
                auto function = _agg_functions[i];
433
73
                auto* agg_place = row->agg_places(i);
434
73
                auto* col_ptr = _output_mutable_block.get_column_by_position(i).get();
435
73
                function->add(agg_place, const_cast<const doris::vectorized::IColumn**>(&col_ptr),
436
73
                              row_pos, _arena.get());
437
73
            }
438
73
        }
439
200k
    } else {
440
        // move columns for rows do not need agg
441
3.67M
        for (size_t i = _tablet_schema->num_key_columns(); i < _num_columns; ++i) {
442
3.47M
            _output_mutable_block.get_column_by_position(i)->insert_from(
443
3.47M
                    *block_data[i].column.get(), row->_row_pos);
444
3.47M
        }
445
200k
    }
446
201k
    if constexpr (!is_final) {
447
201k
        row->_row_pos = row_pos;
448
201k
    }
449
201k
}
450
451
73
void MemTable::_init_row_for_agg(RowInBlock* row, vectorized::MutableBlock& mutable_block) {
452
73
    row->init_agg_places(_arena->aligned_alloc(_total_size_of_aggregate_states, 16),
453
73
                         _offsets_of_aggregate_states.data());
454
539
    for (auto cid = _tablet_schema->num_key_columns(); cid < _num_columns; cid++) {
455
466
        auto* col_ptr = mutable_block.mutable_columns()[cid].get();
456
466
        auto* data = row->agg_places(cid);
457
466
        _agg_functions[cid]->create(data);
458
466
        _agg_functions[cid]->add(data, const_cast<const doris::vectorized::IColumn**>(&col_ptr),
459
466
                                 row->_row_pos, _arena.get());
460
466
    }
461
73
}
462
0
void MemTable::_clear_row_agg(RowInBlock* row) {
463
0
    if (row->has_init_agg()) {
464
0
        for (size_t i = _tablet_schema->num_key_columns(); i < _num_columns; ++i) {
465
0
            auto function = _agg_functions[i];
466
0
            auto* agg_place = row->agg_places(i);
467
0
            function->destroy(agg_place);
468
0
        }
469
0
        row->remove_init_agg();
470
0
    }
471
0
}
472
473
template <bool is_final, bool has_skip_bitmap_col>
474
47
void MemTable::_aggregate() {
475
47
    SCOPED_RAW_TIMER(&_stat.agg_ns);
476
47
    _stat.agg_times++;
477
47
    vectorized::Block in_block = _input_mutable_block.to_block();
478
47
    vectorized::MutableBlock mutable_block =
479
47
            vectorized::MutableBlock::build_mutable_block(&in_block);
480
47
    _vec_row_comparator->set_block(&mutable_block);
481
47
    auto& block_data = in_block.get_columns_with_type_and_name();
482
47
    std::vector<std::shared_ptr<RowInBlock>> temp_row_in_blocks;
483
47
    temp_row_in_blocks.reserve(_last_sorted_pos);
484
    //only init agg if needed
485
486
47
    if constexpr (!has_skip_bitmap_col) {
487
0
        RowInBlock* prev_row = nullptr;
488
0
        int row_pos = -1;
489
201k
        for (const auto& cur_row_ptr : _row_in_blocks) {
490
201k
            RowInBlock* cur_row = cur_row_ptr.get();
491
201k
            if (!temp_row_in_blocks.empty() && (*_vec_row_comparator)(prev_row, cur_row) == 0) {
492
84
                if (!prev_row->has_init_agg()) {
493
73
                    _init_row_for_agg(prev_row, mutable_block);
494
73
                }
495
84
                _stat.merged_rows++;
496
84
                _aggregate_two_row_in_block<has_skip_bitmap_col>(mutable_block, cur_row, prev_row);
497
201k
            } else {
498
201k
                prev_row = cur_row;
499
201k
                if (!temp_row_in_blocks.empty()) {
500
                    // no more rows to merge for prev row, finalize it
501
200k
                    _finalize_one_row<is_final>(temp_row_in_blocks.back().get(), block_data,
502
200k
                                                row_pos);
503
200k
                }
504
201k
                temp_row_in_blocks.push_back(cur_row_ptr);
505
201k
                row_pos++;
506
201k
            }
507
201k
        }
508
47
        if (!temp_row_in_blocks.empty()) {
509
            // finalize the last low
510
47
            _finalize_one_row<is_final>(temp_row_in_blocks.back().get(), block_data, row_pos);
511
47
        }
512
47
    } else {
513
0
        DCHECK(_delete_sign_col_idx != -1);
514
0
        if (_seq_col_idx_in_block == -1) {
515
0
            _aggregate_for_flexible_partial_update_without_seq_col<is_final>(
516
0
                    block_data, mutable_block, temp_row_in_blocks);
517
0
        } else {
518
0
            _aggregate_for_flexible_partial_update_with_seq_col<is_final>(block_data, mutable_block,
519
0
                                                                          temp_row_in_blocks);
520
0
        }
521
0
    }
522
47
    if constexpr (!is_final) {
523
        // if is not final, we collect the agg results to input_block and then continue to insert
524
0
        _input_mutable_block.swap(_output_mutable_block);
525
        //TODO(weixang):opt here.
526
0
        std::unique_ptr<vectorized::Block> empty_input_block = in_block.create_same_struct_block(0);
527
0
        _output_mutable_block =
528
0
                vectorized::MutableBlock::build_mutable_block(empty_input_block.get());
529
0
        _output_mutable_block.clear_column_data();
530
0
        _row_in_blocks = temp_row_in_blocks;
531
0
        _last_sorted_pos = _row_in_blocks.size();
532
0
    }
533
47
}
Unexecuted instantiation: _ZN5doris8MemTable10_aggregateILb0ELb0EEEvv
Unexecuted instantiation: _ZN5doris8MemTable10_aggregateILb0ELb1EEEvv
_ZN5doris8MemTable10_aggregateILb1ELb0EEEvv
Line
Count
Source
474
47
void MemTable::_aggregate() {
475
47
    SCOPED_RAW_TIMER(&_stat.agg_ns);
476
47
    _stat.agg_times++;
477
47
    vectorized::Block in_block = _input_mutable_block.to_block();
478
47
    vectorized::MutableBlock mutable_block =
479
47
            vectorized::MutableBlock::build_mutable_block(&in_block);
480
47
    _vec_row_comparator->set_block(&mutable_block);
481
47
    auto& block_data = in_block.get_columns_with_type_and_name();
482
47
    std::vector<std::shared_ptr<RowInBlock>> temp_row_in_blocks;
483
47
    temp_row_in_blocks.reserve(_last_sorted_pos);
484
    //only init agg if needed
485
486
47
    if constexpr (!has_skip_bitmap_col) {
487
47
        RowInBlock* prev_row = nullptr;
488
47
        int row_pos = -1;
489
201k
        for (const auto& cur_row_ptr : _row_in_blocks) {
490
201k
            RowInBlock* cur_row = cur_row_ptr.get();
491
201k
            if (!temp_row_in_blocks.empty() && (*_vec_row_comparator)(prev_row, cur_row) == 0) {
492
84
                if (!prev_row->has_init_agg()) {
493
73
                    _init_row_for_agg(prev_row, mutable_block);
494
73
                }
495
84
                _stat.merged_rows++;
496
84
                _aggregate_two_row_in_block<has_skip_bitmap_col>(mutable_block, cur_row, prev_row);
497
201k
            } else {
498
201k
                prev_row = cur_row;
499
201k
                if (!temp_row_in_blocks.empty()) {
500
                    // no more rows to merge for prev row, finalize it
501
200k
                    _finalize_one_row<is_final>(temp_row_in_blocks.back().get(), block_data,
502
200k
                                                row_pos);
503
200k
                }
504
201k
                temp_row_in_blocks.push_back(cur_row_ptr);
505
201k
                row_pos++;
506
201k
            }
507
201k
        }
508
47
        if (!temp_row_in_blocks.empty()) {
509
            // finalize the last low
510
47
            _finalize_one_row<is_final>(temp_row_in_blocks.back().get(), block_data, row_pos);
511
47
        }
512
47
    } else {
513
47
        DCHECK(_delete_sign_col_idx != -1);
514
47
        if (_seq_col_idx_in_block == -1) {
515
47
            _aggregate_for_flexible_partial_update_without_seq_col<is_final>(
516
47
                    block_data, mutable_block, temp_row_in_blocks);
517
47
        } else {
518
47
            _aggregate_for_flexible_partial_update_with_seq_col<is_final>(block_data, mutable_block,
519
47
                                                                          temp_row_in_blocks);
520
47
        }
521
47
    }
522
47
    if constexpr (!is_final) {
523
        // if is not final, we collect the agg results to input_block and then continue to insert
524
47
        _input_mutable_block.swap(_output_mutable_block);
525
        //TODO(weixang):opt here.
526
47
        std::unique_ptr<vectorized::Block> empty_input_block = in_block.create_same_struct_block(0);
527
47
        _output_mutable_block =
528
47
                vectorized::MutableBlock::build_mutable_block(empty_input_block.get());
529
47
        _output_mutable_block.clear_column_data();
530
47
        _row_in_blocks = temp_row_in_blocks;
531
47
        _last_sorted_pos = _row_in_blocks.size();
532
47
    }
533
47
}
Unexecuted instantiation: _ZN5doris8MemTable10_aggregateILb1ELb1EEEvv
534
535
template <bool is_final>
536
void MemTable::_aggregate_for_flexible_partial_update_without_seq_col(
537
        const vectorized::ColumnsWithTypeAndName& block_data,
538
        vectorized::MutableBlock& mutable_block,
539
0
        std::vector<std::shared_ptr<RowInBlock>>& temp_row_in_blocks) {
540
0
    std::shared_ptr<RowInBlock> prev_row {nullptr};
541
0
    int row_pos = -1;
542
0
    auto& skip_bitmaps = assert_cast<vectorized::ColumnBitmap*>(
543
0
                                 mutable_block.mutable_columns()[_skip_bitmap_col_idx].get())
544
0
                                 ->get_data();
545
0
    auto& delete_signs = assert_cast<vectorized::ColumnInt8*>(
546
0
                                 mutable_block.mutable_columns()[_delete_sign_col_idx].get())
547
0
                                 ->get_data();
548
0
    std::shared_ptr<RowInBlock> row_with_delete_sign {nullptr};
549
0
    std::shared_ptr<RowInBlock> row_without_delete_sign {nullptr};
550
551
0
    auto finalize_rows = [&]() {
552
0
        if (row_with_delete_sign != nullptr) {
553
0
            temp_row_in_blocks.push_back(row_with_delete_sign);
554
0
            _finalize_one_row<is_final>(row_with_delete_sign.get(), block_data, ++row_pos);
555
0
            row_with_delete_sign = nullptr;
556
0
        }
557
0
        if (row_without_delete_sign != nullptr) {
558
0
            temp_row_in_blocks.push_back(row_without_delete_sign);
559
0
            _finalize_one_row<is_final>(row_without_delete_sign.get(), block_data, ++row_pos);
560
0
            row_without_delete_sign = nullptr;
561
0
        }
562
        // _arena.clear();
563
0
    };
Unexecuted instantiation: _ZZN5doris8MemTable54_aggregate_for_flexible_partial_update_without_seq_colILb0EEEvRKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS4_EERNS3_12MutableBlockERS2_ISt10shared_ptrINS_10RowInBlockEESaISD_EEENKUlvE_clEv
Unexecuted instantiation: _ZZN5doris8MemTable54_aggregate_for_flexible_partial_update_without_seq_colILb1EEEvRKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS4_EERNS3_12MutableBlockERS2_ISt10shared_ptrINS_10RowInBlockEESaISD_EEENKUlvE_clEv
564
565
0
    auto add_row = [&](std::shared_ptr<RowInBlock> row, bool with_delete_sign) {
566
0
        if (with_delete_sign) {
567
0
            row_with_delete_sign = std::move(row);
568
0
        } else {
569
0
            row_without_delete_sign = std::move(row);
570
0
        }
571
0
    };
Unexecuted instantiation: _ZZN5doris8MemTable54_aggregate_for_flexible_partial_update_without_seq_colILb0EEEvRKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS4_EERNS3_12MutableBlockERS2_ISt10shared_ptrINS_10RowInBlockEESaISD_EEENKUlSD_bE_clESD_b
Unexecuted instantiation: _ZZN5doris8MemTable54_aggregate_for_flexible_partial_update_without_seq_colILb1EEEvRKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS4_EERNS3_12MutableBlockERS2_ISt10shared_ptrINS_10RowInBlockEESaISD_EEENKUlSD_bE_clESD_b
572
0
    for (const auto& cur_row_ptr : _row_in_blocks) {
573
0
        RowInBlock* cur_row = cur_row_ptr.get();
574
0
        const BitmapValue& skip_bitmap = skip_bitmaps[cur_row->_row_pos];
575
0
        bool cur_row_has_delete_sign = (!skip_bitmap.contains(_delete_sign_col_unique_id) &&
576
0
                                        delete_signs[cur_row->_row_pos] != 0);
577
0
        prev_row =
578
0
                (row_with_delete_sign == nullptr) ? row_without_delete_sign : row_with_delete_sign;
579
        // compare keys, the keys of row_with_delete_sign and row_without_delete_sign is the same,
580
        // choose any of them if it's valid
581
0
        if (prev_row != nullptr && (*_vec_row_comparator)(prev_row.get(), cur_row) == 0) {
582
0
            if (cur_row_has_delete_sign) {
583
0
                if (row_without_delete_sign != nullptr) {
584
                    // if there exits row without delete sign, remove it first
585
0
                    _clear_row_agg(row_without_delete_sign.get());
586
0
                    _stat.merged_rows++;
587
0
                    row_without_delete_sign = nullptr;
588
0
                }
589
                // and then unconditionally replace the previous row
590
0
                prev_row = row_with_delete_sign;
591
0
            } else {
592
0
                prev_row = row_without_delete_sign;
593
0
            }
594
595
0
            if (prev_row == nullptr) {
596
0
                add_row(cur_row_ptr, cur_row_has_delete_sign);
597
0
            } else {
598
0
                if (!prev_row->has_init_agg()) {
599
0
                    _init_row_for_agg(prev_row.get(), mutable_block);
600
0
                }
601
0
                _stat.merged_rows++;
602
0
                _aggregate_two_row_in_block<true>(mutable_block, cur_row, prev_row.get());
603
0
            }
604
0
        } else {
605
0
            finalize_rows();
606
0
            add_row(cur_row_ptr, cur_row_has_delete_sign);
607
0
        }
608
0
    }
609
    // finalize the last lows
610
0
    finalize_rows();
611
0
}
Unexecuted instantiation: _ZN5doris8MemTable54_aggregate_for_flexible_partial_update_without_seq_colILb0EEEvRKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS4_EERNS3_12MutableBlockERS2_ISt10shared_ptrINS_10RowInBlockEESaISD_EE
Unexecuted instantiation: _ZN5doris8MemTable54_aggregate_for_flexible_partial_update_without_seq_colILb1EEEvRKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS4_EERNS3_12MutableBlockERS2_ISt10shared_ptrINS_10RowInBlockEESaISD_EE
612
613
template <bool is_final>
614
void MemTable::_aggregate_for_flexible_partial_update_with_seq_col(
615
        const vectorized::ColumnsWithTypeAndName& block_data,
616
        vectorized::MutableBlock& mutable_block,
617
0
        std::vector<std::shared_ptr<RowInBlock>>& temp_row_in_blocks) {
618
    // For flexible partial update, when table has sequence column, we don't do any aggregation
619
    // in memtable. These duplicate rows will be aggregated in VerticalSegmentWriter
620
0
    int row_pos = -1;
621
0
    for (const auto& row_ptr : _row_in_blocks) {
622
0
        RowInBlock* row = row_ptr.get();
623
0
        temp_row_in_blocks.push_back(row_ptr);
624
0
        _finalize_one_row<is_final>(row, block_data, ++row_pos);
625
0
    }
626
0
}
Unexecuted instantiation: _ZN5doris8MemTable51_aggregate_for_flexible_partial_update_with_seq_colILb0EEEvRKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS4_EERNS3_12MutableBlockERS2_ISt10shared_ptrINS_10RowInBlockEESaISD_EE
Unexecuted instantiation: _ZN5doris8MemTable51_aggregate_for_flexible_partial_update_with_seq_colILb1EEEvRKSt6vectorINS_10vectorized21ColumnWithTypeAndNameESaIS4_EERNS3_12MutableBlockERS2_ISt10shared_ptrINS_10RowInBlockEESaISD_EE
627
628
0
void MemTable::shrink_memtable_by_agg() {
629
0
    SCOPED_CONSUME_MEM_TRACKER(_mem_tracker);
630
0
    if (_keys_type == KeysType::DUP_KEYS) {
631
0
        return;
632
0
    }
633
0
    size_t same_keys_num = _sort();
634
0
    if (same_keys_num != 0) {
635
0
        (_skip_bitmap_col_idx == -1) ? _aggregate<false, false>() : _aggregate<false, true>();
636
0
    }
637
0
}
638
639
42.6k
bool MemTable::need_flush() const {
640
42.6k
    DBUG_EXECUTE_IF("MemTable.need_flush", { return true; });
641
42.6k
    auto max_size = config::write_buffer_size;
642
42.6k
    if (_partial_update_mode == UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS) {
643
159
        auto update_columns_size = _num_columns;
644
159
        auto min_buffer_size = config::min_write_buffer_size_for_partial_update;
645
159
        max_size = max_size * update_columns_size / _tablet_schema->num_columns();
646
159
        max_size = max_size > min_buffer_size ? max_size : min_buffer_size;
647
159
    }
648
42.6k
    return memory_usage() >= max_size;
649
42.6k
}
650
651
42.6k
bool MemTable::need_agg() const {
652
42.6k
    if (_keys_type == KeysType::AGG_KEYS) {
653
468
        auto max_size = config::write_buffer_size_for_agg;
654
468
        return memory_usage() >= max_size;
655
468
    }
656
42.1k
    return false;
657
42.6k
}
658
659
7.68k
Status MemTable::_to_block(std::unique_ptr<vectorized::Block>* res) {
660
7.68k
    size_t same_keys_num = _sort();
661
7.68k
    if (_keys_type == KeysType::DUP_KEYS || same_keys_num == 0) {
662
7.63k
        if (_keys_type == KeysType::DUP_KEYS && _tablet_schema->num_key_columns() == 0) {
663
4
            _output_mutable_block.swap(_input_mutable_block);
664
7.63k
        } else {
665
7.63k
            vectorized::Block in_block = _input_mutable_block.to_block();
666
7.63k
            RETURN_IF_ERROR(_put_into_output(in_block));
667
7.63k
        }
668
7.63k
    } else {
669
18.4E
        (_skip_bitmap_col_idx == -1) ? _aggregate<true, false>() : _aggregate<true, true>();
670
44
    }
671
7.68k
    if (_keys_type == KeysType::UNIQUE_KEYS && _enable_unique_key_mow &&
672
7.68k
        !_tablet_schema->cluster_key_idxes().empty()) {
673
1
        if (_partial_update_mode != UniqueKeyUpdateModePB::UPSERT) {
674
0
            return Status::InternalError(
675
0
                    "Partial update for mow with cluster keys is not supported");
676
0
        }
677
1
        RETURN_IF_ERROR(_sort_by_cluster_keys());
678
1
    }
679
7.68k
    _input_mutable_block.clear();
680
7.68k
    *res = vectorized::Block::create_unique(_output_mutable_block.to_block());
681
7.68k
    return Status::OK();
682
7.68k
}
683
684
7.68k
Status MemTable::to_block(std::unique_ptr<vectorized::Block>* res) {
685
7.68k
    RETURN_IF_ERROR_OR_CATCH_EXCEPTION(_to_block(res));
686
7.67k
    return Status::OK();
687
7.68k
}
688
689
} // namespace doris