Coverage Report

Created: 2026-07-06 08:54

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
24
#include "common/logging.h"
25
#include "common/status.h"
26
#include "core/assert_cast.h"
27
#include "core/column/column.h"
28
#include "core/column/column_nullable.h"
29
#include "exprs/vectorized_fn_call.h"
30
#include "exprs/vexpr_context.h"
31
#include "exprs/vexpr_fwd.h"
32
#include "storage/index/zone_map/zonemap_eval_context.h"
33
#include "util/simd/bits.h"
34
35
namespace doris {
36
37
5.74k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
38
5.74k
    if (op == TExprOpcode::COMPOUND_AND) {
39
1.02k
        return "and";
40
4.72k
    } else if (op == TExprOpcode::COMPOUND_OR) {
41
4.24k
        return "or";
42
4.24k
    } else {
43
476
        return "not";
44
476
    }
45
5.74k
}
46
47
class VCompoundPred : public VectorizedFnCall {
48
    ENABLE_FACTORY_CREATOR(VCompoundPred);
49
50
public:
51
5.74k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
52
5.74k
        _op = node.opcode;
53
5.74k
        _fn.name.function_name = compound_operator_to_string(_op);
54
5.74k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
55
5.74k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
56
5.74k
    }
57
58
#ifdef BE_TEST
59
    VCompoundPred() = default;
60
#endif
61
62
12.8k
    const std::string& expr_name() const override { return _expr_name; }
63
398
    Status clone_node(VExprSPtr* cloned_expr) const override {
64
398
        DORIS_CHECK(cloned_expr != nullptr);
65
398
        *cloned_expr = VCompoundPred::create_shared(clone_texpr_node());
66
398
        return Status::OK();
67
398
    }
68
69
14.5k
    bool can_evaluate_zonemap_filter() const override {
70
14.5k
        switch (_op) {
71
2.86k
        case TExprOpcode::COMPOUND_AND:
72
3.38k
            return std::ranges::any_of(_children, [](const VExprSPtr& child) {
73
3.38k
                return child->can_evaluate_zonemap_filter();
74
3.38k
            });
75
9.02k
        case TExprOpcode::COMPOUND_OR:
76
14.8k
            return !_children.empty() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
77
14.8k
                return child->can_evaluate_zonemap_filter();
78
14.8k
            });
79
2.69k
        case TExprOpcode::COMPOUND_NOT:
80
2.69k
            return false;
81
0
        default:
82
0
            return false;
83
14.5k
        }
84
14.5k
    }
85
86
2.67k
    ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const override {
87
2.67k
        switch (_op) {
88
377
        case TExprOpcode::COMPOUND_AND: {
89
682
            for (const auto& child : _children) {
90
682
                if (!child->can_evaluate_zonemap_filter()) {
91
58
                    continue;
92
58
                }
93
624
                if (child->evaluate_zonemap_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
94
135
                    return ZoneMapFilterResult::kNoMatch;
95
135
                }
96
624
            }
97
242
            return ZoneMapFilterResult::kMayMatch;
98
377
        }
99
2.29k
        case TExprOpcode::COMPOUND_OR: {
100
3.88k
            for (const auto& child : _children) {
101
3.88k
                DORIS_CHECK(child->can_evaluate_zonemap_filter());
102
3.88k
                if (child->evaluate_zonemap_filter(ctx) != ZoneMapFilterResult::kNoMatch) {
103
1.94k
                    return ZoneMapFilterResult::kMayMatch;
104
1.94k
                }
105
3.88k
            }
106
352
            return ZoneMapFilterResult::kNoMatch;
107
2.29k
        }
108
1
        case TExprOpcode::COMPOUND_NOT:
109
1
            return unsupported_zonemap_filter(ctx);
110
0
        default:
111
0
            return unsupported_zonemap_filter(ctx);
112
2.67k
        }
113
2.67k
    }
114
115
4.91k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
116
4.91k
        segment_v2::InvertedIndexResultBitmap res;
117
4.91k
        bool all_pass = true;
