Coverage Report

Created: 2026-05-28 04:38

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/status.h"
25
#include "core/assert_cast.h"
26
#include "core/column/column.h"
27
#include "core/column/column_nullable.h"
28
#include "exprs/vectorized_fn_call.h"
29
#include "exprs/vexpr_context.h"
30
#include "exprs/vexpr_fwd.h"
31
#include "util/simd/bits.h"
32
33
namespace doris {
34
35
4.58k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
36
4.58k
    if (op == TExprOpcode::COMPOUND_AND) {
37
873
        return "and";
38
3.71k
    } else if (op == TExprOpcode::COMPOUND_OR) {
39
3.29k
        return "or";
40
3.29k
    } else {
41
420
        return "not";
42
420
    }
43
4.58k
}
44
45
class VCompoundPred : public VectorizedFnCall {
46
    ENABLE_FACTORY_CREATOR(VCompoundPred);
47
48
public:
49
4.58k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
50
4.58k
        _op = node.opcode;
51
4.58k
        _fn.name.function_name = compound_operator_to_string(_op);
52
4.58k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
53
4.58k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
54
4.58k
    }
55
56
#ifdef BE_TEST
57
    VCompoundPred() = default;
58
#endif
59
60
10.9k
    const std::string& expr_name() const override { return _expr_name; }
61
62
5.34k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
63
5.34k
        segment_v2::InvertedIndexResultBitmap res;
64
5.34k
        bool all_pass = true;
65
66
5.34k
        switch (_op) {
67
3.34k
        case TExprOpcode::COMPOUND_OR: {
68
6.48k
            for (const auto& child : _children) {
69
6.48k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
70
6.48k
                    !st.ok()) {
71
179
                    LOG(ERROR) << "expr:" << child->expr_name()
72
179
                               << " evaluate_inverted_index error:" << st.to_string();
73
179
                    all_pass = false;
74
179
                    continue;
75
179
                }
76
6.30k
                auto inverted_index_context = context->get_index_context();
77
6.30k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
78
3.21k
                    const auto* index_result =
79
3.21k
                            inverted_index_context->get_index_result_for_expr(child.get());
80
3.21k
                    if (res.is_empty()) {
81
2.21k
                        res = *index_result;
82
2.21k
                    } else {
83
995
                        res |= *index_result;
84
995
                    }
85
3.21k
                    if (inverted_index_context->get_score_runtime() == nullptr) {
86
3.20k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
87
343
                            break; // Early exit if result is full
88
343
                        }
89
3.20k
                    }
90
3.21k
                } else {
91
3.09k
                    all_pass = false;
92
3.09k
                }
93
6.30k
            }
94
3.34k
            break;
95
0
        }
96
5.95k
        case TExprOpcode::COMPOUND_AND: {
97
1.59k
            for (const auto& child : _children) {
98
1.59k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
99
1.59k
                    !st.ok()) {
100
29
                    LOG(ERROR) << "expr:" << child->expr_name()
101
29
                               << " evaluate_inverted_index error:" << st.to_string();
102
29
                    all_pass = false;
103
29
                    continue;
104
29
                }
105
1.56k
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
106
251
                    const auto* index_result =
107
251
                            context->get_index_context()->get_index_result_for_expr(child.get());
108
251
                    if (res.is_empty()) {
109
185
                        res = *index_result;
110
185
                    } else {
111
66
                        res &= *index_result;
112
66
                    }
113
114
251
                    if (res.get_data_bitmap()->isEmpty()) {
115
109
                        break; // Early exit if result is empty
116
109
                    }
117
1.31k
                } else {
118
1.31k
                    all_pass = false;
119
1.31k
                }
120
1.56k
            }
121
841
            break;
122
0
        }
123
1.45k
        case TExprOpcode::COMPOUND_NOT: {
124
1.17k
            const auto& child = _children[0];
125
1.17k
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
126
1.17k
            if (!st.ok()) {
127
32
                LOG(ERROR) << "expr:" << child->expr_name()
128
32
                           << " evaluate_inverted_index error:" << st.to_string();
129
32
                return st;
130
32
            }
131
132
1.13k
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
133
622
                const auto* index_result =
134
622
                        context->get_index_context()->get_index_result_for_expr(child.get());
135
622
                roaring::Roaring full_result;
136
622
                full_result.addRange(0, segment_num_rows);
137
622
                res = index_result->op_not(&full_result);
138
622
            } else {
139
516
                all_pass = false;
140
516
            }
