Coverage Report

Created: 2026-07-01 15:58

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
4.77k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
38
4.77k
    if (op == TExprOpcode::COMPOUND_AND) {
39
899
        return "and";
40
3.87k
    } else if (op == TExprOpcode::COMPOUND_OR) {
41
3.37k
        return "or";
42
3.37k
    } else {
43
496
        return "not";
44
496
    }
45
4.77k
}
46
47
class VCompoundPred : public VectorizedFnCall {
48
    ENABLE_FACTORY_CREATOR(VCompoundPred);
49
50
public:
51
4.77k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
52
4.77k
        _op = node.opcode;
53
4.77k
        _fn.name.function_name = compound_operator_to_string(_op);
54
4.77k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
55
4.77k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
56
4.77k
    }
57
58
#ifdef BE_TEST
59
    VCompoundPred() = default;
60
#endif
61
62
11.0k
    const std::string& expr_name() const override { return _expr_name; }
63
64
14.1k
    bool can_evaluate_zonemap_filter() const override {
65
14.1k
        switch (_op) {
66
2.42k
        case TExprOpcode::COMPOUND_AND:
67
2.95k
            return std::ranges::any_of(_children, [](const VExprSPtr& child) {
68
2.95k
                return child->can_evaluate_zonemap_filter();
69
2.95k
            });
70
8.97k
        case TExprOpcode::COMPOUND_OR:
71
14.7k
            return !_children.empty() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
72
14.7k
                return child->can_evaluate_zonemap_filter();
73
14.7k
            });
74
2.68k
        case TExprOpcode::COMPOUND_NOT:
75
2.68k
            return false;
76
0
        default:
77
0
            return false;
78
14.1k
        }
79
14.1k
    }
80
81
2.59k
    ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const override {
82
2.59k
        switch (_op) {
83
337
        case TExprOpcode::COMPOUND_AND: {
84
600
            for (const auto& child : _children) {
85
600
                if (!child->can_evaluate_zonemap_filter()) {
86
57
                    continue;
87
57
                }
88
543
                if (child->evaluate_zonemap_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
89
125
                    return ZoneMapFilterResult::kNoMatch;
90
125
                }
91
543
            }
92
212
            return ZoneMapFilterResult::kMayMatch;
93
337
        }
94
2.25k
        case TExprOpcode::COMPOUND_OR: {
95
3.80k
            for (const auto& child : _children) {
96
3.80k
                DORIS_CHECK(child->can_evaluate_zonemap_filter());
97
3.80k
                if (child->evaluate_zonemap_filter(ctx) != ZoneMapFilterResult::kNoMatch) {
98
1.90k
                    return ZoneMapFilterResult::kMayMatch;
99
1.90k
                }
100
3.80k
            }
101
347
            return ZoneMapFilterResult::kNoMatch;
102
2.25k
        }
103
1
        case TExprOpcode::COMPOUND_NOT:
104
1
            return unsupported_zonemap_filter(ctx);
105
0
        default:
106
0
            return unsupported_zonemap_filter(ctx);
107
2.59k
        }
108
2.59k
    }
109
110
4.80k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
111
4.80k
        segment_v2::InvertedIndexResultBitmap res;
112
4.80k
        bool all_pass = true;
113
114
4.80k
        switch (_op) {
115
2.98k
        case TExprOpcode::COMPOUND_OR: {
116
5.77k
            for (const auto& child : _children) {
117
5.77k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
118
5.77k
                    !st.ok()) {
119
177
                    LOG(ERROR) << "expr:" << child->expr_name()
120
177
                               << " evaluate_inverted_index error:" << st.to_string();
121
177
                    all_pass = false;
122
177
                    continue;
123
177
                }
124
5.59k
                auto inverted_index_context = context->get_index_context();
125
5.59k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
126
2.96k
                    const auto* index_result =
127
2.96k
                            inverted_index_context->get_index_result_for_expr(child.get());
128
2.96k
                    if (res.is_empty()) {
129
1.98k
                        res = *index_result;
130
1.98k
                    } else {
131
976
                        res |= *index_result;
132
976
                    }
133
2.96k
                    if (inverted_index_context->get_score_runtime() == nullptr) {
134
2.96k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
135
334
                            break; // Early exit if result is full
136
334
                        }
137
2.96k
                    }
138
2.96k
                } else {
139
2.62k
                    all_pass = false;
140
2.62k
                }