118
119
4.91k
        switch (_op) {
120
3.00k
        case TExprOpcode::COMPOUND_OR: {
121
5.80k
            for (const auto& child : _children) {
122
5.80k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
123
5.80k
                    !st.ok()) {
124
176
                    LOG(ERROR) << "expr:" << child->expr_name()
125
176
                               << " evaluate_inverted_index error:" << st.to_string();
126
176
                    all_pass = false;
127
176
                    continue;
128
176
                }
129
5.62k
                auto inverted_index_context = context->get_index_context();
130
5.62k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
131
2.95k
                    const auto* index_result =
132
2.95k
                            inverted_index_context->get_index_result_for_expr(child.get());
133
2.95k
                    if (res.is_empty()) {
134
1.97k
                        res = *index_result;
135
1.97k
                    } else {
136
984
                        res |= *index_result;
137
984
                    }
138
2.95k
                    if (inverted_index_context->get_score_runtime() == nullptr) {
139
2.95k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
140
346
                            break; // Early exit if result is full
141
346
                        }
142
2.95k
                    }
143
2.95k
                } else {
144
2.66k
                    all_pass = false;
145
2.66k
                }
146
5.62k
            }
147
3.00k
            break;
148
0
        }
149
5.28k
        case TExprOpcode::COMPOUND_AND: {
150
1.50k
            for (const auto& child : _children) {
151
1.50k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
152
1.50k
                    !st.ok()) {
153
27
                    LOG(ERROR) << "expr:" << child->expr_name()
154
27
                               << " evaluate_inverted_index error:" << st.to_string();
155
27
                    all_pass = false;
156
27
                    continue;
157
27
                }
158
1.48k
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
159
214
                    const auto* index_result =
160
214
                            context->get_index_context()->get_index_result_for_expr(child.get());
161
214
                    if (res.is_empty()) {
162
156
                        res = *index_result;
163
156
                    } else {
164
58
                        res &= *index_result;
165
58
                    }
166
167
214
                    if (res.get_data_bitmap()->isEmpty()) {
168
78
                        break; // Early exit if result is empty
169
78
                    }
170
1.26k
                } else {
171
1.26k
                    all_pass = false;
172
1.26k
                }
173
1.48k
            }
174
789
            break;
175
0
        }
176
1.40k
        case TExprOpcode::COMPOUND_NOT: {
177
1.12k
            const auto& child = _children[0];
178
1.12k
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
179
1.12k
            if (!st.ok()) {
180
40
                LOG(ERROR) << "expr:" << child->expr_name()
181
40
                           << " evaluate_inverted_index error:" << st.to_string();
182
40
                return st;
183
40
            }
184
185
1.08k
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
186
617
                const auto* index_result =
187
617
                        context->get_index_context()->get_index_result_for_expr(child.get());
188
617
                roaring::Roaring full_result;
189
617
                full_result.addRange(0, segment_num_rows);
190
617
                res = index_result->op_not(&full_result);
191
617
            } else {
192
467
                all_pass = false;
193
467
            }
194
1.08k
            break;
195
1.12k
        }
196
0
        default:
197
0
            return Status::NotSupported(
198
0
                    "Compound operator must be AND, OR, or NOT to execute with inverted index.");
199
4.91k
        }
200
201
4.90k
        if (all_pass && !res.is_empty()) {
202
1.95k
            context->get_index_context()->set_index_result_for_expr(this, res);
203
1.95k
        }
204
4.90k
        return Status::OK();
205
4.91k
    }