141
1.13k
            break;
142
1.17k
        }
143
0
        default:
144
0
            return Status::NotSupported(
145
0
                    "Compound operator must be AND, OR, or NOT to execute with inverted index.");
146
5.34k
        }
147
148
5.34k
        if (all_pass && !res.is_empty()) {
149
2.00k
            context->get_index_context()->set_index_result_for_expr(this, res);
150
2.00k
        }
151
5.34k
        return Status::OK();
152
5.34k
    }
153
154
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
155
61.3k
                               size_t count, ColumnPtr& result_column) const override {
156
61.3k
        if (fast_execute(context, selector, count, result_column)) {
157
85
            return Status::OK();
158
85
        }
159
61.2k
        if (get_num_children() == 1 || _has_const_child()) {
160
978
            return VectorizedFnCall::execute_column_impl(context, block, selector, count,
161
978
                                                         result_column);
162
978
        }
163
164
60.2k
        ColumnPtr lhs_column;
165
60.2k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
166
60.2k
        lhs_column = lhs_column->convert_to_full_column_if_const();
167
60.2k
        size_t size = lhs_column->size();
168
169
60.2k
        bool lhs_is_nullable = lhs_column->is_nullable();
170
60.2k
        auto [lhs_data_column, lhs_null_map] =
171
60.2k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
172
60.2k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
173
60.2k
        bool lhs_all_true = (filted == 0);
174
60.2k
        bool lhs_all_false = (filted == size);
175
176
60.2k
        bool lhs_all_is_not_null = false;
177
60.2k
        if (lhs_is_nullable) {
178
50.5k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
179
50.5k
            lhs_all_is_not_null = (filted == size);
180
50.5k
        }
181
182
60.2k
        ColumnPtr rhs_column = nullptr;
183
60.2k
        const uint8_t* __restrict rhs_data_column = nullptr;
184
60.2k
        const uint8_t* __restrict rhs_null_map = nullptr;
185
60.2k
        bool rhs_is_nullable = false;
186
60.2k
        bool rhs_all_true = false;
187
60.2k
        bool rhs_all_false = false;
188
60.2k
        bool rhs_all_is_not_null = false;
189
60.2k
        bool result_is_nullable = _data_type->is_nullable();
190
191
60.2k
        auto get_rhs_colum = [&]() {
192
39.7k
            if (!rhs_column) {
193
39.7k
                RETURN_IF_ERROR(
194
39.7k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
195
39.7k
                rhs_column = rhs_column->convert_to_full_column_if_const();
196
39.7k
                rhs_is_nullable = rhs_column->is_nullable();
197
39.7k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
198
39.7k
                rhs_data_column = rhs_nullable_column.first;
199
39.7k
                rhs_null_map = rhs_nullable_column.second;
200
39.7k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
201
39.7k
                rhs_all_true = (filted == 0);
202
39.7k
                rhs_all_false = (filted == size);
203
39.7k
                if (rhs_is_nullable) {
204
30.4k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
205
30.4k
                    rhs_all_is_not_null = (filted == size);
206
30.4k
                }
207
39.7k
            }
208
39.7k
            return Status::OK();
209
39.7k
        };
210
211
60.2k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
212
48.7k
            result_column = std::move(*arg_column).mutate();
213
48.7k
            if (result_is_nullable && !result_column->is_nullable()) {
214
1.87k
                result_column = make_nullable(result_column);
215
1.87k
            }
216
48.7k
        };
217
218
60.2k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
219
60.2k
                                          const uint8_t* __restrict null_map_data) {
220
21.7k
            if (null_map_data == nullptr) {
221
580
                null_map_column = ColumnUInt8::create(size, 0);
222
580
                null_map_data =
223
580
                        assert_cast<const ColumnUInt8*>(null_map_column.get())->get_data().data();
224
580
            }
225
21.7k
            return null_map_data;
226
21.7k
        };
