Coverage Report

Created: 2026-06-01 21:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/delete/delete_handler.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/delete/delete_handler.h"
19
20
#include <gen_cpp/PaloInternalService_types.h>
21
#include <gen_cpp/olap_file.pb.h>
22
#include <thrift/protocol/TDebugProtocol.h>
23
24
#include <string>
25
#include <vector>
26
27
#include "common/config.h"
28
#include "common/logging.h"
29
#include "common/status.h"
30
#include "core/data_type_serde/data_type_serde.h"
31
#include "storage/olap_common.h"
32
#include "storage/predicate/block_column_predicate.h"
33
#include "storage/predicate/null_predicate.h"
34
#include "storage/predicate/predicate_creator.h"
35
#include "storage/tablet/tablet_schema.h"
36
#include "storage/utils.h"
37
#include "util/debug_points.h"
38
39
using apache::thrift::ThriftDebugString;
40
using std::vector;
41
using std::string;
42
43
using ::google::protobuf::RepeatedPtrField;
44
45
namespace doris {
46
47
// Parses a string value into a Field using the serde's from_fe_string, then builds
48
// a HybridSetBase for IN/NOT_IN predicates.
49
// The type-dispatch via switch/case is still needed because build_set<PType>() and
50
// HybridSet::insert(const void*) require compile-time PrimitiveType, and Field::get<PType>()
51
// must be invoked with the correct type to extract the underlying CppType value.
52
template <PrimitiveType PType>
53
783
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
783
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
203
        const auto& tmp = field.get<PType>();
58
203
        StringRef ref(tmp.data(), tmp.size());
59
203
        set->insert(reinterpret_cast<const void*>(&ref));
60
580
    } else {
61
580
        auto tmp = field.get<PType>();
62
580
        set->insert(reinterpret_cast<const void*>(&tmp));
63
580
    }
64
783
}
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE3EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
4
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
        const auto& tmp = field.get<PType>();
58
        StringRef ref(tmp.data(), tmp.size());
59
        set->insert(reinterpret_cast<const void*>(&ref));
60
4
    } else {
61
4
        auto tmp = field.get<PType>();
62
4
        set->insert(reinterpret_cast<const void*>(&tmp));
63
4
    }
64
4
}
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE4EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
2
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
        const auto& tmp = field.get<PType>();
58
        StringRef ref(tmp.data(), tmp.size());
59
        set->insert(reinterpret_cast<const void*>(&ref));
60
2
    } else {
61
2
        auto tmp = field.get<PType>();
62
2
        set->insert(reinterpret_cast<const void*>(&tmp));
63
2
    }
64
2
}
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE5EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
207
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
        const auto& tmp = field.get<PType>();
58
        StringRef ref(tmp.data(), tmp.size());
59
        set->insert(reinterpret_cast<const void*>(&ref));
60
207
    } else {
61
207
        auto tmp = field.get<PType>();
62
207
        set->insert(reinterpret_cast<const void*>(&tmp));
63
207
    }
64
207
}
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE6EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
8
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
        const auto& tmp = field.get<PType>();
58
        StringRef ref(tmp.data(), tmp.size());
59
        set->insert(reinterpret_cast<const void*>(&ref));
60
8
    } else {
61
8
        auto tmp = field.get<PType>();
62
8
        set->insert(reinterpret_cast<const void*>(&tmp));
63
8
    }
64
8
}
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE7EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE8EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE9EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE11EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE12EEEvRKNS_5FieldEPNS_13HybridSetBaseE
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE25EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
2
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
        const auto& tmp = field.get<PType>();
58
        StringRef ref(tmp.data(), tmp.size());
59
        set->insert(reinterpret_cast<const void*>(&ref));
60
2
    } else {
61
2
        auto tmp = field.get<PType>();
62
2
        set->insert(reinterpret_cast<const void*>(&tmp));
63
2
    }
64
2
}
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE26EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
2
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
        const auto& tmp = field.get<PType>();
58
        StringRef ref(tmp.data(), tmp.size());
59
        set->insert(reinterpret_cast<const void*>(&ref));
60
2
    } else {
61
2
        auto tmp = field.get<PType>();
62
2
        set->insert(reinterpret_cast<const void*>(&tmp));
63
2
    }
64
2
}
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE42EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
345
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
        const auto& tmp = field.get<PType>();
58
        StringRef ref(tmp.data(), tmp.size());
59
        set->insert(reinterpret_cast<const void*>(&ref));
60
345
    } else {
61
345
        auto tmp = field.get<PType>();
62
345
        set->insert(reinterpret_cast<const void*>(&tmp));
63
345
    }
64
345
}
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE2EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE36EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE37EEEvRKNS_5FieldEPNS_13HybridSetBaseE
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE20EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
8
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
        const auto& tmp = field.get<PType>();
58
        StringRef ref(tmp.data(), tmp.size());
59
        set->insert(reinterpret_cast<const void*>(&ref));
60
8
    } else {
61
8
        auto tmp = field.get<PType>();
62
8
        set->insert(reinterpret_cast<const void*>(&tmp));
63
8
    }
64
8
}
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE28EEEvRKNS_5FieldEPNS_13HybridSetBaseE
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE29EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
2
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
        const auto& tmp = field.get<PType>();
58
        StringRef ref(tmp.data(), tmp.size());
59
        set->insert(reinterpret_cast<const void*>(&ref));
60
2
    } else {
61
2
        auto tmp = field.get<PType>();
62
2
        set->insert(reinterpret_cast<const void*>(&tmp));
63
2
    }
64
2
}
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE30EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Unexecuted instantiation: _ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE35EEEvRKNS_5FieldEPNS_13HybridSetBaseE
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE15EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
4
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
4
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
4
        const auto& tmp = field.get<PType>();