141
5.59k
            }
142
2.98k
            break;
143
0
        }
144
5.25k
        case TExprOpcode::COMPOUND_AND: {
145
1.31k
            for (const auto& child : _children) {
146
1.31k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
147
1.31k
                    !st.ok()) {
148
27
                    LOG(ERROR) << "expr:" << child->expr_name()
149
27
                               << " evaluate_inverted_index error:" << st.to_string();
150
27
                    all_pass = false;
151
27
                    continue;
152
27
                }
153
1.28k
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
154
215
                    const auto* index_result =
155
215
                            context->get_index_context()->get_index_result_for_expr(child.get());
156
215
                    if (res.is_empty()) {
157
158
                        res = *index_result;
158
158
                    } else {
159
57
                        res &= *index_result;
160
57
                    }
161
162
215
                    if (res.get_data_bitmap()->isEmpty()) {
163
74
                        break; // Early exit if result is empty
164
74
                    }
165
1.06k
                } else {
166
1.06k
                    all_pass = false;
167
1.06k
                }
168
1.28k
            }
169
690
            break;
170
0
        }
171
1.20k
        case TExprOpcode::COMPOUND_NOT: {
172
1.12k
            const auto& child = _children[0];
173
1.12k
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
174
1.12k
            if (!st.ok()) {
175
40
                LOG(ERROR) << "expr:" << child->expr_name()
176
40
                           << " evaluate_inverted_index error:" << st.to_string();
177
40
                return st;
178
40
            }
179
180
1.08k
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
181
640
                const auto* index_result =
182
640
                        context->get_index_context()->get_index_result_for_expr(child.get());
183
640
                roaring::Roaring full_result;
184
640
                full_result.addRange(0, segment_num_rows);
185
640
                res = index_result->op_not(&full_result);
186
640
            } else {
187
443
                all_pass = false;
188
443
            }
189
1.08k
            break;
190
1.12k
        }
191
0
        default:
192
0
            return Status::NotSupported(
193
0
                    "Compound operator must be AND, OR, or NOT to execute with inverted index.");
194
4.80k
        }
195
196
4.77k
        if (all_pass && !res.is_empty()) {
197
1.96k
            context->get_index_context()->set_index_result_for_expr(this, res);
198
1.96k
        }
199
4.77k
        return Status::OK();
200
4.80k
    }
