Coverage Report

Created: 2026-10-16 23:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vcompound_pred.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
#include <gen_cpp/Opcodes_types.h>
20
21
#include <algorithm>
22
#include <cstdint>
23
#include <memory>
24
25
#include "common/logging.h"
26
#include "common/status.h"
27
#include "core/assert_cast.h"
28
#include "core/column/column.h"
29
#include "core/column/column_nullable.h"
30
#include "exprs/vectorized_fn_call.h"
31
#include "exprs/vexpr_context.h"
32
#include "exprs/vexpr_fwd.h"
33
#include "storage/index/inverted/query/scoring/collection_similarity.h"
34
#include "storage/index/zone_map/zonemap_eval_context.h"
35
#include "util/defer_op.h"
36
#include "util/simd/bits.h"
37
38
namespace doris {
39
40
9.11k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
41
9.11k
    if (op == TExprOpcode::COMPOUND_AND) {
42
1.74k
        return "and";
43
7.37k
    } else if (op == TExprOpcode::COMPOUND_OR) {
44
4.99k
        return "or";
45
4.99k
    } else {
46
2.37k
        return "not";
47
2.37k
    }
48
9.11k
}
49
50
206
inline bool inverted_index_status_allows_row_fallback(const Status& status) {
51
206
    DORIS_CHECK(!status.ok());
52
206
    return status.is<ErrorCode::INVERTED_INDEX_BYPASS>() ||
53
206
           status.is<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>() ||
54
206
           status.is<ErrorCode::INVERTED_INDEX_FILE_CORRUPTED>() ||
55
206
           status.is<ErrorCode::INVERTED_INDEX_FILE_NOT_FOUND>() ||
56
206
           status.is<ErrorCode::NOT_IMPLEMENTED_ERROR>();
57
206
}
58
59
class VCompoundPred : public VectorizedFnCall {
60
    ENABLE_FACTORY_CREATOR(VCompoundPred);
61
62
public:
63
9.11k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
64
9.11k
        _op = node.opcode;
65
9.11k
        _fn.name.function_name = compound_operator_to_string(_op);
66
9.11k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
67
9.11k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
68
9.11k
    }
69
70
#ifdef BE_TEST
71
    VCompoundPred() = default;
72
#endif
73
74
14.5k
    const std::string& expr_name() const override { return _expr_name; }
75
8
    Status clone_node(VExprSPtr* cloned_expr) const override {
76
8
        DORIS_CHECK(cloned_expr != nullptr);
77
8
        *cloned_expr = VCompoundPred::create_shared(clone_texpr_node());
78
8
        return Status::OK();
79
8
    }
80
81
    bool can_execute_on_raw_fixed_values(const DataTypePtr& data_type,
82
24
                                         int column_id) const override {
83
24
        return !_children.empty() &&
84
24
               (_op == TExprOpcode::COMPOUND_AND || _op == TExprOpcode::COMPOUND_OR) &&
85
27
               std::ranges::all_of(_children, [&](const VExprSPtr& child) {
86
27
                   return child->can_execute_on_raw_fixed_values(data_type, column_id);
87
27
               });
88
24
    }
89
90
    Status execute_on_raw_fixed_values(const uint8_t* values, size_t num_values, size_t value_width,
91
                                       const DataTypePtr& data_type, int column_id,
92
2
                                       uint8_t* matches) const override {
93
2
        if (!can_execute_on_raw_fixed_values(data_type, column_id)) {
94
0
            return Status::NotSupported("Compound predicate cannot evaluate raw fixed values");
95
0
        }
96
2
        return _execute_raw_compound(
97
4
                num_values, matches, [&](const VExprSPtr& child, uint8_t* child_matches) {
98
4
                    return child->execute_on_raw_fixed_values(values, num_values, value_width,
99
4
                                                              data_type, column_id, child_matches);
100
4
                });
101
2
    }
102
103
    bool can_execute_on_raw_binary_values(const DataTypePtr& data_type,
104
40
                                          int column_id) const override {
105
40
        return !_children.empty() &&
106
40
               (_op == TExprOpcode::COMPOUND_AND || _op == TExprOpcode::COMPOUND_OR) &&
107
80
               std::ranges::all_of(_children, [&](const VExprSPtr& child) {
108
80
                   return child->can_execute_on_raw_binary_values(data_type, column_id);
109
80
               });
110
40
    }
111
112
    Status execute_on_raw_binary_values(const StringRef* values, size_t num_values,
113
                                        const DataTypePtr& data_type, int column_id,
114
8
                                        uint8_t* matches) const override {
115
8
        if (!can_execute_on_raw_binary_values(data_type, column_id)) {
116
0
            return Status::NotSupported("Compound predicate cannot evaluate raw binary values");
117
0
        }
118
8
        return _execute_raw_compound(
119
16
                num_values, matches, [&](const VExprSPtr& child, uint8_t* child_matches) {
120
16
                    return child->execute_on_raw_binary_values(values, num_values, data_type,
121
16
                                                               column_id, child_matches);
122
16
                });
123
8
    }