227
228
60.2k
        auto vector_vector = [&]<bool is_and_op>() {
229
631
            MutableColumnPtr mutable_result_column;
230
631
            uint8_t* __restrict result_data_column = nullptr;
231
631
            const uint8_t* __restrict other_data_column = rhs_data_column;
232
631
            if (lhs_column->use_count() == 1) {
233
629
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
234
629
                result_data_column =
235
629
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
236
629
            } else if (rhs_column->use_count() == 1) {
237
1
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
238
1
                result_data_column =
239
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
240
1
                other_data_column = lhs_data_column;
241
1
            } else {
242
1
                mutable_result_column = lhs_column->clone_resized(size);
243
1
                result_data_column =
244
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
245
1
            }
246
247
631
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
248
631
            result_column = std::move(mutable_result_column);
249
631
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb1EEEDav
Line
Count
Source
228
494
        auto vector_vector = [&]<bool is_and_op>() {
229
494
            MutableColumnPtr mutable_result_column;
230
494
            uint8_t* __restrict result_data_column = nullptr;
231
494
            const uint8_t* __restrict other_data_column = rhs_data_column;
232
494
            if (lhs_column->use_count() == 1) {
233
494
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
234
494
                result_data_column =
235
494
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
236
494
            } else if (rhs_column->use_count() == 1) {
237
0
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
238
0
                result_data_column =
239
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
240
0
                other_data_column = lhs_data_column;
241
0
            } else {
242
0
                mutable_result_column = lhs_column->clone_resized(size);
243
0
                result_data_column =
244
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
245
0
            }
246
247
494
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
248
494
            result_column = std::move(mutable_result_column);
249
494
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb0EEEDav
Line
Count
Source
228
137
        auto vector_vector = [&]<bool is_and_op>() {
229
137
            MutableColumnPtr mutable_result_column;
230
137
            uint8_t* __restrict result_data_column = nullptr;
231
137
            const uint8_t* __restrict other_data_column = rhs_data_column;
232
137
            if (lhs_column->use_count() == 1) {
233
135
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
234
135
                result_data_column =
235
135
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
236
135
            } else if (rhs_column->use_count() == 1) {
237
1
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
238
1
                result_data_column =
239
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
240
1
                other_data_column = lhs_data_column;
241
1
            } else {
242
1
                mutable_result_column = lhs_column->clone_resized(size);
243
1
                result_data_column =
244
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
245
1
            }
246
247
137
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
248
137
            result_column = std::move(mutable_result_column);
249
137
        };
250
60.2k
        auto vector_vector_null = [&]<bool is_and_op>() {
251
10.8k
            auto col_res = ColumnUInt8::create(size);
252
10.8k
            auto col_nulls = ColumnUInt8::create(size);
253
254
10.8k
            auto* __restrict res_datas = col_res->get_data().data();
255
10.8k
            auto* __restrict res_nulls = col_nulls->get_data().data();
256
10.8k
            ColumnPtr temp_null_map = nullptr;
257
            // maybe both children are nullable / or one of children is nullable
258
10.8k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
259
10.8k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
260
10.8k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
261
10.8k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
262
263
10.8k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
264
10.8k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
265
266
10.8k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
267
10.8k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
250
6.28k
        auto vector_vector_null = [&]<bool is_and_op>() {
251
6.28k
            auto col_res = ColumnUInt8::create(size);
252
6.28k
            auto col_nulls = ColumnUInt8::create(size);
253
254
6.28k
            auto* __restrict res_datas = col_res->get_data().data();
255
6.28k
            auto* __restrict res_nulls = col_nulls->get_data().data();
256
6.28k
            ColumnPtr temp_null_map = nullptr;
257
            // maybe both children are nullable / or one of children is nullable
258
6.28k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
259
6.28k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
260
6.28k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
261
6.28k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
262
263
6.28k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
264
6.28k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
265
266
6.28k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
267
6.28k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
250
4.58k
        auto vector_vector_null = [&]<bool is_and_op>() {
251
4.58k
            auto col_res = ColumnUInt8::create(size);
252
4.58k
            auto col_nulls = ColumnUInt8::create(size);
253
254
4.58k
            auto* __restrict res_datas = col_res->get_data().data();
255
4.58k
            auto* __restrict res_nulls = col_nulls->get_data().data();
256
4.58k
            ColumnPtr temp_null_map = nullptr;
257
            // maybe both children are nullable / or one of children is nullable
258
4.58k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
259
4.58k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
260
4.58k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
261
4.58k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
262
263
4.58k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
264
4.58k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
265
266
4.58k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
267
4.58k
        };
268
269
        // false and NULL ----> 0
270
        // true  and NULL ----> NULL
271
60.2k
        if (_op == TExprOpcode::COMPOUND_AND) {
272
            //1. not null column: all data is false
273
            //2. nullable column: null map all is not null
274
30.0k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
275
                // false and any = false, return lhs
276
17.6k
                return_result_column_id(lhs_column);
277
17.6k
            } else {
278
12.4k
                RETURN_IF_ERROR(get_rhs_colum());
279
280
12.4k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
281
12.4k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
282
                                                             // true and any = any, return rhs
283
284
672
                    return_result_column_id(rhs_column);
285
11.7k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
286
11.7k
                           (rhs_all_false && rhs_all_is_not_null)) {
287
                    // any and false = false, return rhs
288
218
                    return_result_column_id(rhs_column);
289
11.5k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
290
11.5k
                           (rhs_all_true && rhs_all_is_not_null)) {
291
                    // any and true = any, return lhs
292
4.79k
                    return_result_column_id(lhs_column);
293
6.77k
                } else {
294
6.77k
                    if (!result_is_nullable) {
295
494
                        vector_vector.template operator()<true>();
296
6.28k
                    } else {
297
6.28k
                        vector_vector_null.template operator()<true>();
298
6.28k
                    }
299
6.77k
                }
300
12.4k
            }
301
30.1k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
302
            // true  or NULL ----> 1
303
            // false or NULL ----> NULL
304
30.1k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
305
                // true or any = true, return lhs
306
2.87k
                return_result_column_id(lhs_column);
307
27.3k
            } else {
308
27.3k
                RETURN_IF_ERROR(get_rhs_colum());
309
27.3k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
310
                    // false or any = any, return rhs
311
18.4k
                    return_result_column_id(rhs_column);
312
18.4k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
313
8.90k
                           (rhs_all_true && rhs_all_is_not_null)) {
314
                    // any or true = true, return rhs
315
689
                    return_result_column_id(rhs_column);
316
8.22k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
317
8.22k
                           (rhs_all_false && rhs_all_is_not_null)) {
318
                    // any or false = any, return lhs
319
3.50k
                    return_result_column_id(lhs_column);
320
4.71k
                } else {
321
4.71k
                    if (!result_is_nullable) {
322
137
                        vector_vector.template operator()<false>();
323
4.58k
                    } else {
324
4.58k
                        vector_vector_null.template operator()<false>();
325
4.58k
                    }
326
4.71k
                }
327
27.3k
            }
328
30.1k
        } else {
329
5
            return Status::InternalError("Compound operator must be AND or OR.");
330
5
        }