201
202
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
203
18.3k
                               size_t count, ColumnPtr& result_column) const override {
204
18.3k
        if (fast_execute(context, selector, count, result_column)) {
205
74
            return Status::OK();
206
74
        }
207
18.3k
        if (get_num_children() == 1 || _has_const_child()) {
208
974
            return VectorizedFnCall::execute_column_impl(context, block, selector, count,
209
974
                                                         result_column);
210
974
        }
211
212
17.3k
        ColumnPtr lhs_column;
213
17.3k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
214
17.3k
        lhs_column = lhs_column->convert_to_full_column_if_const();
215
17.3k
        size_t size = lhs_column->size();
216
217
17.3k
        bool lhs_is_nullable = lhs_column->is_nullable();
218
17.3k
        auto [lhs_data_column, lhs_null_map] =
219
17.3k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
220
17.3k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
221
17.3k
        bool lhs_all_true = (filted == 0);
222
17.3k
        bool lhs_all_false = (filted == size);
223
224
17.3k
        bool lhs_all_is_not_null = false;
225
17.3k
        if (lhs_is_nullable) {
226
8.86k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
227
8.86k
            lhs_all_is_not_null = (filted == size);
228
8.86k
        }
229
230
17.3k
        ColumnPtr rhs_column = nullptr;
231
17.3k
        const uint8_t* __restrict rhs_data_column = nullptr;
232
17.3k
        const uint8_t* __restrict rhs_null_map = nullptr;
233
17.3k
        bool rhs_is_nullable = false;
234
17.3k
        bool rhs_all_true = false;
235
17.3k
        bool rhs_all_false = false;
236
17.3k
        bool rhs_all_is_not_null = false;
237
17.3k
        bool result_is_nullable = _data_type->is_nullable();
238
239
17.3k
        auto get_rhs_colum = [&]() {
240
13.0k
            if (!rhs_column) {
241
13.0k
                RETURN_IF_ERROR(
242
13.0k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
243
13.0k
                rhs_column = rhs_column->convert_to_full_column_if_const();
244
13.0k
                rhs_is_nullable = rhs_column->is_nullable();
245
13.0k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
246
13.0k
                rhs_data_column = rhs_nullable_column.first;
247
13.0k
                rhs_null_map = rhs_nullable_column.second;
248
13.0k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
249
13.0k
                rhs_all_true = (filted == 0);
250
13.0k
                rhs_all_false = (filted == size);
251
13.0k
                if (rhs_is_nullable) {
252
8.49k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
253
8.49k
                    rhs_all_is_not_null = (filted == size);
254
8.49k
                }
255
13.0k
            }
256
13.0k
            return Status::OK();
257
13.0k
        };
258
259
17.3k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
260
14.7k
            result_column = std::move(*arg_column).mutate();
261
14.7k
            if (result_is_nullable && !result_column->is_nullable()) {
262
1.42k
                result_column = make_nullable(result_column);
263
1.42k
            }
264
14.7k
        };
265
266
17.3k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
267
17.3k
                                          const uint8_t* __restrict null_map_data) {
268
4.13k
            if (null_map_data == nullptr) {
269
457
                null_map_column = ColumnUInt8::create(size, 0);
270
457
                null_map_data =
271
457
                        assert_cast<const ColumnUInt8*>(null_map_column.get())->get_data().data();
272
457
            }
273
4.13k
            return null_map_data;
274
4.13k
        };