124
125
12
    bool raw_predicate_result_for_null() const override {
126
12
        if (_op != TExprOpcode::COMPOUND_AND && _op != TExprOpcode::COMPOUND_OR) {
127
            // A Boolean keep bit cannot distinguish FALSE from UNKNOWN, so negating a child's
128
            // collapsed result is not SQL-correct. NOT remains residual and rejects NULL here.
129
0
            return false;
130
0
        }
131
12
        if (_op == TExprOpcode::COMPOUND_AND) {
132
3
            return std::ranges::all_of(_children, [](const VExprSPtr& child) {
133
3
                return child->raw_predicate_result_for_null();
134
3
            });
135
3
        }
136
18
        return std::ranges::any_of(_children, [](const VExprSPtr& child) {
137
18
            return child->raw_predicate_result_for_null();
138
18
        });
139
12
    }
140
141
18.5k
    bool can_evaluate_zonemap_filter() const override {
142
18.5k
        switch (_op) {
143
3.64k
        case TExprOpcode::COMPOUND_AND:
144
4.36k
            return std::ranges::any_of(_children, [](const VExprSPtr& child) {
145
4.36k
                return child->can_evaluate_zonemap_filter();
146
4.36k
            });
147
10.1k
        case TExprOpcode::COMPOUND_OR:
148
17.3k
            return !_children.empty() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
149
17.3k
                return child->can_evaluate_zonemap_filter();
150
17.3k
            });
151
4.71k
        case TExprOpcode::COMPOUND_NOT:
152
4.71k
            return false;
153
0
        default:
154
0
            return false;
155
18.5k
        }
156
18.5k
    }
157
158
3.17k
    ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const override {
159
3.17k
        switch (_op) {
160
510
        case TExprOpcode::COMPOUND_AND: {
161
930
            for (const auto& child : _children) {
162
930
                if (!child->can_evaluate_zonemap_filter()) {
163
134
                    continue;
164
134
                }
165
796
                if (child->evaluate_zonemap_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
166
222
                    return ZoneMapFilterResult::kNoMatch;
167
222
                }
168
796
            }
169
288
            return ZoneMapFilterResult::kMayMatch;
170
510
        }
171
2.67k
        case TExprOpcode::COMPOUND_OR: {
172
4.34k
            for (const auto& child : _children) {
173
4.34k
                DORIS_CHECK(child->can_evaluate_zonemap_filter());
174
4.34k
                if (child->evaluate_zonemap_filter(ctx) != ZoneMapFilterResult::kNoMatch) {
175
2.29k
                    return ZoneMapFilterResult::kMayMatch;
176
2.29k
                }
177
4.34k
            }
178
380
            return ZoneMapFilterResult::kNoMatch;
179
2.67k
        }
180
1
        case TExprOpcode::COMPOUND_NOT:
181
1
            return unsupported_zonemap_filter(ctx);
182
0
        default:
183
0
            return unsupported_zonemap_filter(ctx);
184
3.17k
        }
185
3.17k
    }
186
187
33
    bool can_evaluate_dictionary_filter() const override {
188
33
        switch (_op) {
189
30
        case TExprOpcode::COMPOUND_AND:
190
33
            return std::ranges::any_of(_children, [](const VExprSPtr& child) {
191
33
                return child->can_evaluate_dictionary_filter();
192
33
            });
193
3
        case TExprOpcode::COMPOUND_OR:
194
6
            return !_children.empty() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
195
6
                return child->can_evaluate_dictionary_filter();
196
6
            });
197
0
        default:
198
0
            return false;
199
33
        }
200
33
    }
201
202
13
    bool is_safe_to_execute_on_selected_rows() const override {
203
        // Boolean composition introduces no data-dependent failure of its own. Reuse the generic
204
        // child walk so AND/OR remain eligible only when every nested expression is independently
205
        // safe; applying VectorizedFnCall's scalar-function allowlist to this structural node would
206
        // incorrectly disable selected-row execution for otherwise safe predicates.
207
13
        return VExpr::is_safe_to_execute_on_selected_rows();
208
13
    }
209
210
    ZoneMapFilterResult evaluate_dictionary_filter(
211
21
            const DictionaryEvalContext& ctx) const override {
212
21
        switch (_op) {
213
21
        case TExprOpcode::COMPOUND_AND:
214
29
            for (const auto& child : _children) {
215
29
                if (!child->can_evaluate_dictionary_filter()) {
216
8
                    continue;
217
8
                }
218
21
                if (child->evaluate_dictionary_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
219
13
                    return ZoneMapFilterResult::kNoMatch;
220
13
                }
221
21
            }
222
8
            return ZoneMapFilterResult::kMayMatch;
223
0
        case TExprOpcode::COMPOUND_OR:
224
0
            for (const auto& child : _children) {
225
0
                DORIS_CHECK(child->can_evaluate_dictionary_filter());
226
0
                if (child->evaluate_dictionary_filter(ctx) != ZoneMapFilterResult::kNoMatch) {
227
0
                    return ZoneMapFilterResult::kMayMatch;
228
0
                }
229
0
            }
230
0
            return ZoneMapFilterResult::kNoMatch;
231
0
        default:
232
0
            return ZoneMapFilterResult::kUnsupported;
233
21
        }
234
21
    }
235
236
14
    bool can_evaluate_bloom_filter() const override {
237
14
        switch (_op) {
238
9
        case TExprOpcode::COMPOUND_AND:
239
15
            return std::ranges::any_of(_children, [](const VExprSPtr& child) {
240
15
                return child->can_evaluate_bloom_filter();
241
15
            });
242
5
        case TExprOpcode::COMPOUND_OR:
243
8
            return !_children.empty() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
244
8
                return child->can_evaluate_bloom_filter();
245
8
            });