206
207
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
208
60.4k
                               size_t count, ColumnPtr& result_column) const override {
209
60.4k
        if (fast_execute(context, selector, count, result_column)) {
210
71
            return Status::OK();
211
71
        }
212
60.4k
        if (get_num_children() == 1 || _has_const_child()) {
213
1.01k
            return VectorizedFnCall::execute_column_impl(context, block, selector, count,
214
1.01k
                                                         result_column);
215
1.01k
        }
216
217
59.3k
        ColumnPtr lhs_column;
218
59.3k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
219
59.3k
        lhs_column = lhs_column->convert_to_full_column_if_const();
220
59.3k
        size_t size = lhs_column->size();
221
222
59.3k
        bool lhs_is_nullable = lhs_column->is_nullable();
223
59.3k
        auto [lhs_data_column, lhs_null_map] =
224
59.3k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
225
59.3k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
226
59.3k
        bool lhs_all_true = (filted == 0);
227
59.3k
        bool lhs_all_false = (filted == size);
228
229
59.3k
        bool lhs_all_is_not_null = false;
230
59.3k
        if (lhs_is_nullable) {
231
48.2k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
232
48.2k
            lhs_all_is_not_null = (filted == size);
233
48.2k
        }
234
235
59.3k
        ColumnPtr rhs_column = nullptr;
236
59.3k
        const uint8_t* __restrict rhs_data_column = nullptr;
237
59.3k
        const uint8_t* __restrict rhs_null_map = nullptr;
238
59.3k
        bool rhs_is_nullable = false;
239
59.3k
        bool rhs_all_true = false;
240
59.3k
        bool rhs_all_false = false;
241
59.3k
        bool rhs_all_is_not_null = false;
242
59.3k
        bool result_is_nullable = _data_type->is_nullable();
243
244
59.3k
        auto get_rhs_colum = [&]() {
245
37.9k
            if (!rhs_column) {
246
37.9k
                RETURN_IF_ERROR(
247
37.9k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
248
37.9k
                rhs_column = rhs_column->convert_to_full_column_if_const();
249
37.9k
                rhs_is_nullable = rhs_column->is_nullable();
250
37.9k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
251
37.9k
                rhs_data_column = rhs_nullable_column.first;
252
37.9k
                rhs_null_map = rhs_nullable_column.second;
253
37.9k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
254
37.9k
                rhs_all_true = (filted == 0);
255
37.9k
                rhs_all_false = (filted == size);
256
37.9k
                if (rhs_is_nullable) {
257
30.6k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
258
30.6k
                    rhs_all_is_not_null = (filted == size);
259
30.6k
                }
260
37.9k
            }
261
37.9k
            return Status::OK();
262
37.9k
        };
263
264
59.3k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
265
52.6k
            result_column = std::move(*arg_column).mutate();
266
52.6k
            if (result_is_nullable && !result_column->is_nullable()) {
267
2.38k
                result_column = make_nullable(result_column);
268
2.38k
            }
269
52.6k
        };
270
271
59.3k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
272
59.3k
                                          const uint8_t* __restrict null_map_data) {
273
12.2k
            if (null_map_data == nullptr) {
274
680
                null_map_column = ColumnUInt8::create(size, 0);
275
680
                null_map_data =
276
680
                        assert_cast<const ColumnUInt8*>(null_map_column.get())->get_data().data();
277
680
            }
278
12.2k
            return null_map_data;
279
12.2k
        };