58
4
        StringRef ref(tmp.data(), tmp.size());
59
4
        set->insert(reinterpret_cast<const void*>(&ref));
60
    } else {
61
        auto tmp = field.get<PType>();
62
        set->insert(reinterpret_cast<const void*>(&tmp));
63
    }
64
4
}
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE10EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
197
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
197
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
197
        const auto& tmp = field.get<PType>();
58
197
        StringRef ref(tmp.data(), tmp.size());
59
197
        set->insert(reinterpret_cast<const void*>(&ref));
60
    } else {
61
        auto tmp = field.get<PType>();
62
        set->insert(reinterpret_cast<const void*>(&tmp));
63
    }
64
197
}
_ZN5doris19insert_field_to_setILNS_13PrimitiveTypeE23EEEvRKNS_5FieldEPNS_13HybridSetBaseE
Line
Count
Source
53
2
void insert_field_to_set(const Field& field, HybridSetBase* set) {
54
2
    if constexpr (is_string_type(PType)) {
55
        // StringSet::insert expects const StringRef*, so we must construct a StringRef
56
        // from the std::string returned by Field::get<>.
57
2
        const auto& tmp = field.get<PType>();
58
2
        StringRef ref(tmp.data(), tmp.size());
59
2
        set->insert(reinterpret_cast<const void*>(&ref));
60
    } else {
61
        auto tmp = field.get<PType>();
62
        set->insert(reinterpret_cast<const void*>(&tmp));
63
    }
64
2
}
65
66
#define FROM_FE_STRING_CASE(PType)                            \
67
242
    case PType: {                                             \
68
242
        set = build_set<PType>();                             \
69
782
        for (const auto& s : str) {                           \
70
782
            Field field;                                      \
71
782
            RETURN_IF_ERROR(serde->from_fe_string(s, field)); \
72
782
            insert_field_to_set<PType>(field, set.get());     \
73
782
        }                                                     \
74
242
        return Status::OK();                                  \
75
242
    }
76
Status convert(const DataTypePtr& data_type, const std::list<std::string>& str,
77
242
               std::shared_ptr<HybridSetBase>& set) {
78
242
    auto serde = data_type->get_serde();
79
242
    switch (data_type->get_primitive_type()) {
80
1
        FROM_FE_STRING_CASE(TYPE_TINYINT);
81
1
        FROM_FE_STRING_CASE(TYPE_SMALLINT);
82
70
        FROM_FE_STRING_CASE(TYPE_INT);
83
3
        FROM_FE_STRING_CASE(TYPE_BIGINT);
84
0
        FROM_FE_STRING_CASE(TYPE_LARGEINT);
85
0
        FROM_FE_STRING_CASE(TYPE_FLOAT);
86
0
        FROM_FE_STRING_CASE(TYPE_DOUBLE);
87
0
        FROM_FE_STRING_CASE(TYPE_DATE);
88
0
        FROM_FE_STRING_CASE(TYPE_DATETIME);
89
1
        FROM_FE_STRING_CASE(TYPE_DATEV2);
90
1
        FROM_FE_STRING_CASE(TYPE_DATETIMEV2);
91
98
        FROM_FE_STRING_CASE(TYPE_TIMESTAMPTZ);
92
0
        FROM_FE_STRING_CASE(TYPE_BOOLEAN);
93
0
        FROM_FE_STRING_CASE(TYPE_IPV4);
94
0
        FROM_FE_STRING_CASE(TYPE_IPV6);
95
2
        FROM_FE_STRING_CASE(TYPE_DECIMALV2);
96
0
        FROM_FE_STRING_CASE(TYPE_DECIMAL32);
97
1
        FROM_FE_STRING_CASE(TYPE_DECIMAL64);
98
0
        FROM_FE_STRING_CASE(TYPE_DECIMAL128I);
99
0
        FROM_FE_STRING_CASE(TYPE_DECIMAL256);
100
2
        FROM_FE_STRING_CASE(TYPE_CHAR);
101
61
        FROM_FE_STRING_CASE(TYPE_VARCHAR);
102
1
        FROM_FE_STRING_CASE(TYPE_STRING);
103
0
    default:
104
0
        return Status::Error<ErrorCode::INVALID_ARGUMENT>(
105
0
                "unsupported data type in delete handler. type={}",
106
0
                type_to_string(data_type->get_primitive_type()));
107
242
    }
108
0
    return Status::OK();
109
242
}
110
#undef FROM_FE_STRING_CASE
111
112
// Parses a single condition value string into a Field and creates a comparison predicate.
113
// Uses serde->from_fe_string to do the parsing, which handles all type-specific
114
// conversions (including decimal scale, etc.).
115
Status parse_to_predicate(const uint32_t index, const std::string col_name, const DataTypePtr& type,
116
                          DeleteHandler::ConditionParseResult& res, Arena& arena,
117
7.30k
                          std::shared_ptr<ColumnPredicate>& predicate) {
118
7.30k
    DCHECK_EQ(res.value_str.size(), 1);
119
7.30k
    if (res.condition_op == PredicateType::IS_NULL ||
120
7.30k
        res.condition_op == PredicateType::IS_NOT_NULL) {
121
517
        predicate = NullPredicate::create_shared(index, col_name,
122
517
                                                 res.condition_op == PredicateType::IS_NOT_NULL,
123
517
                                                 type->get_primitive_type());
124
517
        return Status::OK();
125
517
    }
126
127
6.78k
    Field v;
128
6.78k
    if (is_string_type(type->get_primitive_type())) {
129
686
        v = Field::create_field<TYPE_STRING>(res.value_str.front());
130
6.09k
    } else {
131
6.09k
        auto serde = type->get_serde();
132
6.09k
        RETURN_IF_ERROR(serde->from_fe_string(res.value_str.front(), v));
133
6.09k
    }
134
135
6.77k
    switch (res.condition_op) {
136
3.50k
    case PredicateType::EQ:
137
3.50k
        predicate = create_comparison_predicate<PredicateType::EQ>(index, col_name, type, v, true);
138
3.50k
        return Status::OK();
139
856
    case PredicateType::NE:
140
856
        predicate = create_comparison_predicate<PredicateType::NE>(index, col_name, type, v, true);
141
856
        return Status::OK();
142
456
    case PredicateType::GT:
143
456
        predicate = create_comparison_predicate<PredicateType::GT>(index, col_name, type, v, true);
144
456
        return Status::OK();
145
323
    case PredicateType::GE:
146
323
        predicate = create_comparison_predicate<PredicateType::GE>(index, col_name, type, v, true);
147
323
        return Status::OK();
148
953
    case PredicateType::LT:
149
953
        predicate = create_comparison_predicate<PredicateType::LT>(index, col_name, type, v, true);
150
953
        return Status::OK();
151
696
    case PredicateType::LE:
152
696
        predicate = create_comparison_predicate<PredicateType::LE>(index, col_name, type, v, true);
153
696
        return Status::OK();
154
0
    default:
155
0
        return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition operator. operator={}",
156
0
                                                          type_to_op_str(res.condition_op));
157
6.77k
    }