246
0
        default:
247
0
            return false;
248
14
        }
249
14
    }
250
251
0
    ZoneMapFilterResult evaluate_bloom_filter(const BloomFilterEvalContext& ctx) const override {
252
0
        switch (_op) {
253
0
        case TExprOpcode::COMPOUND_AND:
254
0
            for (const auto& child : _children) {
255
0
                if (!child->can_evaluate_bloom_filter()) {
256
0
                    continue;
257
0
                }
258
0
                if (child->evaluate_bloom_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
259
0
                    return ZoneMapFilterResult::kNoMatch;
260
0
                }
261
0
            }
262
0
            return ZoneMapFilterResult::kMayMatch;
263
0
        case TExprOpcode::COMPOUND_OR:
264
0
            for (const auto& child : _children) {
265
0
                DORIS_CHECK(child->can_evaluate_bloom_filter());
266
0
                if (child->evaluate_bloom_filter(ctx) != ZoneMapFilterResult::kNoMatch) {
267
0
                    return ZoneMapFilterResult::kMayMatch;
268
0
                }
269
0
            }
270
0
            return ZoneMapFilterResult::kNoMatch;
271
0
        default:
272
0
            return ZoneMapFilterResult::kUnsupported;
273
0
        }
274
0
    }
275
276
    // NOLINTNEXTLINE(readability-function-size,readability-function-cognitive-complexity): Keep each operator's bitmap and score updates together.
277
5.69k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
278
5.69k
        segment_v2::InvertedIndexResultBitmap res;
279
5.69k
        bool all_pass = true;
280
5.69k
        auto index_context = context->get_index_context();
281
5.69k
        auto query_context = index_context->get_index_query_context();
282
5.69k
        auto parent_similarity =
283
18.4E
                query_context != nullptr ? query_context->collection_similarity : nullptr;
284
5.69k
        CollectionSimilarityPtr branch_similarity;
285
5.69k
        if (parent_similarity != nullptr) {
286
20
            branch_similarity = std::make_shared<CollectionSimilarity>();
287
20
            query_context->collection_similarity = branch_similarity;
288
20
        }
289
5.70k
        Defer restore_similarity {[&]() {
290
5.70k
            if (branch_similarity != nullptr) {
291
20
                query_context->collection_similarity = parent_similarity;
292
20
            }
293
5.70k
        }};
294
295
5.69k
        switch (_op) {
296
3.19k
        case TExprOpcode::COMPOUND_OR: {
297
6.18k
            for (const auto& child : _children) {
298
6.18k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
299
6.18k
                    !st.ok()) {
300
176
                    LOG(ERROR) << "expr:" << child->expr_name()
301
176
                               << " evaluate_inverted_index error:" << st.to_string();
302
176
                    if (!inverted_index_status_allows_row_fallback(st)) {
303
2
                        return st;
304
2
                    }
305
174
                    all_pass = false;
306
174
                    continue;
307
176
                }
308
6.00k
                auto inverted_index_context = context->get_index_context();
309
6.00k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
310
2.81k
                    const auto* index_result =
311
2.81k
                            inverted_index_context->get_index_result_for_expr(child.get());
312
2.81k
                    if (res.is_empty()) {
313
1.93k
                        res = *index_result;
314
1.93k
                    } else {
315
885
                        res |= *index_result;
316
885
                    }
317
2.81k
                    if (branch_similarity == nullptr) {
318
2.81k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
319
343
                            break; // Early exit if result is full
320
343
                        }
321
2.81k
                    }
322
3.18k
                } else {
323
3.18k
                    all_pass = false;
324
3.18k
                }
325
6.00k
            }
326
3.19k
            break;
327
3.19k
        }
328
3.19k
        case TExprOpcode::COMPOUND_AND: {
329
1.85k
            for (const auto& child : _children) {
330
1.85k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
331
1.85k
                    !st.ok()) {
332
28
                    LOG(ERROR) << "expr:" << child->expr_name()
333
28
                               << " evaluate_inverted_index error:" << st.to_string();
334
28
                    if (!inverted_index_status_allows_row_fallback(st)) {
335
2
                        return st;
336
2
                    }
337
26
                    all_pass = false;
338
26
                    continue;
339
28
                }
340
1.82k
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
341
258
                    const auto* index_result =
342
258
                            context->get_index_context()->get_index_result_for_expr(child.get());
343
258
                    if (res.is_empty()) {
344
192
                        res = *index_result;
345
192
                    } else {
346
66
                        res &= *index_result;
347
66
                    }
348
349
258
                    if (res.get_data_bitmap()->isEmpty()) {
350
102
                        break; // Early exit if result is empty
351
102
                    }
352
1.56k
                } else {
353
1.56k
                    all_pass = false;
354
1.56k
                }
355
1.82k
            }
356
971
            break;
357
973
        }
358
1.51k
        case TExprOpcode::COMPOUND_NOT: {
359
1.51k
            const auto& child = _children[0];
360
1.51k
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
361
1.51k
            if (!st.ok()) {
362
37
                LOG(ERROR) << "expr:" << child->expr_name()
363
37
                           << " evaluate_inverted_index error:" << st.to_string();
364
37
                return st;
365
37
            }
366
367
1.47k
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
368
695
                const auto* index_result =
369
695
                        context->get_index_context()->get_index_result_for_expr(child.get());
370
695
                roaring::Roaring full_result;
371
695
                full_result.addRange(0, segment_num_rows);
372
695
                res = index_result->op_not(&full_result);
373
783
            } else {
374
783
                all_pass = false;
375
783
            }