275
276
17.3k
        auto vector_vector = [&]<bool is_and_op>() {
277
481
            MutableColumnPtr mutable_result_column;
278
481
            uint8_t* __restrict result_data_column = nullptr;
279
481
            const uint8_t* __restrict other_data_column = rhs_data_column;
280
481
            if (lhs_column->use_count() == 1) {
281
479
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
282
479
                result_data_column =
283
479
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
284
479
            } else if (rhs_column->use_count() == 1) {
285
1
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
286
1
                result_data_column =
287
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
288
1
                other_data_column = lhs_data_column;
289
1
            } else {
290
1
                mutable_result_column = lhs_column->clone_resized(size);
291
1
                result_data_column =
292
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
293
1
            }
294
295
481
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
296
481
            result_column = std::move(mutable_result_column);
297
481
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb1EEEDav
Line
Count
Source
276
376
        auto vector_vector = [&]<bool is_and_op>() {
277
376
            MutableColumnPtr mutable_result_column;
278
376
            uint8_t* __restrict result_data_column = nullptr;
279
376
            const uint8_t* __restrict other_data_column = rhs_data_column;
280
376
            if (lhs_column->use_count() == 1) {
281
376
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
282
376
                result_data_column =
283
376
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
284
376
            } else if (rhs_column->use_count() == 1) {
285
0
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
286
0
                result_data_column =
287
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
288
0
                other_data_column = lhs_data_column;
289
0
            } else {
290
0
                mutable_result_column = lhs_column->clone_resized(size);
291
0
                result_data_column =
292
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
293
0
            }
294
295
376
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
296
376
            result_column = std::move(mutable_result_column);
297
376
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb0EEEDav
Line
Count
Source
276
105
        auto vector_vector = [&]<bool is_and_op>() {
277
105
            MutableColumnPtr mutable_result_column;
278
105
            uint8_t* __restrict result_data_column = nullptr;
279
105
            const uint8_t* __restrict other_data_column = rhs_data_column;
280
105
            if (lhs_column->use_count() == 1) {
281
103
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
282
103
                result_data_column =
283
103
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
284
103
            } else if (rhs_column->use_count() == 1) {
285
1
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
286
1
                result_data_column =
287
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
288
1
                other_data_column = lhs_data_column;
289
1
            } else {
290
1
                mutable_result_column = lhs_column->clone_resized(size);
291
1
                result_data_column =
292
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
293
1
            }
294
295
105
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
296
105
            result_column = std::move(mutable_result_column);
297
105
        };
298
17.3k
        auto vector_vector_null = [&]<bool is_and_op>() {
299
2.06k
            auto col_res = ColumnUInt8::create(size);
300
2.06k
            auto col_nulls = ColumnUInt8::create(size);
301
302
2.06k
            auto* __restrict res_datas = col_res->get_data().data();
303
2.06k
            auto* __restrict res_nulls = col_nulls->get_data().data();
304
2.06k
            ColumnPtr temp_null_map = nullptr;
305
            // maybe both children are nullable / or one of children is nullable
306
2.06k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
307
2.06k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
308
2.06k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
309
2.06k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
310
311
2.06k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
312
2.06k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
313
314
2.06k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
315
2.06k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
298
317
        auto vector_vector_null = [&]<bool is_and_op>() {
299
317
            auto col_res = ColumnUInt8::create(size);
300
317
            auto col_nulls = ColumnUInt8::create(size);
301
302
317
            auto* __restrict res_datas = col_res->get_data().data();
303
317
            auto* __restrict res_nulls = col_nulls->get_data().data();
304
317
            ColumnPtr temp_null_map = nullptr;
305
            // maybe both children are nullable / or one of children is nullable
306
317
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
307
317
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
308
317
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
309
317
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
310
311
317
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
312
317
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
313
314
317
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
315
317
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
298
1.75k
        auto vector_vector_null = [&]<bool is_and_op>() {
299
1.75k
            auto col_res = ColumnUInt8::create(size);
300
1.75k
            auto col_nulls = ColumnUInt8::create(size);
301
302
1.75k
            auto* __restrict res_datas = col_res->get_data().data();
303
1.75k
            auto* __restrict res_nulls = col_nulls->get_data().data();
304
1.75k
            ColumnPtr temp_null_map = nullptr;
305
            // maybe both children are nullable / or one of children is nullable
306
1.75k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
307
1.75k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
308
1.75k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
309
1.75k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
310
311
1.75k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
312
1.75k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
313
314
1.75k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
315
1.75k
        };
316
317
        // false and NULL ----> 0
318
        // true  and NULL ----> NULL
319
17.3k
        if (_op == TExprOpcode::COMPOUND_AND) {
320
            //1. not null column: all data is false
321
            //2. nullable column: null map all is not null
322
3.03k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
323
                // false and any = false, return lhs
324
1.31k
                return_result_column_id(lhs_column);
325
1.72k
            } else {
326
1.72k
                RETURN_IF_ERROR(get_rhs_colum());
327
328
1.72k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
329
1.72k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
330
                                                             // true and any = any, return rhs
331
332
609
                    return_result_column_id(rhs_column);
333
1.11k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
334
1.11k
                           (rhs_all_false && rhs_all_is_not_null)) {
335
                    // any and false = false, return rhs
336
199
                    return_result_column_id(rhs_column);
337
914
                } else if ((rhs_all_true && !rhs_is_nullable) ||
338
914
                           (rhs_all_true && rhs_all_is_not_null)) {
339
                    // any and true = any, return lhs
340
221
                    return_result_column_id(lhs_column);
341
693
                } else {
342
693
                    if (!result_is_nullable) {
343
376
                        vector_vector.template operator()<true>();
344
376
                    } else {
345
317
                        vector_vector_null.template operator()<true>();
346
317
                    }
347
693
                }
348
1.72k
            }
349
14.3k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
350
            // true  or NULL ----> 1
351
            // false or NULL ----> NULL
352
14.3k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
353
                // true or any = true, return lhs
354
2.93k
                return_result_column_id(lhs_column);
355
11.3k
            } else {
356
11.3k
                RETURN_IF_ERROR(get_rhs_colum());
357
11.3k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
358
                    // false or any = any, return rhs
359
8.39k
                    return_result_column_id(rhs_column);
360
8.39k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
361
2.97k
                           (rhs_all_true && rhs_all_is_not_null)) {
362
                    // any or true = true, return rhs
363
580
                    return_result_column_id(rhs_column);
364
2.39k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
365
2.39k
                           (rhs_all_false && rhs_all_is_not_null)) {
366
                    // any or false = any, return lhs
367
538
                    return_result_column_id(lhs_column);
368
1.85k
                } else {
369
1.85k
                    if (!result_is_nullable) {
370
105
                        vector_vector.template operator()<false>();
371
1.75k
                    } else {
372
1.75k
                        vector_vector_null.template operator()<false>();
373
1.75k
                    }
374
1.85k
                }
375
11.3k
            }
376
18.4E
        } else {
377
18.4E
            return Status::InternalError("Compound operator must be AND or OR.");
378
18.4E
        }
