Coverage Report

Created: 2026-04-11 14:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/tablet_info.cpp
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
#include "storage/tablet_info.h"
19
20
#include <butil/logging.h>
21
#include <gen_cpp/Descriptors_types.h>
22
#include <gen_cpp/Exprs_types.h>
23
#include <gen_cpp/Partitions_types.h>
24
#include <gen_cpp/Types_types.h>
25
#include <gen_cpp/descriptors.pb.h>
26
#include <gen_cpp/olap_file.pb.h>
27
#include <glog/logging.h>
28
29
#include <algorithm>
30
#include <cstddef>
31
#include <cstdint>
32
#include <memory>
33
#include <ostream>
34
#include <string>
35
#include <tuple>
36
37
#include "common/exception.h"
38
#include "common/logging.h"
39
#include "common/status.h"
40
#include "core/column/column.h"
41
#include "core/data_type/data_type.h"
42
#include "core/data_type/data_type_factory.hpp"
43
#include "core/data_type/define_primitive_type.h"
44
#include "core/data_type/primitive_type.h"
45
#include "core/value/large_int_value.h"
46
#include "runtime/descriptors.h"
47
#include "runtime/memory/mem_tracker.h"
48
#include "storage/tablet/tablet_schema.h"
49
#include "util/raw_value.h"
50
#include "util/string_parser.hpp"
51
#include "util/string_util.h"
52
// NOLINTNEXTLINE(unused-includes)
53
#include "core/value/vdatetime_value.h"
54
#include "exprs/function/cast/cast_to_date_or_datetime_impl.hpp"
55
#include "exprs/function/cast/cast_to_datetimev2_impl.hpp"
56
#include "exprs/function/cast/cast_to_datev2_impl.hpp"
57
#include "exprs/function/cast/cast_to_timestamptz.h"
58
#include "exprs/vexpr_context.h" // IWYU pragma: keep
59
#include "exprs/vliteral.h"
60
61
namespace doris {
62
63
57.0k
void OlapTableIndexSchema::to_protobuf(POlapTableIndexSchema* pindex) const {
64
57.0k
    pindex->set_id(index_id);
65
57.0k
    pindex->set_schema_hash(schema_hash);
66
407k
    for (auto* slot : slots) {
67
407k
        pindex->add_columns(slot->col_name());
68
407k
    }
69
435k
    for (auto* column : columns) {
70
435k
        column->to_schema_pb(pindex->add_columns_desc());
71
435k
    }
72
57.0k
    for (auto* index : indexes) {
73
6.87k
        index->to_schema_pb(pindex->add_indexes_desc());
74
6.87k
    }
75
57.0k
}
76
77
bool VOlapTablePartKeyComparator::operator()(const BlockRowWithIndicator& lhs,
78
59.2M
                                             const BlockRowWithIndicator& rhs) const {
79
59.2M
    Block* l_block = std::get<0>(lhs);
80
59.2M
    Block* r_block = std::get<0>(rhs);
81
59.2M
    int32_t l_row = std::get<1>(lhs);
82
59.2M
    int32_t r_row = std::get<1>(rhs);
83
59.2M
    bool l_use_new = std::get<2>(lhs);
84
59.2M
    bool r_use_new = std::get<2>(rhs);
85
86
18.4E
    VLOG_TRACE << '\n' << l_block->dump_data() << '\n' << r_block->dump_data();
87
88
59.2M
    if (l_row == -1) {
89
172
        return false;
90
59.2M
    } else if (r_row == -1) {
91
30.9M
        return true;
92
30.9M
    }
93
94
28.2M
    if (_param_locs.empty()) { // no transform, use origin column
95
27.2M
        for (auto slot_loc : _slot_locs) {
96
27.2M
            auto res = l_block->get_by_position(slot_loc).column->compare_at(
97
27.2M
                    l_row, r_row, *r_block->get_by_position(slot_loc).column, -1);
98
27.2M
            if (res != 0) {
99
27.0M
                return res < 0;
100
27.0M
            }
101
27.2M
        }
102
27.2M
    } else { // use transformed column to compare
103
18.4E
        DCHECK(_slot_locs.size() == _param_locs.size())
104
18.4E
                << _slot_locs.size() << ' ' << _param_locs.size();
105
106
1.03M
        const std::vector<uint16_t>* l_index = l_use_new ? &_param_locs : &_slot_locs;
107
1.03M
        const std::vector<uint16_t>* r_index = r_use_new ? &_param_locs : &_slot_locs;
108
109
1.41M
        for (int i = 0; i < _slot_locs.size(); i++) {
110
1.08M
            ColumnPtr l_col = l_block->get_by_position((*l_index)[i]).column;
111
1.08M
            ColumnPtr r_col = r_block->get_by_position((*r_index)[i]).column;
112
113
1.08M
            auto res = l_col->compare_at(l_row, r_row, *r_col, -1);
114
1.08M
            if (res != 0) {
115
714k
                return res < 0;
116
714k
            }
117
1.08M
        }
118
1.03M
    }
119
120
    // equal, return false
121
440k
    return false;
122
28.2M
}
123
124
30.9k
Status OlapTableSchemaParam::init(const POlapTableSchemaParam& pschema) {
125
30.9k
    _db_id = pschema.db_id();
126
30.9k
    _table_id = pschema.table_id();
127
30.9k
    _version = pschema.version();
128
30.9k
    if (pschema.has_unique_key_update_mode()) {
129
30.9k
        _unique_key_update_mode = pschema.unique_key_update_mode();
130
30.9k
        if (pschema.has_sequence_map_col_unique_id()) {
131
30.9k
            _sequence_map_col_uid = pschema.sequence_map_col_unique_id();
132
30.9k
        }
133
18.4E
    } else {
134
        // for backward compatibility
135
18.4E
        if (pschema.has_partial_update() && pschema.partial_update()) {
136
0
            _unique_key_update_mode = UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS;
137
18.4E
        } else {
138
18.4E
            _unique_key_update_mode = UniqueKeyUpdateModePB::UPSERT;
139
18.4E
        }
140
18.4E
    }
141
30.9k
    _is_strict_mode = pschema.is_strict_mode();
142
30.9k
    if (_unique_key_update_mode == UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS) {
143
2.72k
        _auto_increment_column = pschema.auto_increment_column();
144
2.72k
        if (!_auto_increment_column.empty() && pschema.auto_increment_column_unique_id() == -1) {
145
0
            return Status::InternalError(
146
0
                    "Auto increment column id is not set in FE. Maybe FE is an older version "
147
0
                    "different from BE.");
148
0
        }
149
2.72k
        _auto_increment_column_unique_id = pschema.auto_increment_column_unique_id();
150
2.72k
    }
151
30.9k
    if (_unique_key_update_mode != UniqueKeyUpdateModePB::UPSERT) {
152
2.88k
        if (pschema.has_partial_update_new_key_policy()) {
153
2.88k
            _partial_update_new_row_policy = pschema.partial_update_new_key_policy();
154
2.88k
        }
155
2.88k
    }
156
30.9k
    _timestamp_ms = pschema.timestamp_ms();
157
30.9k
    if (pschema.has_nano_seconds()) {
158
30.9k
        _nano_seconds = pschema.nano_seconds();
159
30.9k
    }
160
30.9k
    _timezone = pschema.timezone();
161
162
30.9k
    for (const auto& col : pschema.partial_update_input_columns()) {
163
17.4k
        _partial_update_input_columns.insert(col);
164
17.4k
    }
165
30.9k
    std::unordered_map<std::string, SlotDescriptor*> slots_map;
166
167
30.9k
    _tuple_desc = _obj_pool.add(new TupleDescriptor(pschema.tuple_desc()));
168
169
277k
    for (const auto& p_slot_desc : pschema.slot_descs()) {
170
277k
        auto* slot_desc = _obj_pool.add(new SlotDescriptor(p_slot_desc));
171
277k
        _tuple_desc->add_slot(slot_desc);
172
277k
        std::string data_type;
173
277k
        EnumToString(TPrimitiveType, to_thrift(slot_desc->col_type()), data_type);
174
277k
        std::string is_null_str = slot_desc->is_nullable() ? "true" : "false";
175
277k
        std::string data_type_str =
176
277k
                std::to_string(int64_t(TabletColumn::get_field_type_by_string(data_type)));
177
277k
        slots_map.emplace(to_lower(slot_desc->col_name()) + "+" + data_type_str + is_null_str,
178
277k
                          slot_desc);
179
277k
    }
180
181
38.8k
    for (const auto& p_index : pschema.indexes()) {
182
38.8k
        auto* index = _obj_pool.add(new OlapTableIndexSchema());
183
38.8k
        index->index_id = p_index.id();
184
38.8k
        index->schema_hash = p_index.schema_hash();
185
301k
        for (const auto& pcolumn_desc : p_index.columns_desc()) {
186
301k
            if (_unique_key_update_mode != UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS ||
187
301k
                _partial_update_input_columns.contains(pcolumn_desc.name())) {
188
280k
                std::string is_null_str = pcolumn_desc.is_nullable() ? "true" : "false";
189
280k
                std::string data_type_str = std::to_string(
190
280k
                        int64_t(TabletColumn::get_field_type_by_string(pcolumn_desc.type())));
191
280k
                auto it = slots_map.find(to_lower(pcolumn_desc.name()) + "+" + data_type_str +
192
280k
                                         is_null_str);
193
280k
                if (it == std::end(slots_map)) {
194
0
                    std::string keys {};
195
0
                    for (const auto& [key, _] : slots_map) {
196
0
                        keys += fmt::format("{},", key);
197
0
                    }
198
0
                    LOG_EVERY_SECOND(WARNING) << fmt::format(
199
0
                            "[OlapTableSchemaParam::init(const POlapTableSchemaParam& pschema)]: "
200
0
                            "unknown index column, column={}, type={}, data_type_str={}, "
201
0
                            "is_null_str={}, slots_map.keys()=[{}], {}\npschema={}",
202
0
                            pcolumn_desc.name(), pcolumn_desc.type(), data_type_str, is_null_str,
203
0
                            keys, debug_string(), pschema.ShortDebugString());
204
205
0
                    return Status::InternalError("unknown index column, column={}, type={}",
206
0
                                                 pcolumn_desc.name(), pcolumn_desc.type());
207
0
                }
208
280k
                index->slots.emplace_back(it->second);
209
280k
            }
210
301k
            TabletColumn* tc = _obj_pool.add(new TabletColumn());
211
301k
            tc->init_from_pb(pcolumn_desc);
212
301k
            index->columns.emplace_back(tc);
213
301k
        }
214
38.8k
        for (const auto& pindex_desc : p_index.indexes_desc()) {
215
5.84k
            TabletIndex* ti = _obj_pool.add(new TabletIndex());
216
5.84k
            ti->init_from_pb(pindex_desc);
217
5.84k
            index->indexes.emplace_back(ti);
218
5.84k
        }
219
38.8k
        _indexes.emplace_back(index);
220
38.8k
    }
221
222
30.9k
    std::sort(_indexes.begin(), _indexes.end(),
223
32.9k
              [](const OlapTableIndexSchema* lhs, const OlapTableIndexSchema* rhs) {
224
32.9k
                  return lhs->index_id < rhs->index_id;
225
32.9k
              });
226
30.9k
    return Status::OK();
227
30.9k
}
228
229
85.8k
Status OlapTableSchemaParam::init_unique_key_update_mode(const TOlapTableSchemaParam& tschema) {
230
85.8k
    if (tschema.__isset.unique_key_update_mode) {
231
85.8k
        switch (tschema.unique_key_update_mode) {
232
78.6k
        case doris::TUniqueKeyUpdateMode::UPSERT: {
233
78.6k
            _unique_key_update_mode = UniqueKeyUpdateModePB::UPSERT;
234
78.6k
            break;
235
0
        }
236
7.05k
        case doris::TUniqueKeyUpdateMode::UPDATE_FIXED_COLUMNS: {
237
7.05k
            _unique_key_update_mode = UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS;
238
7.05k
            break;
239
0
        }
240
157
        case doris::TUniqueKeyUpdateMode::UPDATE_FLEXIBLE_COLUMNS: {
241
157
            _unique_key_update_mode = UniqueKeyUpdateModePB::UPDATE_FLEXIBLE_COLUMNS;
242
157
            break;
243
0
        }
244
0
        default: {
245
0
            return Status::InternalError(
246
0
                    "Unknown unique_key_update_mode: {}, should be one of "
247
0
                    "UPSERT/UPDATE_FIXED_COLUMNS/UPDATE_FLEXIBLE_COLUMNS",
248
0
                    tschema.unique_key_update_mode);
249
0
        }
250
85.8k
        }
251
85.8k
        if (tschema.__isset.sequence_map_col_unique_id) {
252
85.8k
            _sequence_map_col_uid = tschema.sequence_map_col_unique_id;
253
85.8k
        }
254
85.8k
    } else {
255
        // for backward compatibility
256
20
        if (tschema.__isset.is_partial_update && tschema.is_partial_update) {
257
0
            _unique_key_update_mode = UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS;
258
20
        } else {
259
20
            _unique_key_update_mode = UniqueKeyUpdateModePB::UPSERT;
260
20
        }
261
20
    }
262
85.8k
    return Status::OK();
263
85.8k
}
264
265
85.8k
Status OlapTableSchemaParam::init(const TOlapTableSchemaParam& tschema) {
266
85.8k
    _db_id = tschema.db_id;
267
85.8k
    _table_id = tschema.table_id;
268
85.8k
    _version = tschema.version;
269
85.8k
    RETURN_IF_ERROR(init_unique_key_update_mode(tschema));
270
85.8k
    if (tschema.__isset.is_strict_mode) {
271
85.8k
        _is_strict_mode = tschema.is_strict_mode;
272
85.8k
    }
273
85.8k
    if (_unique_key_update_mode == UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS) {
274
7.05k
        _auto_increment_column = tschema.auto_increment_column;
275
7.05k
        if (!_auto_increment_column.empty() && tschema.auto_increment_column_unique_id == -1) {
276
0
            return Status::InternalError(
277
0
                    "Auto increment column id is not set in FE. Maybe FE is an older version "
278
0
                    "different from BE.");
279
0
        }
280
7.05k
        _auto_increment_column_unique_id = tschema.auto_increment_column_unique_id;
281
7.05k
    }
282
283
85.8k
    if (_unique_key_update_mode != UniqueKeyUpdateModePB::UPSERT) {
284
7.21k
        if (tschema.__isset.partial_update_new_key_policy) {
285
7.21k
            switch (tschema.partial_update_new_key_policy) {
286
7.12k
            case doris::TPartialUpdateNewRowPolicy::APPEND: {
287
7.12k
                _partial_update_new_row_policy = PartialUpdateNewRowPolicyPB::APPEND;
288
7.12k
                break;
289
0
            }
290
85
            case doris::TPartialUpdateNewRowPolicy::ERROR: {
291
85
                _partial_update_new_row_policy = PartialUpdateNewRowPolicyPB::ERROR;
292
85
                break;
293
0
            }
294
0
            default: {
295
0
                return Status::InvalidArgument(
296
0
                        "Unknown partial_update_new_key_behavior: {}, should be one of "
297
0
                        "'APPEND' or 'ERROR'",
298
0
                        tschema.partial_update_new_key_policy);
299
0
            }
300
7.21k
            }
301
7.21k
        }
302
7.21k
    }
303
304
85.8k
    for (const auto& tcolumn : tschema.partial_update_input_columns) {
305
39.1k
        _partial_update_input_columns.insert(tcolumn);
306
39.1k
    }
307
85.8k
    std::unordered_map<std::string, SlotDescriptor*> slots_map;
308
85.8k
    _tuple_desc = _obj_pool.add(new TupleDescriptor(tschema.tuple_desc));
309
628k
    for (const auto& t_slot_desc : tschema.slot_descs) {
310
628k
        auto* slot_desc = _obj_pool.add(new SlotDescriptor(t_slot_desc));
311
628k
        _tuple_desc->add_slot(slot_desc);
312
628k
        std::string is_null_str = slot_desc->is_nullable() ? "true" : "false";
313
628k
        std::string data_type_str = std::to_string(int64_t(slot_desc->col_type()));
314
628k
        slots_map.emplace(to_lower(slot_desc->col_name()) + "+" + data_type_str + is_null_str,
315
628k
                          slot_desc);
316
628k
    }
317
318
87.7k
    for (const auto& t_index : tschema.indexes) {
319
87.7k
        std::unordered_map<std::string, int32_t> index_slots_map;
320
87.7k
        auto* index = _obj_pool.add(new OlapTableIndexSchema());
321
87.7k
        index->index_id = t_index.id;
322
87.7k
        index->schema_hash = t_index.schema_hash;
323
678k
        for (const auto& tcolumn_desc : t_index.columns_desc) {
324
678k
            if (_unique_key_update_mode != UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS ||
325
678k
                _partial_update_input_columns.contains(tcolumn_desc.column_name)) {
326
630k
                std::string is_null_str = tcolumn_desc.is_allow_null ? "true" : "false";
327
630k
                std::string data_type_str =
328
630k
                        std::to_string(int64_t(thrift_to_type(tcolumn_desc.column_type.type)));
329
630k
                auto it = slots_map.find(to_lower(tcolumn_desc.column_name) + "+" + data_type_str +
330
630k
                                         is_null_str);
331
630k
                if (it == slots_map.end()) {
332
0
                    std::stringstream ss;
333
0
                    ss << tschema;
334
0
                    std::string keys {};
335
0
                    for (const auto& [key, _] : slots_map) {
336
0
                        keys += fmt::format("{},", key);
337
0
                    }
338
0
                    LOG_EVERY_SECOND(WARNING) << fmt::format(
339
0
                            "[OlapTableSchemaParam::init(const TOlapTableSchemaParam& tschema)]: "
340
0
                            "unknown index column, column={}, type={}, data_type_str={}, "
341
0
                            "is_null_str={}, slots_map.keys()=[{}], {}\ntschema={}",
342
0
                            tcolumn_desc.column_name, tcolumn_desc.column_type.type, data_type_str,
343
0
                            is_null_str, keys, debug_string(), ss.str());
344
0
                    return Status::InternalError("unknown index column, column={}, type={}",
345
0
                                                 tcolumn_desc.column_name,
346
0
                                                 tcolumn_desc.column_type.type);
347
0
                }
348
630k
                index->slots.emplace_back(it->second);
349
630k
            }
350
678k
            index_slots_map.emplace(to_lower(tcolumn_desc.column_name), tcolumn_desc.col_unique_id);
351
678k
            TabletColumn* tc = _obj_pool.add(new TabletColumn());
352
678k
            tc->init_from_thrift(tcolumn_desc);
353
678k
            index->columns.emplace_back(tc);
354
678k
        }
355
87.7k
        if (t_index.__isset.indexes_desc) {
356
87.6k
            for (const auto& tindex_desc : t_index.indexes_desc) {
357
11.3k
                std::vector<int32_t> column_unique_ids(tindex_desc.columns.size());
358
22.6k
                for (size_t i = 0; i < tindex_desc.columns.size(); i++) {
359
11.3k
                    auto it = index_slots_map.find(to_lower(tindex_desc.columns[i]));
360
11.3k
                    if (it != index_slots_map.end()) {
361
11.3k
                        column_unique_ids[i] = it->second;
362
11.3k
                    }
363
11.3k
                }
364
11.3k
                TabletIndex* ti = _obj_pool.add(new TabletIndex());
365
11.3k
                ti->init_from_thrift(tindex_desc, column_unique_ids);
366
11.3k
                index->indexes.emplace_back(ti);
367
11.3k
            }
368
87.6k
        }
369
87.7k
        if (t_index.__isset.where_clause) {
370
66
            RETURN_IF_ERROR(VExpr::create_expr_tree(t_index.where_clause, index->where_clause));
371
66
        }
372
87.7k
        _indexes.emplace_back(index);
373
87.7k
    }
374
375
85.8k
    std::sort(_indexes.begin(), _indexes.end(),
376
85.8k
              [](const OlapTableIndexSchema* lhs, const OlapTableIndexSchema* rhs) {
377
5.88k
                  return lhs->index_id < rhs->index_id;
378
5.88k
              });
379
85.8k
    return Status::OK();
380
85.8k
}
381
382
55.8k
void OlapTableSchemaParam::to_protobuf(POlapTableSchemaParam* pschema) const {
383
55.8k
    pschema->set_db_id(_db_id);
384
55.8k
    pschema->set_table_id(_table_id);
385
55.8k
    pschema->set_version(_version);
386
55.8k
    pschema->set_unique_key_update_mode(_unique_key_update_mode);
387
55.8k
    if (_unique_key_update_mode == UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS) {
388
        // for backward compatibility
389
4.08k
        pschema->set_partial_update(true);
390
4.08k
    }
391
55.8k
    pschema->set_partial_update_new_key_policy(_partial_update_new_row_policy);
392
55.8k
    pschema->set_is_strict_mode(_is_strict_mode);
393
55.8k
    pschema->set_auto_increment_column(_auto_increment_column);
394
55.8k
    pschema->set_auto_increment_column_unique_id(_auto_increment_column_unique_id);
395
55.8k
    pschema->set_timestamp_ms(_timestamp_ms);
396
55.8k
    pschema->set_timezone(_timezone);
397
55.8k
    pschema->set_nano_seconds(_nano_seconds);
398
55.8k
    pschema->set_sequence_map_col_unique_id(_sequence_map_col_uid);
399
55.8k
    for (auto col : _partial_update_input_columns) {
400
21.0k
        *pschema->add_partial_update_input_columns() = col;
401
21.0k
    }
402
55.8k
    _tuple_desc->to_protobuf(pschema->mutable_tuple_desc());
403
405k
    for (auto* slot : _tuple_desc->slots()) {
404
405k
        slot->to_protobuf(pschema->add_slot_descs());
405
405k
    }
406
57.1k
    for (auto* index : _indexes) {
407
57.1k
        index->to_protobuf(pschema->add_indexes());
408
57.1k
    }
409
55.8k
}
410
411
0
std::string OlapTableSchemaParam::debug_string() const {
412
0
    std::stringstream ss;
413
0
    ss << "tuple_desc=" << _tuple_desc->debug_string();
414
0
    return ss.str();
415
0
}
416
417
VOlapTablePartitionParam::VOlapTablePartitionParam(std::shared_ptr<OlapTableSchemaParam>& schema,
418
                                                   const TOlapTablePartitionParam& t_param)
419
58.0k
        : _schema(schema),
420
58.0k
          _t_param(t_param),
421
58.0k
          _slots(_schema->tuple_desc()->slots()),
422
58.0k
          _mem_tracker(std::make_unique<MemTracker>("OlapTablePartitionParam")),
423
58.0k
          _part_type(t_param.partition_type) {
424
58.0k
    if (t_param.__isset.enable_automatic_partition && t_param.enable_automatic_partition) {
425
297
        _is_auto_partition = true;
426
297
        auto size = t_param.partition_function_exprs.size();
427
297
        _part_func_ctx.resize(size);
428
297
        _partition_function.resize(size);
429
297
        DCHECK((t_param.partition_type == TPartitionType::RANGE_PARTITIONED && size == 1) ||
430
1
               (t_param.partition_type == TPartitionType::LIST_PARTITIONED && size >= 1))
431
1
                << "now support only 1 partition column for auto range partitions. "
432
1
                << t_param.partition_type << " " << size;
433
604
        for (int i = 0; i < size; ++i) {
434
307
            Status st =
435
307
                    VExpr::create_expr_tree(t_param.partition_function_exprs[i], _part_func_ctx[i]);
436
307
            if (!st.ok()) {
437
0
                throw Exception(Status::InternalError("Partition function expr is not valid"),
438
0
                                "Partition function expr is not valid");
439
0
            }
440
307
            _partition_function[i] = _part_func_ctx[i]->root();
441
307
        }
442
297
    }
443
444
58.0k
    if (t_param.__isset.enable_auto_detect_overwrite && t_param.enable_auto_detect_overwrite) {
445
43
        _is_auto_detect_overwrite = true;
446
43
        DCHECK(t_param.__isset.overwrite_group_id);
447
43
        _overwrite_group_id = t_param.overwrite_group_id;
448
43
    }
449
450
58.0k
    if (t_param.__isset.master_address) {
451
40
        _master_address = std::make_shared<TNetworkAddress>(t_param.master_address);
452
40
    }
453
454
58.0k
    if (_is_auto_partition) {
455
        // the nullable mode depends on partition_exprs. not column slots. so use them.
456
296
        DCHECK(_partition_function.size() <= _slots.size())
457
0
                << _partition_function.size() << ", " << _slots.size();
458
459
        // suppose (k0, [k1], [k2]), so get [k1, 0], [k2, 1]
460
296
        std::map<std::string, int> partition_slots_map; // name to idx in part_exprs
461
604
        for (size_t i = 0; i < t_param.partition_columns.size(); i++) {
462
308
            partition_slots_map.emplace(t_param.partition_columns[i], i);
463
308
        }
464
465
        // here we rely on the same order and number of the _part_funcs and _slots in the prefix
466
        // _part_block contains all slots of table.
467
1.14k
        for (auto* slot : _slots) {
468
            // try to replace with partition expr.
469
1.14k
            if (auto it = partition_slots_map.find(slot->col_name());
470
1.14k
                it != partition_slots_map.end()) { // it's a partition column slot
471
308
                auto& expr_type = _partition_function[it->second]->data_type();
472
308
                _partition_block.insert({expr_type->create_column(), expr_type, slot->col_name()});
473
832
            } else {
474
832
                _partition_block.insert({slot->get_empty_mutable_column(),
475
832
                                         slot->get_data_type_ptr(), slot->col_name()});
476
832
            }
477
1.14k
        }
478
18.4E
        VLOG_TRACE << _partition_block.dump_structure();
479
57.7k
    } else {
480
        // we insert all. but not all will be used. it will controlled by _partition_slot_locs
481
407k
        for (auto* slot : _slots) {
482
407k
            _partition_block.insert({slot->get_empty_mutable_column(), slot->get_data_type_ptr(),
483
407k
                                     slot->col_name()});
484
407k
        }
485
57.7k
    }
486
58.0k
}
487
488
58.1k
VOlapTablePartitionParam::~VOlapTablePartitionParam() {
489
58.1k
    _mem_tracker->release(_mem_usage);
490
58.1k
}
491
492
57.8k
Status VOlapTablePartitionParam::init() {
493
57.8k
    std::vector<std::string> slot_column_names;
494
409k
    for (auto* slot_desc : _schema->tuple_desc()->slots()) {
495
409k
        slot_column_names.emplace_back(slot_desc->col_name());
496
409k
    }
497
498
57.8k
    auto find_slot_locs = [&slot_column_names](const std::string& slot_name,
499
57.8k
                                               std::vector<uint16_t>& locs,
500
77.7k
                                               const std::string& column_type) {
501
77.7k
        auto it = std::find(slot_column_names.begin(), slot_column_names.end(), slot_name);
502
77.7k
        if (it == slot_column_names.end()) {
503
0
            return Status::InternalError("{} column not found, column ={}", column_type, slot_name);
504
0
        }
505
77.7k
        locs.emplace_back(it - slot_column_names.begin());
506
77.7k
        return Status::OK();
507
77.7k
    };
508
509
    // here we find the partition columns. others maybe non-partition columns/special columns.
510
57.8k
    if (_t_param.__isset.partition_columns) {
511
8.71k
        for (auto& part_col : _t_param.partition_columns) {
512
8.71k
            RETURN_IF_ERROR(find_slot_locs(part_col, _partition_slot_locs, "partition"));
513
8.71k
        }
514
8.57k
    }
515
516
57.8k
    _partitions_map = std::make_unique<
517
57.8k
            std::map<BlockRowWithIndicator, VOlapTablePartition*, VOlapTablePartKeyComparator>>(
518
57.8k
            VOlapTablePartKeyComparator(_partition_slot_locs, _transformed_slot_locs));
519
57.8k
    if (_t_param.__isset.distributed_columns) {
520
69.0k
        for (auto& col : _t_param.distributed_columns) {
521
69.0k
            RETURN_IF_ERROR(find_slot_locs(col, _distributed_slot_locs, "distributed"));
522
69.0k
        }
523
57.8k
    }
524
525
    // for both auto/non-auto partition table.
526
57.8k
    _is_in_partition = _part_type == TPartitionType::type::LIST_PARTITIONED;
527
528
    // initial partitions. if meet dummy partitions only for open BE nodes, not generate key of them for finding
529
72.0k
    for (const auto& t_part : _t_param.partitions) {
530
72.0k
        VOlapTablePartition* part = nullptr;
531
72.0k
        RETURN_IF_ERROR(generate_partition_from(t_part, part));
532
72.0k
        _partitions.emplace_back(part);
533
534
72.0k
        if (!_t_param.partitions_is_fake) {
535
72.0k
            if (_is_in_partition) {
536
8.12k
                for (auto& in_key : part->in_keys) {
537
8.12k
                    _partitions_map->emplace(std::tuple {in_key.first, in_key.second, false}, part);
538
8.12k
                }
539
66.5k
            } else {
540
66.5k
                _partitions_map->emplace(
541
66.5k
                        std::tuple {part->end_key.first, part->end_key.second, false}, part);
542
66.5k
            }
543
72.0k
        }
544
72.0k
    }
545
546
57.8k
    _mem_usage = _partition_block.allocated_bytes();
547
57.8k
    _mem_tracker->consume(_mem_usage);
548
57.8k
    return Status::OK();
549
57.8k
}
550
551
bool VOlapTablePartitionParam::_part_contains(VOlapTablePartition* part,
552
37.8M
                                              BlockRowWithIndicator key) const {
553
37.8M
    VOlapTablePartKeyComparator comparator(_partition_slot_locs, _transformed_slot_locs);
554
    // we have used upper_bound to find to ensure key < part.right and this part is closest(right - key is min)
555
    // now we only have to check (key >= part.left). the comparator(a,b) means a < b, so we use anti
556
37.8M
    return part->start_key.second == -1 /* spj: start_key.second == -1 means only single partition*/
557
37.8M
           || !comparator(key, std::tuple {part->start_key.first, part->start_key.second, false});
558
37.8M
}
559
560
// insert value into _partition_block's column
561
// NOLINTBEGIN(readability-function-size)
562
42.6k
static Status _create_partition_key(const TExprNode& t_expr, BlockRow* part_key, uint16_t pos) {
563
42.6k
    auto column = std::move(*part_key->first->get_by_position(pos).column).mutate();
564
42.6k
    switch (t_expr.node_type) {
565
26.5k
    case TExprNodeType::DATE_LITERAL: {
566
26.5k
        auto primitive_type =
567
26.5k
                DataTypeFactory::instance().create_data_type(t_expr.type)->get_primitive_type();
568
26.5k
        if (primitive_type == TYPE_DATEV2) {
569
19.8k
            DateV2Value<DateV2ValueType> dt;
570
19.8k
            CastParameters params;
571
19.8k
            if (!CastToDateV2::from_string_strict_mode<DatelikeParseMode::STRICT>(
572
19.8k
                        {t_expr.date_literal.value.c_str(), t_expr.date_literal.value.size()}, dt,
573
19.8k
                        nullptr, params)) {
574
0
                std::stringstream ss;
575
0
                ss << "invalid date literal in partition column, date=" << t_expr.date_literal;
576
0
                return Status::InternalError(ss.str());
577
0
            }
578
19.8k
            column->insert_data(reinterpret_cast<const char*>(&dt), 0);
579
19.8k
        } else if (primitive_type == TYPE_DATETIMEV2) {
580
6.08k
            DateV2Value<DateTimeV2ValueType> dt;
581
6.08k
            const int32_t scale =
582
6.08k
                    t_expr.type.types.empty() ? -1 : t_expr.type.types.front().scalar_type.scale;
583
6.08k
            CastParameters params;
584
6.08k
            if (!CastToDatetimeV2::from_string_strict_mode<DatelikeParseMode::STRICT>(
585
6.08k
                        {t_expr.date_literal.value.c_str(), t_expr.date_literal.value.size()}, dt,
586
6.08k
                        nullptr, scale, params)) {
587
0
                std::stringstream ss;
588
0
                ss << "invalid date literal in partition column, date=" << t_expr.date_literal;
589
0
                return Status::InternalError(ss.str());
590
0
            }
591
6.08k
            column->insert_data(reinterpret_cast<const char*>(&dt), 0);
592
6.08k
        } else if (primitive_type == TYPE_TIMESTAMPTZ) {
593
387
            TimestampTzValue res;
594
387
            CastParameters params {.status = Status::OK(), .is_strict = true};
595
387
            const int32_t scale =
596
387
                    t_expr.type.types.empty() ? -1 : t_expr.type.types.front().scalar_type.scale;
597
387
            if (!CastToTimestampTz::from_string(
598
387
                        {t_expr.date_literal.value.c_str(), t_expr.date_literal.value.size()}, res,
599
387
                        params, nullptr, scale)) [[unlikely]] {
600
0
                std::stringstream ss;
601
0
                ss << "invalid timestamptz literal in partition column, value="
602
0
                   << t_expr.date_literal;
603
0
                return Status::InternalError(ss.str());
604
0
            }
605
387
            column->insert_data(reinterpret_cast<const char*>(&res), 0);
606
387
        } else {
607
257
            VecDateTimeValue dt;
608
257
            CastParameters params;
609
257
            if (!CastToDateOrDatetime::from_string_strict_mode<DatelikeParseMode::STRICT,
610
257
                                                               DatelikeTargetType::DATE_TIME>(
611
257
                        {t_expr.date_literal.value.c_str(), t_expr.date_literal.value.size()}, dt,
612
257
                        nullptr, params)) {
613
0
                std::stringstream ss;
614
0
                ss << "invalid date literal in partition column, date=" << t_expr.date_literal;
615
0
                return Status::InternalError(ss.str());
616
0
            }
617
257
            if (primitive_type == TYPE_DATE) {
618
120
                dt.cast_to_date();
619
120
            }
620
257
            column->insert_data(reinterpret_cast<const char*>(&dt), 0);
621
257
        }
622
26.5k
        break;
623
26.5k
    }
624
26.5k
    case TExprNodeType::INT_LITERAL: {
625
13.0k
        switch (t_expr.type.types[0].scalar_type.type) {
626
2.12k
        case TPrimitiveType::TINYINT: {
627
2.12k
            auto value = cast_set<int8_t>(t_expr.int_literal.value);
628
2.12k
            column->insert_data(reinterpret_cast<const char*>(&value), 0);
629
2.12k
            break;
630
0
        }
631
378
        case TPrimitiveType::SMALLINT: {
632
378
            auto value = cast_set<int16_t>(t_expr.int_literal.value);
633
378
            column->insert_data(reinterpret_cast<const char*>(&value), 0);
634
378
            break;
635
0
        }
636
9.93k
        case TPrimitiveType::INT: {
637
9.93k
            auto value = cast_set<int32_t>(t_expr.int_literal.value);
638
9.93k
            column->insert_data(reinterpret_cast<const char*>(&value), 0);
639
9.93k
            break;
640
0
        }
641
593
        default:
642
593
            int64_t value = t_expr.int_literal.value;
643
593
            column->insert_data(reinterpret_cast<const char*>(&value), 0);
644
13.0k
        }
645
13.0k
        break;
646
13.0k
    }
647
13.0k
    case TExprNodeType::LARGE_INT_LITERAL: {
648
148
        StringParser::ParseResult parse_result = StringParser::PARSE_SUCCESS;
649
148
        auto value = StringParser::string_to_int<__int128>(t_expr.large_int_literal.value.c_str(),
650
148
                                                           t_expr.large_int_literal.value.size(),
651
148
                                                           &parse_result);
652
148
        if (parse_result != StringParser::PARSE_SUCCESS) {
653
0
            value = MAX_INT128;
654
0
        }
655
148
        column->insert_data(reinterpret_cast<const char*>(&value), 0);
656
148
        break;
657
13.0k
    }
658
2.73k
    case TExprNodeType::STRING_LITERAL: {
659
2.73k
        size_t len = t_expr.string_literal.value.size();
660
2.73k
        const char* str_val = t_expr.string_literal.value.c_str();
661
2.73k
        column->insert_data(str_val, len);
662
2.73k
        break;
663
13.0k
    }
664
23
    case TExprNodeType::BOOL_LITERAL: {
665
23
        column->insert_data(reinterpret_cast<const char*>(&t_expr.bool_literal.value), 0);
666
23
        break;
667
13.0k
    }
668
114
    case TExprNodeType::NULL_LITERAL: {
669
        // insert a null literal
670
114
        if (!column->is_nullable()) {
671
            // https://github.com/apache/doris/pull/39449 have forbid this cause. always add this check as protective measures
672
0
            return Status::InternalError("The column {} is not null, can't insert into NULL value.",
673
0
                                         part_key->first->get_by_position(pos).name);
674
0
        }
675
114
        column->insert_data(nullptr, 0);
676
114
        break;
677
114
    }
678
0
    default: {
679
0
        return Status::InternalError("unsupported partition column node type, type={}",
680
0
                                     t_expr.node_type);
681
114
    }
682
42.6k
    }
683
42.6k
    part_key->second = cast_set<int32_t>(column->size() - 1);
684
42.6k
    return Status::OK();
685
42.6k
}
686
// NOLINTEND(readability-function-size)
687
688
Status VOlapTablePartitionParam::_create_partition_keys(const std::vector<TExprNode>& t_exprs,
689
41.7k
                                                        BlockRow* part_key) {
690
84.4k
    for (int i = 0; i < t_exprs.size(); i++) {
691
42.6k
        RETURN_IF_ERROR(_create_partition_key(t_exprs[i], part_key, _partition_slot_locs[i]));
692
42.6k
    }
693
41.7k
    return Status::OK();
694
41.7k
}
695
696
Status VOlapTablePartitionParam::generate_partition_from(const TOlapTablePartition& t_part,
697
72.3k
                                                         VOlapTablePartition*& part_result) {
698
72.3k
    DCHECK(part_result == nullptr);
699
    // here we set the default value of partition bounds first! if it doesn't have some key, it will be -1.
700
72.3k
    part_result = _obj_pool.add(new VOlapTablePartition(&_partition_block));
701
72.3k
    part_result->id = t_part.id;
702
72.3k
    part_result->is_mutable = t_part.is_mutable;
703
    // only load_to_single_tablet = true will set load_tablet_idx
704
72.3k
    if (t_part.__isset.load_tablet_idx) {
705
22.6k
        part_result->load_tablet_idx = t_part.load_tablet_idx;
706
22.6k
    }
707
708
72.3k
    if (_is_in_partition) {
709
8.36k
        for (const auto& keys : t_part.in_keys) {
710
8.36k
            RETURN_IF_ERROR(_create_partition_keys(
711
8.36k
                    keys, &part_result->in_keys.emplace_back(&_partition_block, -1)));
712
8.36k
        }
713
5.75k
        if (t_part.__isset.is_default_partition && t_part.is_default_partition &&
714
5.75k
            _default_partition == nullptr) {
715
20
            _default_partition = part_result;
716
20
        }
717
66.6k
    } else { // range
718
66.6k
        if (t_part.__isset.start_keys) {
719
15.8k
            RETURN_IF_ERROR(_create_partition_keys(t_part.start_keys, &part_result->start_key));
720
15.8k
        }
721
        // we generate the right bound but not insert into partition map
722
66.6k
        if (t_part.__isset.end_keys) {
723
17.0k
            RETURN_IF_ERROR(_create_partition_keys(t_part.end_keys, &part_result->end_key));
724
17.0k
        }
725
66.6k
    }
726
727
72.3k
    part_result->num_buckets = t_part.num_buckets;
728
72.3k
    auto num_indexes = _schema->indexes().size();
729
72.3k
    if (t_part.indexes.size() != num_indexes) {
730
0
        return Status::InternalError(
731
0
                "number of partition's index is not equal with schema's"
732
0
                ", num_part_indexes={}, num_schema_indexes={}",
733
0
                t_part.indexes.size(), num_indexes);
734
0
    }
735
72.3k
    part_result->indexes = t_part.indexes;
736
72.3k
    std::sort(part_result->indexes.begin(), part_result->indexes.end(),
737
72.3k
              [](const OlapTableIndexTablets& lhs, const OlapTableIndexTablets& rhs) {
738
4.65k
                  return lhs.index_id < rhs.index_id;
739
4.65k
              });
740
    // check index
741
146k
    for (int j = 0; j < num_indexes; ++j) {
742
74.0k
        if (part_result->indexes[j].index_id != _schema->indexes()[j]->index_id) {
743
0
            return Status::InternalError(
744
0
                    "partition's index is not equal with schema's"
745
0
                    ", part_index={}, schema_index={}",
746
0
                    part_result->indexes[j].index_id, _schema->indexes()[j]->index_id);
747
0
        }
748
74.0k
    }
749
72.3k
    if (t_part.__isset.total_replica_num) {
750
72.2k
        part_result->total_replica_num = t_part.total_replica_num;
751
72.2k
    }
752
72.3k
    if (t_part.__isset.load_required_replica_num) {
753
72.3k
        part_result->load_required_replica_num = t_part.load_required_replica_num;
754
72.3k
    }
755
72.3k
    if (t_part.__isset.tablet_version_gap_backends) {
756
0
        for (const auto& [tablet_id, backend_ids] : t_part.tablet_version_gap_backends) {
757
0
            auto& gap_set = part_result->tablet_version_gap_backends[tablet_id];
758
0
            for (auto backend_id : backend_ids) {
759
0
                gap_set.insert(backend_id);
760
0
            }
761
0
        }
762
0
    }
763
72.3k
    return Status::OK();
764
72.3k
}
765
766
Status VOlapTablePartitionParam::add_partitions(
767
168
        const std::vector<TOlapTablePartition>& partitions) {
768
335
    for (const auto& t_part : partitions) {
769
335
        auto* part = _obj_pool.add(new VOlapTablePartition(&_partition_block));
770
335
        part->id = t_part.id;
771
335
        part->is_mutable = t_part.is_mutable;
772
773
        // we dont pass right keys when it's MAX_VALUE. so there's possibility we only have start_key but not end_key
774
        // range partition
775
335
        if (t_part.__isset.start_keys) {
776
147
            RETURN_IF_ERROR(_create_partition_keys(t_part.start_keys, &part->start_key));
777
147
        }
778
335
        if (t_part.__isset.end_keys) {
779
146
            RETURN_IF_ERROR(_create_partition_keys(t_part.end_keys, &part->end_key));
780
146
        }
781
        // list partition - we only set 1 value in 1 partition for new created ones
782
335
        if (t_part.__isset.in_keys) {
783
185
            for (const auto& keys : t_part.in_keys) {
784
185
                RETURN_IF_ERROR(_create_partition_keys(
785
185
                        keys, &part->in_keys.emplace_back(&_partition_block, -1)));
786
185
            }
787
185
            if (t_part.__isset.is_default_partition && t_part.is_default_partition) {
788
0
                _default_partition = part;
789
0
            }
790
185
        }
791
792
335
        part->num_buckets = t_part.num_buckets;
793
335
        auto num_indexes = _schema->indexes().size();
794
335
        if (t_part.indexes.size() != num_indexes) {
795
0
            return Status::InternalError(
796
0
                    "number of partition's index is not equal with schema's"
797
0
                    ", num_part_indexes={}, num_schema_indexes={}",
798
0
                    t_part.indexes.size(), num_indexes);
799
0
        }
800
335
        part->indexes = t_part.indexes;
801
335
        std::sort(part->indexes.begin(), part->indexes.end(),
802
335
                  [](const OlapTableIndexTablets& lhs, const OlapTableIndexTablets& rhs) {
803
0
                      return lhs.index_id < rhs.index_id;
804
0
                  });
805
        // check index
806
670
        for (int j = 0; j < num_indexes; ++j) {
807
335
            if (part->indexes[j].index_id != _schema->indexes()[j]->index_id) {
808
0
                return Status::InternalError(
809
0
                        "partition's index is not equal with schema's"
810
0
                        ", part_index={}, schema_index={}",
811
0
                        part->indexes[j].index_id, _schema->indexes()[j]->index_id);
812
0
            }
813
335
        }
814
335
        _partitions.emplace_back(part);
815
        // after _creating_partiton_keys
816
335
        if (_is_in_partition) {
817
185
            for (auto& in_key : part->in_keys) {
818
185
                _partitions_map->emplace(std::tuple {in_key.first, in_key.second, false}, part);
819
185
            }
820
185
        } else {
821
150
            _partitions_map->emplace(std::tuple {part->end_key.first, part->end_key.second, false},
822
150
                                     part);
823
150
        }
824
335
    }
825
826
168
    return Status::OK();
827
168
}
828
829
Status VOlapTablePartitionParam::replace_partitions(
830
        std::vector<int64_t>& old_partition_ids,
831
20
        const std::vector<TOlapTablePartition>& new_partitions) {
832
    // remove old replaced partitions
833
20
    DCHECK(old_partition_ids.size() == new_partitions.size());
834
835
    // init and add new partitions. insert into _partitions
836
52
    for (int i = 0; i < new_partitions.size(); i++) {
837
32
        const auto& t_part = new_partitions[i];
838
        // pair old_partition_ids and new_partitions one by one. TODO: sort to opt performance
839
32
        VOlapTablePartition* old_part = nullptr;
840
32
        auto old_part_id = old_partition_ids[i];
841
32
        if (auto it = std::find_if(
842
32
                    _partitions.begin(), _partitions.end(),
843
76
                    [=](const VOlapTablePartition* lhs) { return lhs->id == old_part_id; });
844
32
            it != _partitions.end()) {
845
32
            old_part = *it;
846
32
        } else {
847
0
            return Status::InternalError("Cannot find old tablet {} in replacing", old_part_id);
848
0
        }
849
850
32
        auto* part = _obj_pool.add(new VOlapTablePartition(&_partition_block));
851
32
        part->id = t_part.id;
852
32
        part->is_mutable = t_part.is_mutable;
853
854
        /// just substitute directly. no need to remove and reinsert keys.
855
        // range partition
856
32
        part->start_key = std::move(old_part->start_key);
857
32
        part->end_key = std::move(old_part->end_key);
858
        // list partition
859
32
        part->in_keys = std::move(old_part->in_keys);
860
32
        if (t_part.__isset.is_default_partition && t_part.is_default_partition) {
861
0
            _default_partition = part;
862
0
        }
863
864
32
        part->num_buckets = t_part.num_buckets;
865
32
        auto num_indexes = _schema->indexes().size();
866
32
        if (t_part.indexes.size() != num_indexes) {
867
0
            return Status::InternalError(
868
0
                    "number of partition's index is not equal with schema's"
869
0
                    ", num_part_indexes={}, num_schema_indexes={}",
870
0
                    t_part.indexes.size(), num_indexes);
871
0
        }
872
32
        part->indexes = t_part.indexes;
873
32
        std::sort(part->indexes.begin(), part->indexes.end(),
874
32
                  [](const OlapTableIndexTablets& lhs, const OlapTableIndexTablets& rhs) {
875
0
                      return lhs.index_id < rhs.index_id;
876
0
                  });
877
        // check index
878
64
        for (int j = 0; j < num_indexes; ++j) {
879
32
            if (part->indexes[j].index_id != _schema->indexes()[j]->index_id) {
880
0
                return Status::InternalError(
881
0
                        "partition's index is not equal with schema's"
882
0
                        ", part_index={}, schema_index={}",
883
0
                        part->indexes[j].index_id, _schema->indexes()[j]->index_id);
884
0
            }
885
32
        }
886
887
        // add new partitions with new id.
888
32
        _partitions.emplace_back(part);
889
32
        VLOG_NOTICE << "params add new partition " << part->id;
890
891
        // replace items in _partition_maps
892
32
        if (_is_in_partition) {
893
44
            for (auto& in_key : part->in_keys) {
894
44
                (*_partitions_map)[std::tuple {in_key.first, in_key.second, false}] = part;
895
44
            }
896
21
        } else {
897
11
            (*_partitions_map)[std::tuple {part->end_key.first, part->end_key.second, false}] =
898
11
                    part;
899
11
        }
900
32
    }
901
    // remove old partitions by id
902
20
    std::ranges::sort(old_partition_ids);
903
129
    for (auto it = _partitions.begin(); it != _partitions.end();) {
904
109
        if (std::ranges::binary_search(old_partition_ids, (*it)->id)) {
905
32
            it = _partitions.erase(it);
906
77
        } else {
907
77
            it++;
908
77
        }
909
109
    }
910
911
20
    return Status::OK();
912
20
}
913
914
} // namespace doris