376
1.47k
            break;
377
1.51k
        }
378
0
        default:
379
0
            return Status::NotSupported(
380
0
                    "Compound operator must be AND, OR, or NOT to execute with inverted index.");
381
5.69k
        }
382
383
5.68k
        if (branch_similarity != nullptr && _op != TExprOpcode::COMPOUND_NOT) {
384
16
            auto scores = branch_similarity->release_scores();
385
16
            if (!scores.empty() && (!all_pass || res.is_empty())) {
386
2
                return Status::Error<ErrorCode::INVERTED_INDEX_NOT_SUPPORTED>(
387
2
                        "Cannot score a compound predicate with incomplete index evaluation");
388
2
            }
389
14
            if (all_pass && !res.is_empty()) {
390
14
                DORIS_CHECK(res.get_data_bitmap() != nullptr);
391
14
                parent_similarity->merge_scores(scores, *res.get_data_bitmap());
392
14
            }
393
14
        }
394
5.67k
        if (all_pass && !res.is_empty()) {
395
1.96k
            index_context->set_index_result_for_expr(this, res);
396
1.96k
        }
397
5.67k
        return Status::OK();
398
5.68k
    }
399
400
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
401
25.9k
                               size_t count, ColumnPtr& result_column) const override {
402
25.9k
        if (fast_execute(context, selector, count, result_column)) {
403
97
            return Status::OK();
404
97
        }
405
25.8k
        if (get_num_children() == 1 || _has_const_child()) {
406
3.56k
            return VectorizedFnCall::execute_column_impl(context, block, selector, count,
407
3.56k
                                                         result_column);
408
3.56k
        }
409
410
22.2k
        ColumnPtr lhs_column;
411
22.2k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
412
22.2k
        lhs_column = lhs_column->convert_to_full_column_if_const();
413
22.2k
        size_t size = lhs_column->size();
414
415
22.2k
        bool lhs_is_nullable = lhs_column->is_nullable();
416
22.2k
        auto [lhs_data_column, lhs_null_map] =
417
22.2k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
418
22.2k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
419
22.2k
        bool lhs_all_true = (filted == 0);
420
22.2k
        bool lhs_all_false = (filted == size);
421
422
22.2k
        bool lhs_all_is_not_null = false;
423
22.2k
        if (lhs_is_nullable) {
424
11.5k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
425
11.5k
            lhs_all_is_not_null = (filted == size);
426
11.5k
        }
427
428
22.2k
        ColumnPtr rhs_column = nullptr;
429
22.2k
        const uint8_t* __restrict rhs_data_column = nullptr;
430
22.2k
        const uint8_t* __restrict rhs_null_map = nullptr;
431
22.2k
        bool rhs_is_nullable = false;
432
22.2k
        bool rhs_all_true = false;
433
22.2k
        bool rhs_all_false = false;
434
22.2k
        bool rhs_all_is_not_null = false;
435
22.2k
        bool result_is_nullable = _data_type->is_nullable();
436
437
22.2k
        auto get_rhs_colum = [&]() {
438
16.1k
            if (!rhs_column) {
439
16.1k
                RETURN_IF_ERROR(
440
16.1k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
441
16.1k
                rhs_column = rhs_column->convert_to_full_column_if_const();
442
16.1k
                rhs_is_nullable = rhs_column->is_nullable();
443
16.1k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
444
16.1k
                rhs_data_column = rhs_nullable_column.first;
445
16.1k
                rhs_null_map = rhs_nullable_column.second;
446
16.1k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
447
16.1k
                rhs_all_true = (filted == 0);
448
16.1k
                rhs_all_false = (filted == size);
449
16.1k
                if (rhs_is_nullable) {
450
10.9k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
451
10.9k
                    rhs_all_is_not_null = (filted == size);
452
10.9k
                }
453
16.1k
            }
454
16.1k
            return Status::OK();
455
16.1k
        };
456
457
22.2k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
458
18.5k
            result_column = std::move(*arg_column).mutate();
459
18.5k
            if (result_is_nullable && !result_column->is_nullable()) {
460
2.89k
                result_column = make_nullable(result_column);
461
2.89k
            }
462
18.5k
        };
463
464
22.2k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
465
22.2k
                                          const uint8_t* __restrict null_map_data) {
466
6.17k
            if (null_map_data == nullptr) {
467
799
                null_map_column = ColumnUInt8::create(size, 0);
468
799
                null_map_data =
469
799
                        assert_cast<const ColumnUInt8*>(null_map_column.get())->get_data().data();
470
799
            }
471
6.17k
            return null_map_data;
472
6.17k
        };