158
6.77k
}
159
160
Status parse_to_in_predicate(const uint32_t index, const std::string& col_name,
161
                             const DataTypePtr& type, DeleteHandler::ConditionParseResult& res,
162
242
                             Arena& arena, std::shared_ptr<ColumnPredicate>& predicate) {
163
242
    DCHECK_GT(res.value_str.size(), 1);
164
242
    switch (res.condition_op) {
165
189
    case PredicateType::IN_LIST: {
166
189
        std::shared_ptr<HybridSetBase> set;
167
189
        RETURN_IF_ERROR(convert(type, res.value_str, set));
168
189
        predicate =
169
189
                create_in_list_predicate<PredicateType::IN_LIST>(index, col_name, type, set, true);
170
189
        break;
171
189
    }
172
53
    case PredicateType::NOT_IN_LIST: {
173
53
        std::shared_ptr<HybridSetBase> set;
174
53
        RETURN_IF_ERROR(convert(type, res.value_str, set));
175
53
        predicate = create_in_list_predicate<PredicateType::NOT_IN_LIST>(index, col_name, type, set,
176
53
                                                                         true);
177
53
        break;
178
53
    }
179
0
    default:
180
0
        return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition operator. operator={}",
181
0
                                                          type_to_op_str(res.condition_op));
182
242
    }
183
241
    return Status::OK();