280
281
59.3k
        auto vector_vector = [&]<bool is_and_op>() {
282
546
            MutableColumnPtr mutable_result_column;
283
546
            uint8_t* __restrict result_data_column = nullptr;
284
546
            const uint8_t* __restrict other_data_column = rhs_data_column;
285
546
            if (lhs_column->use_count() == 1) {
286
545
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
287
545
                result_data_column =
288
545
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
289
545
            } else if (rhs_column->use_count() == 1) {
290
1
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
291
1
                result_data_column =
292
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
293
1
                other_data_column = lhs_data_column;
294
1
            } else {
295
0
                mutable_result_column = lhs_column->clone_resized(size);
296
0
                result_data_column =
297
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
298
0
            }
299
300
546
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
301
546
            result_column = std::move(mutable_result_column);
302
546
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb1EEEDav
Line
Count
Source
281
429
        auto vector_vector = [&]<bool is_and_op>() {
282
429
            MutableColumnPtr mutable_result_column;
283
429
            uint8_t* __restrict result_data_column = nullptr;
284
429
            const uint8_t* __restrict other_data_column = rhs_data_column;
285
432
            if (lhs_column->use_count() == 1) {
286
432
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
287
432
                result_data_column =
288
432
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
289
18.4E
            } else if (rhs_column->use_count() == 1) {
290
0
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
291
0
                result_data_column =
292
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
293
0
                other_data_column = lhs_data_column;
294
18.4E
            } else {
295
18.4E
                mutable_result_column = lhs_column->clone_resized(size);
296
18.4E
                result_data_column =
297
18.4E
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
298
18.4E
            }
299
300
429
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
301
429
            result_column = std::move(mutable_result_column);
302
429
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb0EEEDav
Line
Count
Source
281
117
        auto vector_vector = [&]<bool is_and_op>() {
282
117
            MutableColumnPtr mutable_result_column;
283
117
            uint8_t* __restrict result_data_column = nullptr;
284
117
            const uint8_t* __restrict other_data_column = rhs_data_column;
285
117
            if (lhs_column->use_count() == 1) {
286
113
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
287
113
                result_data_column =
288
113
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
289
113
            } else if (rhs_column->use_count() == 1) {
290
1
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
291
1
                result_data_column =
292
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
293
1
                other_data_column = lhs_data_column;
294
3
            } else {
295
3
                mutable_result_column = lhs_column->clone_resized(size);
296
3
                result_data_column =
297
3
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
298
3
            }
299
300
117
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
301
117
            result_column = std::move(mutable_result_column);
302
117
        };
303
59.3k
        auto vector_vector_null = [&]<bool is_and_op>() {
304
6.11k
            auto col_res = ColumnUInt8::create(size);
305
6.11k
            auto col_nulls = ColumnUInt8::create(size);
306
307
6.11k
            auto* __restrict res_datas = col_res->get_data().data();
308
6.11k
            auto* __restrict res_nulls = col_nulls->get_data().data();
309
6.11k
            ColumnPtr temp_null_map = nullptr;
310
            // maybe both children are nullable / or one of children is nullable
311
6.11k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
312
6.11k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
313
6.11k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
314
6.11k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
315
316
6.11k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
317
6.11k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
318
319
6.11k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
320
6.11k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
303
2.95k
        auto vector_vector_null = [&]<bool is_and_op>() {
304
2.95k
            auto col_res = ColumnUInt8::create(size);
305
2.95k
            auto col_nulls = ColumnUInt8::create(size);
306
307
2.95k
            auto* __restrict res_datas = col_res->get_data().data();
308
2.95k
            auto* __restrict res_nulls = col_nulls->get_data().data();
309
2.95k
            ColumnPtr temp_null_map = nullptr;
310
            // maybe both children are nullable / or one of children is nullable
311
2.95k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
312
2.95k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
313
2.95k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
314
2.95k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
315
316
2.95k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
317
2.95k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
318
319
2.95k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
320
2.95k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
303
3.16k
        auto vector_vector_null = [&]<bool is_and_op>() {
304
3.16k
            auto col_res = ColumnUInt8::create(size);
305
3.16k
            auto col_nulls = ColumnUInt8::create(size);
306
307
3.16k
            auto* __restrict res_datas = col_res->get_data().data();
308
3.16k
            auto* __restrict res_nulls = col_nulls->get_data().data();
309
3.16k
            ColumnPtr temp_null_map = nullptr;
310
            // maybe both children are nullable / or one of children is nullable
311
3.16k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
312
3.16k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
313
3.16k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
314
3.16k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
315
316
3.16k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
317
3.16k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
318
319
3.16k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
320
3.16k
        };
321
322
        // false and NULL ----> 0
323
        // true  and NULL ----> NULL
324
59.3k
        if (_op == TExprOpcode::COMPOUND_AND) {
325
            //1. not null column: all data is false
326
            //2. nullable column: null map all is not null
327
26.0k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
328
                // false and any = false, return lhs
329
18.1k
                return_result_column_id(lhs_column);
330
18.1k
            } else {
331
7.82k
                RETURN_IF_ERROR(get_rhs_colum());
332
333
7.82k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
334
7.82k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
335
                                                             // true and any = any, return rhs
336
337
1.17k
                    return_result_column_id(rhs_column);
338
6.64k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
339
6.64k
                           (rhs_all_false && rhs_all_is_not_null)) {
340
                    // any and false = false, return rhs
341
838
                    return_result_column_id(rhs_column);
342
5.80k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
343
5.80k
                           (rhs_all_true && rhs_all_is_not_null)) {
344
                    // any and true = any, return lhs
345
2.43k
                    return_result_column_id(lhs_column);
346
3.37k
                } else {
347
3.37k
                    if (!result_is_nullable) {
348
431
                        vector_vector.template operator()<true>();
349
2.94k
                    } else {
350
2.94k
                        vector_vector_null.template operator()<true>();
351
2.94k
                    }
352
3.37k
                }
353
7.82k
            }
354
33.3k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
355
            // true  or NULL ----> 1
356
            // false or NULL ----> NULL
357
33.3k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
358
                // true or any = true, return lhs
359
3.20k
                return_result_column_id(lhs_column);
360
30.1k
            } else {
361
30.1k
                RETURN_IF_ERROR(get_rhs_colum());
362
30.1k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
363
                    // false or any = any, return rhs
364
23.8k
                    return_result_column_id(rhs_column);
365
23.8k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
366
6.27k
                           (rhs_all_true && rhs_all_is_not_null)) {
367
                    // any or true = true, return rhs
368
722
                    return_result_column_id(rhs_column);
369
5.55k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
370
5.55k
                           (rhs_all_false && rhs_all_is_not_null)) {
371
                    // any or false = any, return lhs
372
2.27k
                    return_result_column_id(lhs_column);
373
3.27k
                } else {
374
3.27k
                    if (!result_is_nullable) {
375
117
                        vector_vector.template operator()<false>();
376
3.16k
                    } else {
377
3.16k
                        vector_vector_null.template operator()<false>();
378
3.16k
                    }
379
3.27k
                }
380
30.1k
            }
381
33.3k
        } else {
382
13
            return Status::InternalError("Compound operator must be AND or OR.");
383
13
        }