379
380
17.3k
        DCHECK_EQ(result_column->size(), count);
381
17.3k
        return Status::OK();
382
17.3k
    }
383
384
936
    double execute_cost() const override {
385
936
        double cost = 0.3;
386
1.48k
        for (const auto& child : _children) {
387
1.48k
            cost += child->execute_cost();
388
1.48k
        }
389
936
        return cost;
390
936
    }
391
392
private:
393
6.10k
    static inline constexpr uint8_t apply_and_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
394
        // (<> && false) is false, (true && NULL) is NULL
395
6.10k
        return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b));
396
6.10k
    }
397
48.8k
    static inline constexpr uint8_t apply_or_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
398
        // (<> || true) is true, (false || NULL) is NULL
399
48.8k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
400
48.8k
    }
401
402
    template <bool is_and>
403
    void static do_not_null_pred(uint8_t* __restrict lhs, const uint8_t* __restrict rhs,
404
481
                                 size_t size) {
405
#ifdef NDEBUG
406
#if defined(__clang__)
407
#pragma clang loop vectorize(enable)
408
#elif defined(__GNUC__) && (__GNUC__ >= 5)
409
#pragma GCC ivdep
410
#endif
411
#endif
412
14.4k
        for (size_t i = 0; i < size; ++i) {
413
13.9k
            if constexpr (is_and) {
414
9.97k
                lhs[i] &= rhs[i];
415
9.97k
            } else {
416
3.96k
                lhs[i] |= rhs[i];
417
3.96k
            }
418
13.9k
        }
419
481
    }
_ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhPKhm
Line
Count
Source
404
376
                                 size_t size) {
405
#ifdef NDEBUG
406
#if defined(__clang__)
407
#pragma clang loop vectorize(enable)
408
#elif defined(__GNUC__) && (__GNUC__ >= 5)
409
#pragma GCC ivdep
410
#endif
411
#endif
412
10.3k
        for (size_t i = 0; i < size; ++i) {
413
9.97k
            if constexpr (is_and) {
414
9.97k
                lhs[i] &= rhs[i];
415
            } else {
416
                lhs[i] |= rhs[i];
417
            }
418
9.97k
        }
419
376
    }
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhPKhm
Line
Count
Source
404
105
                                 size_t size) {
405
#ifdef NDEBUG
406
#if defined(__clang__)
407
#pragma clang loop vectorize(enable)
408
#elif defined(__GNUC__) && (__GNUC__ >= 5)
409
#pragma GCC ivdep
410
#endif
411
#endif
412
4.07k
        for (size_t i = 0; i < size; ++i) {
413
            if constexpr (is_and) {
414
                lhs[i] &= rhs[i];
415
3.96k
            } else {
416
3.96k
                lhs[i] |= rhs[i];
417
3.96k
            }
418
3.96k
        }
419
105
    }