473
474
22.2k
        auto vector_vector = [&]<bool is_and_op>() {
475
694
            MutableColumnPtr mutable_result_column;
476
694
            uint8_t* __restrict result_data_column = nullptr;
477
694
            const uint8_t* __restrict other_data_column = rhs_data_column;
478
694
            if (lhs_column->use_count() == 1) {
479
646
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
480
646
                result_data_column =
481
646
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
482
646
            } else if (rhs_column->use_count() == 1) {
483
2
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
484
2
                result_data_column =
485
2
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
486
2
                other_data_column = lhs_data_column;
487
46
            } else {
488
46
                mutable_result_column = lhs_column->clone_resized(size);
489
46
                result_data_column =
490
46
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
491
46
            }
492
493
694
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
494
694
            result_column = std::move(mutable_result_column);
495
694
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb1EEEDav
Line
Count
Source
474
490
        auto vector_vector = [&]<bool is_and_op>() {
475
490
            MutableColumnPtr mutable_result_column;
476
490
            uint8_t* __restrict result_data_column = nullptr;
477
490
            const uint8_t* __restrict other_data_column = rhs_data_column;
478
490
            if (lhs_column->use_count() == 1) {
479
490
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
480
490
                result_data_column =
481
490
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
482
490
            } else if (rhs_column->use_count() == 1) {
483
0
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
484
0
                result_data_column =
485
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
486
0
                other_data_column = lhs_data_column;
487
0
            } else {
488
0
                mutable_result_column = lhs_column->clone_resized(size);
489
0
                result_data_column =
490
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
491
0
            }
492
493
490
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
494
490
            result_column = std::move(mutable_result_column);
495
490
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb0EEEDav
Line
Count
Source
474
204
        auto vector_vector = [&]<bool is_and_op>() {
475
204
            MutableColumnPtr mutable_result_column;
476
204
            uint8_t* __restrict result_data_column = nullptr;
477
204
            const uint8_t* __restrict other_data_column = rhs_data_column;
478
204
            if (lhs_column->use_count() == 1) {
479
156
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
480
156
                result_data_column =
481
156
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
482
156
            } else if (rhs_column->use_count() == 1) {
483
2
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
484
2
                result_data_column =
485
2
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
486
2
                other_data_column = lhs_data_column;
487
46
            } else {
488
46
                mutable_result_column = lhs_column->clone_resized(size);
489
46
                result_data_column =
490
46
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
491
46
            }
492
493
204
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
494
204
            result_column = std::move(mutable_result_column);
495
204
        };
496
22.2k
        auto vector_vector_null = [&]<bool is_and_op>() {
497
3.08k
            auto col_res = ColumnUInt8::create(size);
498
3.08k
            auto col_nulls = ColumnUInt8::create(size);
499
500
3.08k
            auto* __restrict res_datas = col_res->get_data().data();
501
3.08k
            auto* __restrict res_nulls = col_nulls->get_data().data();
502
3.08k
            ColumnPtr temp_null_map = nullptr;
503
            // maybe both children are nullable / or one of children is nullable
504
3.08k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
505
3.08k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
506
3.08k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
507
3.08k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
508
509
3.08k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
510
3.08k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
511
512
3.08k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
513
3.08k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
496
815
        auto vector_vector_null = [&]<bool is_and_op>() {
497
815
            auto col_res = ColumnUInt8::create(size);
498
815
            auto col_nulls = ColumnUInt8::create(size);
499
500
815
            auto* __restrict res_datas = col_res->get_data().data();
501
815
            auto* __restrict res_nulls = col_nulls->get_data().data();
502
815
            ColumnPtr temp_null_map = nullptr;
503
            // maybe both children are nullable / or one of children is nullable
504
815
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
505
815
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
506
815
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
507
815
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
508
509
815
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
510
815
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
511
512
815
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
513
815
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
496
2.26k
        auto vector_vector_null = [&]<bool is_and_op>() {
497
2.26k
            auto col_res = ColumnUInt8::create(size);
498
2.26k
            auto col_nulls = ColumnUInt8::create(size);
499
500
2.26k
            auto* __restrict res_datas = col_res->get_data().data();
501
2.26k
            auto* __restrict res_nulls = col_nulls->get_data().data();
502
2.26k
            ColumnPtr temp_null_map = nullptr;
503
            // maybe both children are nullable / or one of children is nullable
504
2.26k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
505
2.26k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
506
2.26k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
507
2.26k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
508
509
2.26k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
510
2.26k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
511
512
2.26k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
513
2.26k
        };
514
515
        // false and NULL ----> 0
516
        // true  and NULL ----> NULL
517
22.2k
        if (_op == TExprOpcode::COMPOUND_AND) {
518
            //1. not null column: all data is false
519
            //2. nullable column: null map all is not null
520
5.22k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
521
                // false and any = false, return lhs
522
2.06k
                return_result_column_id(lhs_column);
523
3.16k
            } else {
524
3.16k
                RETURN_IF_ERROR(get_rhs_colum());
525
526
3.16k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
527
3.16k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
528
                                                             // true and any = any, return rhs
529
530
1.37k
                    return_result_column_id(rhs_column);
531
1.78k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
532
1.78k
                           (rhs_all_false && rhs_all_is_not_null)) {
533
                    // any and false = false, return rhs
534
208
                    return_result_column_id(rhs_column);
535
1.57k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
536
1.57k
                           (rhs_all_true && rhs_all_is_not_null)) {
537
                    // any and true = any, return lhs
538
273
                    return_result_column_id(lhs_column);
539
1.30k
                } else {
540
1.30k
                    if (!result_is_nullable) {
541
490
                        vector_vector.template operator()<true>();
542
813
                    } else {
543
813
                        vector_vector_null.template operator()<true>();
544
813
                    }
545
1.30k
                }
546
3.16k
            }
547
17.1k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
548
            // true  or NULL ----> 1
549
            // false or NULL ----> NULL
550
17.1k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
551
                // true or any = true, return lhs
552
4.06k
                return_result_column_id(lhs_column);
553
13.0k
            } else {
554
13.0k
                RETURN_IF_ERROR(get_rhs_colum());
555
13.0k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
556
                    // false or any = any, return rhs
557
9.24k
                    return_result_column_id(rhs_column);
558
9.24k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
559
3.81k
                           (rhs_all_true && rhs_all_is_not_null)) {
560
                    // any or true = true, return rhs
561
727
                    return_result_column_id(rhs_column);
562
3.08k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
563
3.08k
                           (rhs_all_false && rhs_all_is_not_null)) {
564
                    // any or false = any, return lhs
565
661
                    return_result_column_id(lhs_column);
566
2.42k
                } else {
567
2.42k
                    if (!result_is_nullable) {
568
204
                        vector_vector.template operator()<false>();
569
2.21k
                    } else {
570
2.21k
                        vector_vector_null.template operator()<false>();
571
2.21k
                    }
572
2.42k
                }
573
13.0k
            }
574
18.4E
        } else {
575
18.4E
            return Status::InternalError("Compound operator must be AND or OR.");
576
18.4E
        }