384
385
59.3k
        DCHECK_EQ(result_column->size(), count);
386
59.3k
        return Status::OK();
387
59.3k
    }
388
389
904
    double execute_cost() const override {
390
904
        double cost = 0.3;
391
1.44k
        for (const auto& child : _children) {
392
1.44k
            cost += child->execute_cost();
393
1.44k
        }
394
904
        return cost;
395
904
    }
396
397
private:
398
89.2k
    static inline constexpr uint8_t apply_and_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
399
        // (<> && false) is false, (true && NULL) is NULL
400
89.2k
        return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b));
401
89.2k
    }
402
295k
    static inline constexpr uint8_t apply_or_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
403
        // (<> || true) is true, (false || NULL) is NULL
404
295k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
405
295k
    }
406
407
    template <bool is_and>
408
    void static do_not_null_pred(uint8_t* __restrict lhs, const uint8_t* __restrict rhs,
409
547
                                 size_t size) {
410
#ifdef NDEBUG
411
#if defined(__clang__)
412
#pragma clang loop vectorize(enable)
413
#elif defined(__GNUC__) && (__GNUC__ >= 5)
414
#pragma GCC ivdep
415
#endif
416
#endif
417
41.8k
        for (size_t i = 0; i < size; ++i) {
418
41.2k
            if constexpr (is_and) {
419
37.5k
                lhs[i] &= rhs[i];
420
37.5k
            } else {
421
3.70k
                lhs[i] |= rhs[i];
422
3.70k
            }
423
41.2k
        }
424
547
    }
_ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhPKhm
Line
Count
Source
409
430
                                 size_t size) {
410
#ifdef NDEBUG
411
#if defined(__clang__)
412
#pragma clang loop vectorize(enable)
413
#elif defined(__GNUC__) && (__GNUC__ >= 5)
414
#pragma GCC ivdep
415
#endif
416
#endif
417
37.9k
        for (size_t i = 0; i < size; ++i) {
418
37.5k
            if constexpr (is_and) {
419
37.5k
                lhs[i] &= rhs[i];
420
            } else {
421
                lhs[i] |= rhs[i];
422
            }
423
37.5k
        }
424
430
    }
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhPKhm
Line
Count
Source
409
117
                                 size_t size) {
410
#ifdef NDEBUG
411
#if defined(__clang__)
412
#pragma clang loop vectorize(enable)
413
#elif defined(__GNUC__) && (__GNUC__ >= 5)
414
#pragma GCC ivdep
415
#endif
416
#endif
417
3.82k
        for (size_t i = 0; i < size; ++i) {
418
            if constexpr (is_and) {
419
                lhs[i] &= rhs[i];
420
3.70k
            } else {
421
3.70k
                lhs[i] |= rhs[i];
422
3.70k
            }
423
3.70k
        }
424
117
    }