420
421
    template <bool is_and>
422
    void static do_null_pred(const uint8_t* __restrict lhs_data, const uint8_t* __restrict lhs_null,
423
                             const uint8_t* __restrict rhs_data, const uint8_t* __restrict rhs_null,
424
                             uint8_t* __restrict res_data, uint8_t* __restrict res_null,
425
2.06k
                             size_t size) {
426
#ifdef NDEBUG
427
#if defined(__clang__)
428
#pragma clang loop vectorize(enable)
429
#elif defined(__GNUC__) && (__GNUC__ >= 5)
430
#pragma GCC ivdep
431
#endif
432
#endif
433
56.9k
        for (size_t i = 0; i < size; ++i) {
434
54.9k
            if constexpr (is_and) {
435
6.10k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
436
6.10k
                res_data[i] = lhs_data[i] & rhs_data[i];
437
48.8k
            } else {
438
48.8k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
439
48.8k
                res_data[i] = lhs_data[i] | rhs_data[i];
440
48.8k
            }
441
54.9k
        }
442
2.06k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
425
317
                             size_t size) {
426
#ifdef NDEBUG
427
#if defined(__clang__)
428
#pragma clang loop vectorize(enable)
429
#elif defined(__GNUC__) && (__GNUC__ >= 5)
430
#pragma GCC ivdep
431
#endif
432
#endif
433
6.41k
        for (size_t i = 0; i < size; ++i) {
434
6.10k
            if constexpr (is_and) {
435
6.10k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
436
6.10k
                res_data[i] = lhs_data[i] & rhs_data[i];
437
            } else {
438
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
439
                res_data[i] = lhs_data[i] | rhs_data[i];
440
            }
441
6.10k
        }
442
317
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
425
1.75k
                             size_t size) {
426
#ifdef NDEBUG
427
#if defined(__clang__)
428
#pragma clang loop vectorize(enable)
429
#elif defined(__GNUC__) && (__GNUC__ >= 5)
430
#pragma GCC ivdep
431
#endif
432
#endif
433
50.5k
        for (size_t i = 0; i < size; ++i) {
434
            if constexpr (is_and) {
435
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
436
                res_data[i] = lhs_data[i] & rhs_data[i];
437
48.8k
            } else {
438
48.8k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
439
48.8k
                res_data[i] = lhs_data[i] | rhs_data[i];
440
48.8k
            }
441
48.8k
        }
442
1.75k
    }
443
444
17.3k
    bool _has_const_child() const {
445
17.3k
        return std::ranges::any_of(_children,
446
34.7k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
447
17.3k
    }
448
449
    std::pair<const uint8_t*, const uint8_t*> _get_raw_data_and_null_map(
450
30.4k
            const ColumnPtr& column, bool has_nullable_column) const {
451
30.4k
        if (has_nullable_column) {
452
17.3k
            const auto* nullable_column = assert_cast<const ColumnNullable*>(column.get());
453
17.3k
            auto* data_column =
454
17.3k
                    assert_cast<const ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
455
17.3k
                            ->get_data()
456
17.3k
                            .data();
457
17.3k
            auto* null_map = nullable_column->get_null_map_column_ptr()->get_data().data();
458
17.3k
            return std::make_pair(data_column, null_map);
459
17.3k
        } else {
460
13.0k
            auto* data_column = assert_cast<const ColumnUInt8*>(column.get())->get_data().data();
461
13.0k
            return std::make_pair(data_column, nullptr);
462
13.0k
        }
463
30.4k
    }
464
465
    TExprOpcode::type _op;
466
};
467
468
} // namespace doris