331
332
60.2k
        DCHECK_EQ(result_column->size(), count);
333
60.2k
        return Status::OK();
334
60.2k
    }
335
336
1.01k
    double execute_cost() const override {
337
1.01k
        double cost = 0.3;
338
1.58k
        for (const auto& child : _children) {
339
1.58k
            cost += child->execute_cost();
340
1.58k
        }
341
1.01k
        return cost;
342
1.01k
    }
343
344
private:
345
33.6k
    static inline constexpr uint8_t apply_and_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
346
        // (<> && false) is false, (true && NULL) is NULL
347
33.6k
        return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b));
348
33.6k
    }
349
58.2k
    static inline constexpr uint8_t apply_or_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
350
        // (<> || true) is true, (false || NULL) is NULL
351
58.2k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
352
58.2k
    }
353
354
    template <bool is_and>
355
    void static do_not_null_pred(uint8_t* __restrict lhs, const uint8_t* __restrict rhs,
356
631
                                 size_t size) {
357
#ifdef NDEBUG
358
#if defined(__clang__)
359
#pragma clang loop vectorize(enable)
360
#elif defined(__GNUC__) && (__GNUC__ >= 5)
361
#pragma GCC ivdep
362
#endif
363
#endif
364
13.6k
        for (size_t i = 0; i < size; ++i) {
365
13.0k
            if constexpr (is_and) {
366
9.46k
                lhs[i] &= rhs[i];
367
9.46k
            } else {
368
3.60k
                lhs[i] |= rhs[i];
369
3.60k
            }
370
13.0k
        }
371
631
    }
_ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhPKhm
Line
Count
Source
356
494
                                 size_t size) {
357
#ifdef NDEBUG
358
#if defined(__clang__)
359
#pragma clang loop vectorize(enable)
360
#elif defined(__GNUC__) && (__GNUC__ >= 5)
361
#pragma GCC ivdep
362
#endif
363
#endif
364
9.95k
        for (size_t i = 0; i < size; ++i) {
365
9.46k
            if constexpr (is_and) {
366
9.46k
                lhs[i] &= rhs[i];
367
            } else {
368
                lhs[i] |= rhs[i];
369
            }
370
9.46k
        }
371
494
    }
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhPKhm
Line
Count
Source
356
137
                                 size_t size) {
357
#ifdef NDEBUG
358
#if defined(__clang__)
359
#pragma clang loop vectorize(enable)
360
#elif defined(__GNUC__) && (__GNUC__ >= 5)
361
#pragma GCC ivdep
362
#endif
363
#endif
364
3.74k
        for (size_t i = 0; i < size; ++i) {
365
            if constexpr (is_and) {
366
                lhs[i] &= rhs[i];
367
3.60k
            } else {
368
3.60k
                lhs[i] |= rhs[i];
369
3.60k
            }
370
3.60k
        }
371
137
    }
372
373
    template <bool is_and>
374
    void static do_null_pred(const uint8_t* __restrict lhs_data, const uint8_t* __restrict lhs_null,
375
                             const uint8_t* __restrict rhs_data, const uint8_t* __restrict rhs_null,
376
                             uint8_t* __restrict res_data, uint8_t* __restrict res_null,
377
10.8k
                             size_t size) {
378
#ifdef NDEBUG
379
#if defined(__clang__)
380
#pragma clang loop vectorize(enable)
381
#elif defined(__GNUC__) && (__GNUC__ >= 5)
382
#pragma GCC ivdep
383
#endif
384
#endif
385
102k
        for (size_t i = 0; i < size; ++i) {
386
91.9k
            if constexpr (is_and) {
387
33.6k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
388
33.6k
                res_data[i] = lhs_data[i] & rhs_data[i];
389
58.2k
            } else {
390
58.2k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
391
58.2k
                res_data[i] = lhs_data[i] | rhs_data[i];
392
58.2k
            }
393
91.9k
        }
394
10.8k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
377
6.28k
                             size_t size) {
378
#ifdef NDEBUG
379
#if defined(__clang__)
380
#pragma clang loop vectorize(enable)
381
#elif defined(__GNUC__) && (__GNUC__ >= 5)
382
#pragma GCC ivdep
383
#endif
384
#endif
385
39.9k
        for (size_t i = 0; i < size; ++i) {
386
33.6k
            if constexpr (is_and) {
387
33.6k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
388
33.6k
                res_data[i] = lhs_data[i] & rhs_data[i];
389
            } else {
390
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
391
                res_data[i] = lhs_data[i] | rhs_data[i];
392
            }
393
33.6k
        }
394
6.28k
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
377
4.58k
                             size_t size) {
378
#ifdef NDEBUG
379
#if defined(__clang__)
380
#pragma clang loop vectorize(enable)
381
#elif defined(__GNUC__) && (__GNUC__ >= 5)
382
#pragma GCC ivdep
383
#endif
384
#endif
385
62.8k
        for (size_t i = 0; i < size; ++i) {
386
            if constexpr (is_and) {
387
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
388
                res_data[i] = lhs_data[i] & rhs_data[i];
389
58.2k
            } else {
390
58.2k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
391
58.2k
                res_data[i] = lhs_data[i] | rhs_data[i];
392
58.2k
            }
393
58.2k
        }
394
4.58k
    }
395
396
60.2k
    bool _has_const_child() const {
397
60.2k
        return std::ranges::any_of(_children,
398
120k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
399
60.2k
    }
400
401
    std::pair<const uint8_t*, const uint8_t*> _get_raw_data_and_null_map(
402
100k
            const ColumnPtr& column, bool has_nullable_column) const {
403
100k
        if (has_nullable_column) {
404
81.0k
            const auto* nullable_column = assert_cast<const ColumnNullable*>(column.get());
405
81.0k
            auto* data_column =
406
81.0k
                    assert_cast<const ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
407
81.0k
                            ->get_data()
408
81.0k
                            .data();
409
81.0k
            auto* null_map = nullable_column->get_null_map_column_ptr()->get_data().data();
410
81.0k
            return std::make_pair(data_column, null_map);
411
81.0k
        } else {
412
18.9k
            auto* data_column = assert_cast<const ColumnUInt8*>(column.get())->get_data().data();
413
18.9k
            return std::make_pair(data_column, nullptr);
414
18.9k
        }
415
100k
    }
416
417
    TExprOpcode::type _op;
418
};
419
420
} // namespace doris