184
242
}
185
186
// construct sub condition from TCondition
187
3.20k
std::string construct_sub_predicate(const TCondition& condition) {
188
3.20k
    string op = condition.condition_op;
189
3.20k
    if (op == "<") {
190
332
        op += "<";
191
2.87k
    } else if (op == ">") {
192
234
        op += ">";
193
234
    }
194
3.20k
    string condition_str;
195
3.20k
    if ("IS" == op) {
196
        // ATTN: tricky! Surround IS with spaces to make it "special"
197
410
        condition_str = condition.column_name + " IS " + condition.condition_values[0];
198
2.79k
    } else { // multi-elements IN expr has been processed with InPredicatePB
199
2.79k
        if (op == "*=") {
200
2
            op = "=";
201
2.79k
        } else if (op == "!*=") {
202
2
            op = "!=";
203
2
        }
204
2.79k
        condition_str = condition.column_name + op + "'" + condition.condition_values[0] + "'";
205
2.79k
    }
206
3.20k
    return condition_str;
207
3.20k
}
208
209
// make operators from FE adaptive to BE
210
3.19k
std::string trans_op(const std::string& opt) {
211
3.19k
    std::string op = string(opt);
212
3.19k
    if (op == "<") {
213
333
        op += "<";
214
2.86k
    } else if (op == ">") {
215
232
        op += ">";
216
232
    }
217
3.19k
    if ("IS" != op) {
218
2.80k
        if (op == "*=") {
219
2
            op = "=";
220
2.79k
        } else if (op == "!*=") {
221
2
            op = "!=";
222
2
        }
223
2.80k
    }
224
3.19k
    return op;
225
3.19k
}
226
227
Status DeleteHandler::generate_delete_predicate(const TabletSchema& schema,
228
                                                const std::vector<TCondition>& conditions,
229
3.33k
                                                DeletePredicatePB* del_pred) {
230
3.33k
    DBUG_EXECUTE_IF("DeleteHandler::generate_delete_predicate.inject_failure", {
231
3.33k
        return Status::Error<false>(dp->param<int>("error_code"),
232
3.33k
                                    dp->param<std::string>("error_msg"));
233
3.33k
    })
234
3.33k
    if (conditions.empty()) {
235
1
        return Status::Error<ErrorCode::INVALID_ARGUMENT>(
236
1
                "invalid parameters for store_cond. condition_size={}", conditions.size());
237
1
    }
238
239
    // Check whether the delete condition meets the requirements
240
3.45k
    for (const TCondition& condition : conditions) {
241
3.45k
        RETURN_IF_ERROR(check_condition_valid(schema, condition));
242
3.45k
    }
243
244
    // Store delete condition
245
3.42k
    for (const TCondition& condition : conditions) {
246
3.42k
        if (condition.condition_values.size() > 1) {
247
194
            InPredicatePB* in_pred = del_pred->add_in_predicates();
248
194
            if (condition.__isset.column_unique_id) {
249
191
                in_pred->set_column_unique_id(condition.column_unique_id);
250
191
            }
251
194
            in_pred->set_column_name(condition.column_name);
252
194
            bool is_not_in = condition.condition_op == "!*=";
253
194
            in_pred->set_is_not_in(is_not_in);
254
622
            for (const auto& condition_value : condition.condition_values) {
255
622
                in_pred->add_values(condition_value);
256
622
            }
257
258
194
            LOG(INFO) << "store one sub-delete condition. condition name=" << in_pred->column_name()
259
194
                      << "condition size=" << in_pred->values().size();
260
3.22k
        } else {
261
            // write sub predicate v1 for compactbility
262
3.22k
            std::string condition_str = construct_sub_predicate(condition);
263
3.22k
            VLOG_NOTICE << __PRETTY_FUNCTION__ << " condition_str: " << condition_str;
264
3.22k
            del_pred->add_sub_predicates(condition_str);
265
3.22k
            DeleteSubPredicatePB* sub_predicate = del_pred->add_sub_predicates_v2();
266
3.22k
            if (condition.__isset.column_unique_id) {
267
                // only light schema change capable table set this field
268
3.12k
                sub_predicate->set_column_unique_id(condition.column_unique_id);
269
3.12k
            } else {
270
100
                try {
271
100
                    [[maybe_unused]] auto parsed_cond = parse_condition(condition_str);
272
100
                } catch (const Exception& e) {
273
0
                    return Status::Error<ErrorCode::INVALID_ARGUMENT>(
274
0
                            "failed to parse condition_str, condition={}, error={}",
275
0
                            ThriftDebugString(condition), e.to_string());
276
0
                }
277
100
            }
278
279
3.22k
            sub_predicate->set_column_name(condition.column_name);
280
3.22k
            sub_predicate->set_op(trans_op(condition.condition_op));
281
3.22k
            sub_predicate->set_cond_value(condition.condition_values[0]);
282
3.22k
            LOG(INFO) << "store one sub-delete condition. condition="
283
3.22k
                      << fmt::format(" {} {} {}", condition.column_name, condition.condition_op,
284
3.22k
                                     condition.condition_values[0]);
285
3.22k
        }
286
3.42k
    }
287
3.30k
    del_pred->set_version(-1);
288
289
3.30k
    return Status::OK();
290
3.30k
}
291
292
Status DeleteHandler::convert_to_sub_pred_v2(DeletePredicatePB* delete_pred,
293
0
                                             TabletSchemaSPtr schema) {
294
0
    if (!delete_pred->sub_predicates().empty() && delete_pred->sub_predicates_v2().empty()) {
295
0
        for (const auto& condition_str : delete_pred->sub_predicates()) {
296
0
            auto* sub_pred = delete_pred->add_sub_predicates_v2();
297
0
            auto condition = parse_condition(condition_str);
298
0
            const auto& column = *DORIS_TRY(schema->column(condition.column_name));
299
0
            sub_pred->set_column_unique_id(column.unique_id());
300
0
            sub_pred->set_column_name(condition.column_name);
301
0
            sub_pred->set_op(type_to_op_str(condition.condition_op));
302
0
            sub_pred->set_cond_value(condition.value_str.front());
303
0
        }
304
0
    }
305
306
0
    auto* in_pred_list = delete_pred->mutable_in_predicates();
307
0
    for (auto& in_pred : *in_pred_list) {
308
0
        const auto& column = *DORIS_TRY(schema->column(in_pred.column_name()));
309
0
        in_pred.set_column_unique_id(column.unique_id());
310
0
    }
311
0
    return Status::OK();
312
0
}
313
314
bool DeleteHandler::is_condition_value_valid(const TabletColumn& column,
315
                                             const std::string& condition_op,
316
3.85k
                                             const string& value_str) {
317
3.85k
    if ("IS" == condition_op && ("NULL" == value_str || "NOT NULL" == value_str)) {
318
411
        return true;
319
411
    }
320
321
3.44k
    FieldType field_type = column.type();
322
3.44k
    switch (field_type) {
323
25
    case FieldType::OLAP_FIELD_TYPE_TINYINT:
324
25
        return valid_signed_number<int8_t>(value_str);
325
17
    case FieldType::OLAP_FIELD_TYPE_SMALLINT:
326
17
        return valid_signed_number<int16_t>(value_str);
327
824
    case FieldType::OLAP_FIELD_TYPE_INT:
328
824
        return valid_signed_number<int32_t>(value_str);
329
59
    case FieldType::OLAP_FIELD_TYPE_BIGINT:
330
59
        return valid_signed_number<int64_t>(value_str);
331
161
    case FieldType::OLAP_FIELD_TYPE_LARGEINT:
332
161
        return valid_signed_number<int128_t>(value_str);
333
0
    case FieldType::OLAP_FIELD_TYPE_UNSIGNED_TINYINT:
334
0
        return valid_unsigned_number<uint8_t>(value_str);
335
0
    case FieldType::OLAP_FIELD_TYPE_UNSIGNED_SMALLINT:
336
0
        return valid_unsigned_number<uint16_t>(value_str);
337
0
    case FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT:
338
0
        return valid_unsigned_number<uint32_t>(value_str);
339
0
    case FieldType::OLAP_FIELD_TYPE_UNSIGNED_BIGINT:
340
0
        return valid_unsigned_number<uint64_t>(value_str);
341
15
    case FieldType::OLAP_FIELD_TYPE_DECIMAL:
342
15
        return valid_decimal(value_str, column.precision(), column.frac());
343
8
    case FieldType::OLAP_FIELD_TYPE_DECIMAL32:
344
8
        return valid_decimal(value_str, column.precision(), column.frac());
345
10
    case FieldType::OLAP_FIELD_TYPE_DECIMAL64:
346
10
        return valid_decimal(value_str, column.precision(), column.frac());
347
0
    case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
348
0
        return valid_decimal(value_str, column.precision(), column.frac());
349
1
    case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
350
1
        return valid_decimal(value_str, column.precision(), column.frac());
351
11
    case FieldType::OLAP_FIELD_TYPE_CHAR:
352
232
    case FieldType::OLAP_FIELD_TYPE_VARCHAR:
353
232
        return value_str.size() <= column.length();
354
44
    case FieldType::OLAP_FIELD_TYPE_STRING:
355
44
        return value_str.size() <= config::string_type_length_soft_limit_bytes;
356
14
    case FieldType::OLAP_FIELD_TYPE_DATE:
357
29
    case FieldType::OLAP_FIELD_TYPE_DATETIME:
358
62
    case FieldType::OLAP_FIELD_TYPE_DATEV2:
359
97
    case FieldType::OLAP_FIELD_TYPE_DATETIMEV2:
360
2.01k
    case FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ:
361
2.01k
        return valid_datetime(value_str, column.frac());
362
5
    case FieldType::OLAP_FIELD_TYPE_BOOL:
363
5
        return valid_bool(value_str);
364
9
    case FieldType::OLAP_FIELD_TYPE_IPV4:
365
9
        return valid_ipv4(value_str);
366
36
    case FieldType::OLAP_FIELD_TYPE_IPV6:
367
36
        return valid_ipv6(value_str);
368
0
    default:
369
0
        LOG(WARNING) << "unknown field type. [type=" << int(field_type) << "]";
370
3.44k
    }
371
0
    return false;
372
3.44k
}
373
374
3.43k
Status DeleteHandler::check_condition_valid(const TabletSchema& schema, const TCondition& cond) {
375
    // Check whether the column exists
376
3.43k
    int32_t field_index = schema.field_index(cond.column_name);
377
3.43k
    if (field_index < 0) {
378
1
        return Status::Error<ErrorCode::INVALID_ARGUMENT>("field is not existent. [field_index={}]",
379
1
                                                          field_index);
380
1
    }
381
382
    // Delete condition should only applied on key columns or duplicate key table, and
383
    // the condition column type should not be float or double.
384
3.43k
    const TabletColumn& column = schema.column(field_index);
385
386
3.43k
    if (column.type() == FieldType::OLAP_FIELD_TYPE_DOUBLE ||
387
3.44k
        column.type() == FieldType::OLAP_FIELD_TYPE_FLOAT) {
388
0
        return Status::Error<ErrorCode::INVALID_ARGUMENT>("data type is float or double.");
389
0
    }
390
391
    // Check operator and operands size are matched.
392
3.43k
    if ("*=" != cond.condition_op && "!*=" != cond.condition_op &&
393
3.43k
        cond.condition_values.size() != 1) {
394
0
        return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition value size. [size={}]",
395
0
                                                          cond.condition_values.size());
396
0
    }