577
578
22.3k
        DCHECK_EQ(result_column->size(), count);
579
22.3k
        return Status::OK();
580
22.2k
    }
581
582
958
    double execute_cost() const override {
583
958
        double cost = 0.3;
584
1.51k
        for (const auto& child : _children) {
585
1.51k
            cost += child->execute_cost();
586
1.51k
        }
587
958
        return cost;
588
958
    }
589
590
private:
591
    template <typename ExecuteChild>
592
    Status _execute_raw_compound(size_t num_values, uint8_t* matches,
593
10
                                 ExecuteChild&& execute_child) const {
594
10
        if (_op == TExprOpcode::COMPOUND_AND) {
595
2
            for (const auto& child : _children) {
596
2
                RETURN_IF_ERROR(execute_child(child, matches));
597
2
            }
598
1
            return Status::OK();
599
1
        }
600
601
        // Each execution context owns its expression tree. Retaining masks on the OR node avoids
602
        // N+1 row-sized allocations for every decoder fragment, while nested OR nodes keep
603
        // independent buffers and therefore cannot overwrite their parent's in-flight state.
604
9
        _raw_combined_scratch.resize(num_values);
605
9
        std::ranges::fill(_raw_combined_scratch, 0);
606
18
        for (const auto& child : _children) {
607
            // resize_fill() initializes only newly appended bytes; explicitly reset a reused mask
608
            // so matches from an earlier page fragment cannot leak into this OR evaluation.
609
18
            _raw_child_scratch.resize(num_values);
610
18
            std::ranges::fill(_raw_child_scratch, 1);
611
18
            RETURN_IF_ERROR(execute_child(child, _raw_child_scratch.data()));
612
154
            for (size_t row = 0; row < num_values; ++row) {
613
136
                _raw_combined_scratch[row] |= _raw_child_scratch[row];
614
136
            }
615
18
        }
616
        // Raw kernels receive an existing selection mask, so composition must preserve rows that
617
        // an earlier conjunct already rejected instead of replacing the caller's mask.
618
77
        for (size_t row = 0; row < num_values; ++row) {
619
68
            matches[row] &= _raw_combined_scratch[row];
620
68
        }
621
9
        constexpr size_t MAX_RETAINED_RAW_MASK_BYTES = 1UL << 20;
622
9
        if (_raw_combined_scratch.capacity() > MAX_RETAINED_RAW_MASK_BYTES) {
623
0
            IColumn::Filter().swap(_raw_combined_scratch);
624
0
        }
625
9
        if (_raw_child_scratch.capacity() > MAX_RETAINED_RAW_MASK_BYTES) {
626
0
            IColumn::Filter().swap(_raw_child_scratch);
627
0
        }
628
9
        return Status::OK();
629
9
    }