425
426
    template <bool is_and>
427
    void static do_null_pred(const uint8_t* __restrict lhs_data, const uint8_t* __restrict lhs_null,
428
                             const uint8_t* __restrict rhs_data, const uint8_t* __restrict rhs_null,
429
                             uint8_t* __restrict res_data, uint8_t* __restrict res_null,
430
6.11k
                             size_t size) {
431
#ifdef NDEBUG
432
#if defined(__clang__)
433
#pragma clang loop vectorize(enable)
434
#elif defined(__GNUC__) && (__GNUC__ >= 5)
435
#pragma GCC ivdep
436
#endif
437
#endif
438
390k
        for (size_t i = 0; i < size; ++i) {
439
384k
            if constexpr (is_and) {
440
89.2k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
441
89.2k
                res_data[i] = lhs_data[i] & rhs_data[i];
442
295k
            } else {
443
295k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
444
295k
                res_data[i] = lhs_data[i] | rhs_data[i];
445
295k
            }
446
384k
        }
447
6.11k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
430
2.95k
                             size_t size) {
431
#ifdef NDEBUG
432
#if defined(__clang__)
433
#pragma clang loop vectorize(enable)
434
#elif defined(__GNUC__) && (__GNUC__ >= 5)
435
#pragma GCC ivdep
436
#endif
437
#endif
438
92.2k
        for (size_t i = 0; i < size; ++i) {
439
89.2k
            if constexpr (is_and) {
440
89.2k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
441
89.2k
                res_data[i] = lhs_data[i] & rhs_data[i];
442
            } else {
443
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
444
                res_data[i] = lhs_data[i] | rhs_data[i];
445
            }
446
89.2k
        }
447
2.95k
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
430
3.16k
                             size_t size) {
431
#ifdef NDEBUG
432
#if defined(__clang__)
433
#pragma clang loop vectorize(enable)
434
#elif defined(__GNUC__) && (__GNUC__ >= 5)
435
#pragma GCC ivdep
436
#endif
437
#endif
438
298k
        for (size_t i = 0; i < size; ++i) {
439
            if constexpr (is_and) {
440
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
441
                res_data[i] = lhs_data[i] & rhs_data[i];
442
295k
            } else {
443
295k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
444
295k
                res_data[i] = lhs_data[i] | rhs_data[i];
445
295k
            }
446
295k
        }
447
3.16k
    }
448
449
59.4k
    bool _has_const_child() const {
450
59.4k
        return std::ranges::any_of(_children,
451
118k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
452
59.4k
    }
453
454
    std::pair<const uint8_t*, const uint8_t*> _get_raw_data_and_null_map(
455
97.3k
            const ColumnPtr& column, bool has_nullable_column) const {
456
97.3k
        if (has_nullable_column) {
457
78.8k
            const auto* nullable_column = assert_cast<const ColumnNullable*>(column.get());
458
78.8k
            auto* data_column =
459
78.8k
                    assert_cast<const ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
460
78.8k
                            ->get_data()
461
78.8k
                            .data();
462
78.8k
            auto* null_map = nullable_column->get_null_map_column_ptr()->get_data().data();
463
78.8k
            return std::make_pair(data_column, null_map);
464
78.8k
        } else {
465
18.4k
            auto* data_column = assert_cast<const ColumnUInt8*>(column.get())->get_data().data();
466
18.4k
            return std::make_pair(data_column, nullptr);
467
18.4k
        }
468
97.3k
    }
469
470
    TExprOpcode::type _op;
471
};
472
473
} // namespace doris