397
398
    // Check each operand is valid
399
3.87k
    for (const auto& condition_value : cond.condition_values) {
400
3.87k
        if (!is_condition_value_valid(column, cond.condition_op, condition_value)) {
401
29
            return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition value. [value={}]",
402
29
                                                              condition_value);
403
29
        }
404
3.87k
    }
405
406
3.40k
    if (!cond.__isset.column_unique_id) {
407
105
        LOG(WARNING) << "column=" << cond.column_name
408
105
                     << " in predicate does not have uid, table id=" << schema.table_id();
409
        // TODO(tsy): make it fail here after FE forbidding hard-link-schema-change
410
105
        return Status::OK();
411
105
    }
412
3.30k
    if (schema.field_index(cond.column_unique_id) == -1) {
413
0
        const auto& err_msg =
414
0
                fmt::format("column id does not exists in table={}, schema version={},",
415
0
                            schema.table_id(), schema.schema_version());
416
0
        return Status::Error<ErrorCode::INVALID_ARGUMENT>(err_msg);
417
0
    }
418
3.30k
    if (!iequal(schema.column_by_uid(cond.column_unique_id).name(), cond.column_name)) {
419
0
        const auto& err_msg = fmt::format(
420
0
                "colum name={} does not belongs to column uid={}, which "
421
0
                "column name={}, "
422
0
                "delete_cond.column_name ={}",
423
0
                cond.column_name, cond.column_unique_id,
424
0
                schema.column_by_uid(cond.column_unique_id).name(), cond.column_name);
425
0
        return Status::Error<ErrorCode::INVALID_ARGUMENT>(err_msg);
426
0
    }
427
428
3.30k
    return Status::OK();
429
3.30k
}
430
431
PredicateType DeleteHandler::parse_condition_op(const std::string& op_str,
432
7.42k
                                                const std::list<std::string>& cond_values) {
433
7.42k
    if (trim(to_lower(op_str)) == "=") {
434
3.54k
        return PredicateType::EQ;
435
3.87k
    } else if (trim(to_lower(op_str)) == "!=") {
436
868
        return PredicateType::NE;
437
3.00k
    } else if (trim(to_lower(op_str)) == ">>") {
438
464
        return PredicateType::GT;
439
2.54k
    } else if (trim(to_lower(op_str)) == "<<") {
440
1.00k
        return PredicateType::LT;
441
1.53k
    } else if (trim(to_lower(op_str)) == ">=") {
442
326
        return PredicateType::GE;
443
1.21k
    } else if (trim(to_lower(op_str)) == "<=") {
444
702
        return PredicateType::LE;
445
702
    } else if (trim(to_lower(op_str)) == "*=") {
446
0
        return cond_values.size() > 1 ? PredicateType::IN_LIST : PredicateType::EQ;
447
509
    } else if (trim(to_lower(op_str)) == "!*=") {
448
0
        return cond_values.size() > 1 ? PredicateType::NOT_IN_LIST : PredicateType::NE;
449
521
    } else if (trim(to_lower(op_str)) == "is") {
450
521
        return to_lower(cond_values.front()) == "null" ? PredicateType::IS_NULL
451
521
                                                       : PredicateType::IS_NOT_NULL;
452
18.4E
    } else {
453
18.4E
        throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>(
454
18.4E
                "invalid condition operator. operator={}", op_str));
455
18.4E
    }