_ZNK5doris13VCompoundPred21_execute_raw_compoundIZNKS0_27execute_on_raw_fixed_valuesEPKhmmRKSt10shared_ptrIKNS_9IDataTypeEEiPhEUlRKS4_INS_5VExprEESA_E_EENS_6StatusEmSA_OT_
Line
Count
Source
593
2
                                 ExecuteChild&& execute_child) const {
594
2
        if (_op == TExprOpcode::COMPOUND_AND) {
595
2
            for (const auto& child : _children) {
596
2
                RETURN_IF_ERROR(execute_child(child, matches));
597
2
            }
598
1
            return Status::OK();
599
1
        }
600
601
        // Each execution context owns its expression tree. Retaining masks on the OR node avoids
602
        // N+1 row-sized allocations for every decoder fragment, while nested OR nodes keep
603
        // independent buffers and therefore cannot overwrite their parent's in-flight state.
604
1
        _raw_combined_scratch.resize(num_values);
605
1
        std::ranges::fill(_raw_combined_scratch, 0);
606
2
        for (const auto& child : _children) {
607
            // resize_fill() initializes only newly appended bytes; explicitly reset a reused mask
608
            // so matches from an earlier page fragment cannot leak into this OR evaluation.
609
2
            _raw_child_scratch.resize(num_values);
610
2
            std::ranges::fill(_raw_child_scratch, 1);
611
2
            RETURN_IF_ERROR(execute_child(child, _raw_child_scratch.data()));
612
10
            for (size_t row = 0; row < num_values; ++row) {
613
8
                _raw_combined_scratch[row] |= _raw_child_scratch[row];
614
8
            }
615
2
        }
616
        // Raw kernels receive an existing selection mask, so composition must preserve rows that
617
        // an earlier conjunct already rejected instead of replacing the caller's mask.
618
5
        for (size_t row = 0; row < num_values; ++row) {
619
4
            matches[row] &= _raw_combined_scratch[row];
620
4
        }
621
1
        constexpr size_t MAX_RETAINED_RAW_MASK_BYTES = 1UL << 20;
622
1
        if (_raw_combined_scratch.capacity() > MAX_RETAINED_RAW_MASK_BYTES) {
623
0
            IColumn::Filter().swap(_raw_combined_scratch);
624
0
        }
625
1
        if (_raw_child_scratch.capacity() > MAX_RETAINED_RAW_MASK_BYTES) {
626
0
            IColumn::Filter().swap(_raw_child_scratch);
627
0
        }
628
1
        return Status::OK();
629
1
    }
_ZNK5doris13VCompoundPred21_execute_raw_compoundIZNKS0_28execute_on_raw_binary_valuesEPKNS_9StringRefEmRKSt10shared_ptrIKNS_9IDataTypeEEiPhEUlRKS5_INS_5VExprEESB_E_EENS_6StatusEmSB_OT_
Line
Count
Source
593
8
                                 ExecuteChild&& execute_child) const {
594
8
        if (_op == TExprOpcode::COMPOUND_AND) {
595
0
            for (const auto& child : _children) {
596
0
                RETURN_IF_ERROR(execute_child(child, matches));
597
0
            }
598
0
            return Status::OK();
599
0
        }
600
601
        // Each execution context owns its expression tree. Retaining masks on the OR node avoids
602
        // N+1 row-sized allocations for every decoder fragment, while nested OR nodes keep
603
        // independent buffers and therefore cannot overwrite their parent's in-flight state.
604
8
        _raw_combined_scratch.resize(num_values);
605
8
        std::ranges::fill(_raw_combined_scratch, 0);
606
16
        for (const auto& child : _children) {
607
            // resize_fill() initializes only newly appended bytes; explicitly reset a reused mask
608
            // so matches from an earlier page fragment cannot leak into this OR evaluation.
609
16
            _raw_child_scratch.resize(num_values);
610
16
            std::ranges::fill(_raw_child_scratch, 1);
611
16
            RETURN_IF_ERROR(execute_child(child, _raw_child_scratch.data()));
612
144
            for (size_t row = 0; row < num_values; ++row) {
613
128
                _raw_combined_scratch[row] |= _raw_child_scratch[row];
614
128
            }
615
16
        }
616
        // Raw kernels receive an existing selection mask, so composition must preserve rows that
617
        // an earlier conjunct already rejected instead of replacing the caller's mask.
618
72
        for (size_t row = 0; row < num_values; ++row) {
619
64
            matches[row] &= _raw_combined_scratch[row];
620
64
        }
621
8
        constexpr size_t MAX_RETAINED_RAW_MASK_BYTES = 1UL << 20;
622
8
        if (_raw_combined_scratch.capacity() > MAX_RETAINED_RAW_MASK_BYTES) {
623
0
            IColumn::Filter().swap(_raw_combined_scratch);
624
0
        }
625
8
        if (_raw_child_scratch.capacity() > MAX_RETAINED_RAW_MASK_BYTES) {
626
0
            IColumn::Filter().swap(_raw_child_scratch);
627
0
        }
628
8
        return Status::OK();
629
8
    }
630
631
    mutable IColumn::Filter _raw_combined_scratch;
632
    mutable IColumn::Filter _raw_child_scratch;
633
634
8.28k
    static inline constexpr uint8_t apply_and_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
635
        // (<> && false) is false, (true && NULL) is NULL
636
8.28k
        return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b));
637
8.28k
    }
638
877k
    static inline constexpr uint8_t apply_or_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
639
        // (<> || true) is true, (false || NULL) is NULL
640
877k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
641
877k
    }
642
643
    template <bool is_and>
644
    void static do_not_null_pred(uint8_t* __restrict lhs, const uint8_t* __restrict rhs,
645
694
                                 size_t size) {
646
#ifdef NDEBUG
647
#if defined(__clang__)
648
#pragma clang loop vectorize(enable)
649
#elif defined(__GNUC__) && (__GNUC__ >= 5)
650
#pragma GCC ivdep
651
#endif
652
#endif
653
16.6k
        for (size_t i = 0; i < size; ++i) {
654
15.9k
            if constexpr (is_and) {
655
10.9k
                lhs[i] &= rhs[i];
656
10.9k
            } else {
657
                // Logical OR must produce a canonical Boolean instead of preserving input bits.
658
5.01k
                lhs[i] = (lhs[i] | rhs[i]) != 0;
659
5.01k
            }
660
15.9k
        }
661
694
    }
_ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhPKhm
Line
Count
Source
645
490
                                 size_t size) {
646
#ifdef NDEBUG
647
#if defined(__clang__)
648
#pragma clang loop vectorize(enable)
649
#elif defined(__GNUC__) && (__GNUC__ >= 5)
650
#pragma GCC ivdep
651
#endif
652
#endif
653
11.4k
        for (size_t i = 0; i < size; ++i) {
654
10.9k
            if constexpr (is_and) {
655
10.9k
                lhs[i] &= rhs[i];
656
            } else {
657
                // Logical OR must produce a canonical Boolean instead of preserving input bits.
658
                lhs[i] = (lhs[i] | rhs[i]) != 0;
659
            }
660
10.9k
        }
661
490
    }
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhPKhm
Line
Count
Source
645
204
                                 size_t size) {
646
#ifdef NDEBUG
647
#if defined(__clang__)
648
#pragma clang loop vectorize(enable)
649
#elif defined(__GNUC__) && (__GNUC__ >= 5)
650
#pragma GCC ivdep
651
#endif
652
#endif
653
5.21k
        for (size_t i = 0; i < size; ++i) {
654
            if constexpr (is_and) {
655
                lhs[i] &= rhs[i];
656
5.01k
            } else {
657
                // Logical OR must produce a canonical Boolean instead of preserving input bits.
658
5.01k
                lhs[i] = (lhs[i] | rhs[i]) != 0;
659
5.01k
            }
660
5.01k
        }
661
204
    }
662
663
    template <bool is_and>
664
    void static do_null_pred(const uint8_t* __restrict lhs_data, const uint8_t* __restrict lhs_null,
665
                             const uint8_t* __restrict rhs_data, const uint8_t* __restrict rhs_null,
666
                             uint8_t* __restrict res_data, uint8_t* __restrict res_null,
667
3.08k
                             size_t size) {
668
#ifdef NDEBUG
669
#if defined(__clang__)
670
#pragma clang loop vectorize(enable)
671
#elif defined(__GNUC__) && (__GNUC__ >= 5)
672
#pragma GCC ivdep
673
#endif
674
#endif
675
888k
        for (size_t i = 0; i < size; ++i) {
676
885k
            if constexpr (is_and) {
677
8.28k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
678
8.28k
                res_data[i] = lhs_data[i] & rhs_data[i];
679
877k
            } else {
680
877k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
681
                // A NULL row may carry an arbitrary nested byte. If the result remains NULL the
682
                // byte is ignored; otherwise normalization prevents it from becoming visible.
683
877k
                res_data[i] = (lhs_data[i] | rhs_data[i]) != 0;
684
877k
            }
685
885k
        }
686
3.08k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
667
816
                             size_t size) {
668
#ifdef NDEBUG
669
#if defined(__clang__)
670
#pragma clang loop vectorize(enable)
671
#elif defined(__GNUC__) && (__GNUC__ >= 5)
672
#pragma GCC ivdep
673
#endif
674
#endif
675
9.10k
        for (size_t i = 0; i < size; ++i) {
676
8.28k
            if constexpr (is_and) {
677
8.28k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
678
8.28k
                res_data[i] = lhs_data[i] & rhs_data[i];
679
            } else {
680
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
681
                // A NULL row may carry an arbitrary nested byte. If the result remains NULL the
682
                // byte is ignored; otherwise normalization prevents it from becoming visible.
683
                res_data[i] = (lhs_data[i] | rhs_data[i]) != 0;
684
            }
685
8.28k
        }
686
816
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
667
2.27k
                             size_t size) {
668
#ifdef NDEBUG
669
#if defined(__clang__)
670
#pragma clang loop vectorize(enable)
671
#elif defined(__GNUC__) && (__GNUC__ >= 5)
672
#pragma GCC ivdep
673
#endif
674
#endif
675
879k
        for (size_t i = 0; i < size; ++i) {
676
            if constexpr (is_and) {
677
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
678
                res_data[i] = lhs_data[i] & rhs_data[i];
679
877k
            } else {
680
877k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
681
                // A NULL row may carry an arbitrary nested byte. If the result remains NULL the
682
                // byte is ignored; otherwise normalization prevents it from becoming visible.
683
877k
                res_data[i] = (lhs_data[i] | rhs_data[i]) != 0;
684
877k
            }
685
877k
        }
686
2.27k
    }
687
688
22.5k
    bool _has_const_child() const {
689
22.5k
        return std::ranges::any_of(_children,
690
44.8k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
691
22.5k
    }
692
693
    std::pair<const uint8_t*, const uint8_t*> _get_raw_data_and_null_map(
694
38.5k
            const ColumnPtr& column, bool has_nullable_column) const {
695
38.5k
        if (has_nullable_column) {
696
22.5k
            const auto* nullable_column = assert_cast<const ColumnNullable*>(column.get());
697
22.5k
            auto* data_column =
698
22.5k
                    assert_cast<const ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
699
22.5k
                            ->get_data()
700
22.5k
                            .data();
701
22.5k
            auto* null_map = nullable_column->get_null_map_column_ptr()->get_data().data();
702
22.5k
            return std::make_pair(data_column, null_map);
703
22.5k
        } else {
704
16.0k
            auto* data_column = assert_cast<const ColumnUInt8*>(column.get())->get_data().data();
705
16.0k
            return std::make_pair(data_column, nullptr);
706
16.0k
        }
707
38.5k
    }
708
709
    TExprOpcode::type _op;
710
};
711
712
} // namespace doris