456
0
    return PredicateType::UNKNOWN;
457
7.42k
}
458
459
DeleteHandler::ConditionParseResult DeleteHandler::parse_condition(
460
7.24k
        const DeleteSubPredicatePB& sub_cond) {
461
7.24k
    ConditionParseResult res;
462
7.24k
    if (!sub_cond.has_column_name() || !sub_cond.has_op() || !sub_cond.has_cond_value()) {
463
0
        throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>(
464
0
                "fail to parse condition. condition={} {} {}", sub_cond.column_name(),
465
0
                sub_cond.op(), sub_cond.cond_value()));
466
0
    }
467
7.24k
    if (sub_cond.has_column_unique_id()) {
468
7.14k
        res.col_unique_id = sub_cond.column_unique_id();
469
7.14k
    }
470
7.24k
    res.column_name = sub_cond.column_name();
471
7.24k
    res.value_str.push_back(sub_cond.cond_value());
472
7.24k
    res.condition_op = parse_condition_op(sub_cond.op(), res.value_str);
473
7.24k
    return res;
474
7.24k
}
475
476
// clang-format off
477
// Condition string format, the format is (column_name)(op)(value)
478
// eg: condition_str="c1 = 1597751948193618247 and length(source)<1;\n;\n"
479
// column_name: matches "c1", must include FeNameFormat.java COLUMN_NAME_REGEX
480
//              and compactible with any the lagacy
481
// operator: matches "="
482
// value: matches "1597751948193618247  and length(source)<1;\n;\n"
483
//
484
// For more info, see DeleteHandler::construct_sub_predicates
485
// FIXME(gavin): This is a tricky implementation, it should not be the final resolution, refactor it.
486
const char* const CONDITION_STR_PATTERN =
487
    // .----------------- column-name --------------------------.   .----------------------- operator ------------------------.   .------------ value ----------.
488
    R"(([_a-zA-Z@0-9\s/\p{L}][.a-zA-Z0-9_+-/?@#$%^&*"\s,:\p{L}]*)\s*((?:=)|(?:!=)|(?:>>)|(?:<<)|(?:>=)|(?:<=)|(?:\*=)|(?: IS ))\s*('((?:[\s\S]+)?)'|(?:[\s\S]+)?))";
489
    // '----------------- group 1 ------------------------------'   '--------------------- group 2 ---------------------------'   | '-- group 4--'              |
490
    //                                                                   match any of: = != >> << >= <= *= " IS "                 '----------- group 3 ---------'
491
    //                                                                                                                             match **ANY THING** without(4)
492
    //                                                                                                                             or with(3) single quote
493
// clang-format on
494
RE2 DELETE_HANDLER_REGEX(CONDITION_STR_PATTERN);
495
496
DeleteHandler::ConditionParseResult DeleteHandler::parse_condition(
497
182
        const std::string& condition_str) {
498
182
    ConditionParseResult res;
499
182
    std::string col_name, op, value, g4;
500
501
182
    bool matched = RE2::FullMatch(condition_str, DELETE_HANDLER_REGEX, &col_name, &op, &value,
502
182
                                  &g4); // exact match
503
504
182
    if (!matched) {
505
0
        throw Exception(
506
0
                Status::InvalidArgument("fail to sub condition. condition={}", condition_str));
507
0
    }
508
509
182
    res.column_name = col_name;
510
511
    // match string with single quotes, a = b  or a = 'b'
512
182
    if (!g4.empty()) {
513
141
        res.value_str.push_back(g4);
514
141
    } else {
515
41
        res.value_str.push_back(value);
516
41
    }
517
182
    res.condition_op = DeleteHandler::parse_condition_op(op, res.value_str);
518
182
    VLOG_NOTICE << "parsed condition_str: col_name={" << col_name << "} op={" << op << "} val={"
519
48
                << res.value_str.back() << "}";
520
182
    return res;
521
182
}
522
523
template <typename SubPredType>
524
    requires(std::is_same_v<SubPredType, DeleteSubPredicatePB> or
525
             std::is_same_v<SubPredType, std::string>)
526
Status DeleteHandler::_parse_column_pred(TabletSchemaSPtr complete_schema,
527
                                         TabletSchemaSPtr delete_pred_related_schema,
528
                                         const RepeatedPtrField<SubPredType>& sub_pred_list,
529
7.26k
                                         DeleteConditions* delete_conditions) {
530
7.31k
    for (const auto& sub_predicate : sub_pred_list) {
531
7.31k
        auto condition = parse_condition(sub_predicate);
532
7.31k
        int32_t col_unique_id = -1;
533
7.31k
        if constexpr (std::is_same_v<SubPredType, DeleteSubPredicatePB>) {
534
7.23k
            if (sub_predicate.has_column_unique_id()) [[likely]] {
535
7.14k
                col_unique_id = sub_predicate.column_unique_id();
536
7.14k
            }
537
7.23k
        }
538
7.31k
        if (col_unique_id < 0) {
539
181
            const auto& column =
540
181
                    *DORIS_TRY(delete_pred_related_schema->column(condition.column_name));
541
181
            col_unique_id = column.unique_id();
542
181
        }
543
7.31k
        condition.col_unique_id = col_unique_id;
544
7.31k
        const auto& column = complete_schema->column_by_uid(col_unique_id);
545
7.31k
        uint32_t index = complete_schema->field_index(col_unique_id);
546
7.31k
        std::shared_ptr<ColumnPredicate> predicate;
547
7.31k
        RETURN_IF_ERROR(parse_to_predicate(index, column.name(), column.get_vec_type(), condition,
548
7.31k
                                           _predicate_arena, predicate));
549
7.30k
        if (predicate != nullptr) {
550
7.29k
            delete_conditions->column_predicate_vec.push_back(predicate);
551
7.29k
        }
552
7.30k
    }
553
7.25k
    return Status::OK();
554
7.26k
}
_ZN5doris13DeleteHandler18_parse_column_predINS_20DeleteSubPredicatePBEQoosr3stdE9is_same_vIT_S2_Esr3stdE9is_same_vIS3_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEENS_6StatusESt10shared_ptrINS_12TabletSchemaEESD_RKN6google8protobuf16RepeatedPtrFieldIS3_EEPNS_16DeleteConditionsE
Line
Count
Source
529
6.99k
                                         DeleteConditions* delete_conditions) {
530
7.23k
    for (const auto& sub_predicate : sub_pred_list) {
531
7.23k
        auto condition = parse_condition(sub_predicate);
532
7.23k
        int32_t col_unique_id = -1;
533
7.23k
        if constexpr (std::is_same_v<SubPredType, DeleteSubPredicatePB>) {
534
7.23k
            if (sub_predicate.has_column_unique_id()) [[likely]] {
535
7.14k
                col_unique_id = sub_predicate.column_unique_id();
536
7.14k
            }
537
7.23k
        }
538
7.23k
        if (col_unique_id < 0) {
539
100
            const auto& column =
540
100
                    *DORIS_TRY(delete_pred_related_schema->column(condition.column_name));
541
100
            col_unique_id = column.unique_id();
542
100
        }
543
7.23k
        condition.col_unique_id = col_unique_id;
544
7.23k
        const auto& column = complete_schema->column_by_uid(col_unique_id);
545
7.23k
        uint32_t index = complete_schema->field_index(col_unique_id);
546
7.23k
        std::shared_ptr<ColumnPredicate> predicate;
547
7.23k
        RETURN_IF_ERROR(parse_to_predicate(index, column.name(), column.get_vec_type(), condition,
548
7.23k
                                           _predicate_arena, predicate));
549
7.23k
        if (predicate != nullptr) {
550
7.22k
            delete_conditions->column_predicate_vec.push_back(predicate);
551
7.22k
        }
552
7.23k
    }
553
6.99k
    return Status::OK();
554
6.99k
}
_ZN5doris13DeleteHandler18_parse_column_predINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEQoosr3stdE9is_same_vIT_NS_20DeleteSubPredicatePBEEsr3stdE9is_same_vIS8_S7_EEENS_6StatusESt10shared_ptrINS_12TabletSchemaEESD_RKN6google8protobuf16RepeatedPtrFieldIS8_EEPNS_16DeleteConditionsE
Line
Count
Source
529
268
                                         DeleteConditions* delete_conditions) {
530
268
    for (const auto& sub_predicate : sub_pred_list) {
531
81
        auto condition = parse_condition(sub_predicate);
532
81
        int32_t col_unique_id = -1;
533
        if constexpr (std::is_same_v<SubPredType, DeleteSubPredicatePB>) {
534
            if (sub_predicate.has_column_unique_id()) [[likely]] {
535
                col_unique_id = sub_predicate.column_unique_id();
536
            }
537
        }
538
81
        if (col_unique_id < 0) {
539
81
            const auto& column =
540
81
                    *DORIS_TRY(delete_pred_related_schema->column(condition.column_name));
541
81
            col_unique_id = column.unique_id();
542
81
        }
543
81
        condition.col_unique_id = col_unique_id;
544
81
        const auto& column = complete_schema->column_by_uid(col_unique_id);
545
81
        uint32_t index = complete_schema->field_index(col_unique_id);
546
81
        std::shared_ptr<ColumnPredicate> predicate;
547
81
        RETURN_IF_ERROR(parse_to_predicate(index, column.name(), column.get_vec_type(), condition,
548
81
                                           _predicate_arena, predicate));
549
74
        if (predicate != nullptr) {
550
74
            delete_conditions->column_predicate_vec.push_back(predicate);
551
74
        }
552
74
    }
553
261
    return Status::OK();
554
268
}
555
556
Status DeleteHandler::init(TabletSchemaSPtr tablet_schema,
557
1.20M
                           const std::vector<RowsetMetaSharedPtr>& delete_preds, int64_t version) {
558
18.4E
    DCHECK(!_is_inited) << "reinitialize delete handler.";
559
18.4E
    DCHECK(version >= 0) << "invalid parameters. version=" << version;
560
561
1.20M
    for (const auto& delete_pred : delete_preds) {
562
        // Skip the delete condition with large version
563
7.27k
        if (delete_pred->version().first > version) {
564
0
            continue;
565
0
        }
566
        // Need the tablet schema at the delete condition to parse the accurate column
567
7.27k
        const auto& delete_pred_related_schema = delete_pred->tablet_schema();
568
7.27k
        const auto& delete_condition = delete_pred->delete_predicate();
569
7.27k
        DeleteConditions temp;
570
7.27k
        temp.filter_version = delete_pred->version().first;
571
7.27k
        if (!delete_condition.sub_predicates_v2().empty()) {
572
7.01k
            RETURN_IF_ERROR(_parse_column_pred(tablet_schema, delete_pred_related_schema,
573
7.01k
                                               delete_condition.sub_predicates_v2(), &temp));
574
7.01k
        } else {
575
            // make it compatible with the former versions
576
260
            RETURN_IF_ERROR(_parse_column_pred(tablet_schema, delete_pred_related_schema,
577
260
                                               delete_condition.sub_predicates(), &temp));
578
260
        }
579
7.27k
        for (const auto& in_predicate : delete_condition.in_predicates()) {
580
242
            ConditionParseResult condition;
581
242
            condition.column_name = in_predicate.column_name();
582
583
242
            int32_t col_unique_id = -1;
584
242
            if (in_predicate.has_column_unique_id()) {
585
240
                col_unique_id = in_predicate.column_unique_id();
586
240
            } else {
587
                // if upgrade from version 2.0.x, column_unique_id maybe not set
588
2
                const auto& pre_column =
589
2
                        *DORIS_TRY(delete_pred_related_schema->column(condition.column_name));
590
2
                col_unique_id = pre_column.unique_id();
591
2
            }
592
242
            if (col_unique_id == -1) {
593
0
                return Status::Error<ErrorCode::DELETE_INVALID_CONDITION>(
594
0
                        "cannot get column_unique_id for column {}", condition.column_name);
595
0
            }
596
242
            condition.col_unique_id = col_unique_id;
597
598
242
            condition.condition_op =
599
242
                    in_predicate.is_not_in() ? PredicateType::NOT_IN_LIST : PredicateType::IN_LIST;
600
783
            for (const auto& value : in_predicate.values()) {
601
783
                condition.value_str.push_back(value);
602
783
            }
603
242
            const auto& column = tablet_schema->column_by_uid(col_unique_id);
604
242
            uint32_t index = tablet_schema->field_index(col_unique_id);
605
242
            std::shared_ptr<ColumnPredicate> predicate;
606
242
            RETURN_IF_ERROR(parse_to_in_predicate(index, column.name(), column.get_vec_type(),
607
242
                                                  condition, _predicate_arena, predicate));
608
242
            temp.column_predicate_vec.push_back(predicate);
609
242
        }
610
611
7.27k
        _del_conds.emplace_back(std::move(temp));
612
7.27k
    }
613
614
1.20M
    _is_inited = true;
615
616
1.20M
    return Status::OK();
617
1.20M
}
618
619
1.22M
DeleteHandler::~DeleteHandler() {
620
1.22M
    if (!_is_inited) {
621
25.6k
        return;
622
25.6k
    }
623
624
1.20M
    _del_conds.clear();
625
1.20M
    _is_inited = false;
626
1.20M
}
627
628
void DeleteHandler::get_delete_conditions_after_version(
629
        int64_t version, AndBlockColumnPredicate* and_block_column_predicate_ptr,
630
        std::unordered_map<int32_t, std::vector<std::shared_ptr<const ColumnPredicate>>>*
631
3.79M
                del_predicates_for_zone_map) const {
632
3.79M
    for (const auto& del_cond : _del_conds) {
633
73.8k
        if (del_cond.filter_version > version) {
634
            // now, only query support delete column predicate operator
635
41.4k
            if (!del_cond.column_predicate_vec.empty()) {
636
41.4k
                if (del_cond.column_predicate_vec.size() == 1) {
637
40.4k
                    auto single_column_block_predicate = SingleColumnBlockPredicate::create_unique(
638
40.4k
                            del_cond.column_predicate_vec[0]);
639
40.4k
                    and_block_column_predicate_ptr->add_column_predicate(
640
40.4k
                            std::move(single_column_block_predicate));
641
40.4k
                    if (del_predicates_for_zone_map->count(
642
40.4k
                                del_cond.column_predicate_vec[0]->column_id()) < 1) {
643
17.6k
                        del_predicates_for_zone_map->insert(
644
17.6k
                                {del_cond.column_predicate_vec[0]->column_id(),
645
17.6k
                                 std::vector<std::shared_ptr<const ColumnPredicate>> {}});
646
17.6k
                    }
647
40.4k
                    (*del_predicates_for_zone_map)[del_cond.column_predicate_vec[0]->column_id()]
648
40.4k
                            .push_back(del_cond.column_predicate_vec[0]);
649
40.4k
                } else {
650
961
                    auto or_column_predicate = OrBlockColumnPredicate::create_unique();
651
652
                    // build or_column_predicate
653
                    // when delete from where a = 1 and b = 2, we can not use del_predicates_for_zone_map to filter zone page,
654
                    // so here do not put predicate to del_predicates_for_zone_map,
655
                    // refer #17145 for more details.
656
                    // // TODO: need refactor design and code to use more version delete and more column delete to filter zone page.
657
961
                    std::for_each(del_cond.column_predicate_vec.cbegin(),
658
961
                                  del_cond.column_predicate_vec.cend(),
659
961
                                  [&or_column_predicate](
660
2.11k
                                          const std::shared_ptr<const ColumnPredicate> predicate) {
661
2.11k
                                      or_column_predicate->add_column_predicate(
662
2.11k
                                              SingleColumnBlockPredicate::create_unique(predicate));
663
2.11k
                                  });
664
961
                    and_block_column_predicate_ptr->add_column_predicate(
665
961
                            std::move(or_column_predicate));
666
961
                }
667
41.4k
            }
668
41.4k
        }
669
73.8k
    }
670
3.79M
}
671
672
} // namespace doris