Coverage Report

Created: 2026-06-10 07:13

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
5.53k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
36
5.53k
    if (op == TExprOpcode::COMPOUND_AND) {
37
984
        return "and";
38
4.55k
    } else if (op == TExprOpcode::COMPOUND_OR) {
39
3.96k
        return "or";
40
3.96k
    } else {
41
588
        return "not";
42
588
    }
43
5.53k
}
44
45
class VCompoundPred : public VectorizedFnCall {
46
    ENABLE_FACTORY_CREATOR(VCompoundPred);
47
48
public:
49
5.53k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
50
5.53k
        _op = node.opcode;
51
5.53k
        _fn.name.function_name = compound_operator_to_string(_op);
52
5.53k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
53
5.53k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
54
5.53k
    }
55
56
#ifdef BE_TEST
57
    VCompoundPred() = default;
58
#endif
59
60
13.4k
    const std::string& expr_name() const override { return _expr_name; }
61
62
5.52k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
63
5.52k
        segment_v2::InvertedIndexResultBitmap res;
64
5.52k
        bool all_pass = true;
65
66
5.52k
        switch (_op) {
67
3.47k
        case TExprOpcode::COMPOUND_OR: {
68
6.72k
            for (const auto& child : _children) {
69
6.72k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
70
6.72k
                    !st.ok()) {
71
184
                    LOG(ERROR) << "expr:" << child->expr_name()
72
184
                               << " evaluate_inverted_index error:" << st.to_string();
73
184
                    all_pass = false;
74
184
                    continue;
75
184
                }
76
6.54k
                auto inverted_index_context = context->get_index_context();
77
6.54k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
78
3.30k
                    const auto* index_result =
79
3.30k
                            inverted_index_context->get_index_result_for_expr(child.get());
80
3.30k
                    if (res.is_empty()) {
81
2.31k
                        res = *index_result;
82
2.31k
                    } else {
83
996
                        res |= *index_result;
84
996
                    }
85
3.30k
                    if (inverted_index_context->get_score_runtime() == nullptr) {
86
3.30k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
87
364
                            break; // Early exit if result is full
88
364
                        }
89
3.30k
                    }
90
3.30k
                } else {
91
3.23k
                    all_pass = false;
92
3.23k
                }
93
6.54k
            }
94
3.47k
            break;
95
0
        }
96
6.17k
        case TExprOpcode::COMPOUND_AND: {
97
1.36k
            for (const auto& child : _children) {
98
1.36k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
99
1.36k
                    !st.ok()) {
100
34
                    LOG(ERROR) << "expr:" << child->expr_name()
101
34
                               << " evaluate_inverted_index error:" << st.to_string();
102
34
                    all_pass = false;
103
34
                    continue;
104
34
                }
105
1.33k
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
106
287
                    const auto* index_result =
107
287
                            context->get_index_context()->get_index_result_for_expr(child.get());
108
287
                    if (res.is_empty()) {
109
219
                        res = *index_result;
110
219
                    } else {
111
68
                        res &= *index_result;
112
68
                    }
113
114
287
                    if (res.get_data_bitmap()->isEmpty()) {
115
132
                        break; // Early exit if result is empty
116
132
                    }
117
1.04k
                } else {
118
1.04k
                    all_pass = false;
119
1.04k
                }
120
1.33k
            }
121
742
            break;
122
0
        }
123
1.29k
        case TExprOpcode::COMPOUND_NOT: {
124
1.29k
            const auto& child = _children[0];
125
1.29k
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
126
1.29k
            if (!st.ok()) {
127
40
                LOG(ERROR) << "expr:" << child->expr_name()
128
40
                           << " evaluate_inverted_index error:" << st.to_string();
129
40
                return st;
130
40
            }
131
132
1.25k
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
133
738
                const auto* index_result =
134
738
                        context->get_index_context()->get_index_result_for_expr(child.get());
135
738
                roaring::Roaring full_result;
136
738
                full_result.addRange(0, segment_num_rows);
137
738
                res = index_result->op_not(&full_result);
138
738
            } else {
139
521
                all_pass = false;
140
521
            }
141
1.25k
            break;
142
1.29k
        }
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.52k
        }
147
148
5.49k
        if (all_pass && !res.is_empty()) {
149
2.15k
            context->get_index_context()->set_index_result_for_expr(this, res);
150
2.15k
        }
151
5.49k
        return Status::OK();
152
5.52k
    }
153
154
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
155
127k
                               size_t count, ColumnPtr& result_column) const override {
156
127k
        if (fast_execute(context, selector, count, result_column)) {
157
124
            return Status::OK();
158
124
        }
159
127k
        if (get_num_children() == 1 || _has_const_child()) {
160
980
            return VectorizedFnCall::execute_column_impl(context, block, selector, count,
161
980
                                                         result_column);
162
980
        }
163
164
126k
        ColumnPtr lhs_column;
165
126k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
166
126k
        lhs_column = lhs_column->convert_to_full_column_if_const();
167
126k
        size_t size = lhs_column->size();
168
169
126k
        bool lhs_is_nullable = lhs_column->is_nullable();
170
126k
        auto [lhs_data_column, lhs_null_map] =
171
126k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
172
126k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
173
126k
        bool lhs_all_true = (filted == 0);
174
126k
        bool lhs_all_false = (filted == size);
175
176
126k
        bool lhs_all_is_not_null = false;
177
126k
        if (lhs_is_nullable) {
178
115k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
179
115k
            lhs_all_is_not_null = (filted == size);
180
115k
        }
181
182
126k
        ColumnPtr rhs_column = nullptr;
183
126k
        const uint8_t* __restrict rhs_data_column = nullptr;
184
126k
        const uint8_t* __restrict rhs_null_map = nullptr;
185
126k
        bool rhs_is_nullable = false;
186
126k
        bool rhs_all_true = false;
187
126k
        bool rhs_all_false = false;
188
126k
        bool rhs_all_is_not_null = false;
189
126k
        bool result_is_nullable = _data_type->is_nullable();
190
191
126k
        auto get_rhs_colum = [&]() {
192
71.1k
            if (!rhs_column) {
193
71.1k
                RETURN_IF_ERROR(
194
71.1k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
195
71.1k
                rhs_column = rhs_column->convert_to_full_column_if_const();
196
71.1k
                rhs_is_nullable = rhs_column->is_nullable();
197
71.1k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
198
71.1k
                rhs_data_column = rhs_nullable_column.first;
199
71.1k
                rhs_null_map = rhs_nullable_column.second;
200
71.1k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
201
71.1k
                rhs_all_true = (filted == 0);
202
71.1k
                rhs_all_false = (filted == size);
203
71.1k
                if (rhs_is_nullable) {
204
58.9k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
205
58.9k
                    rhs_all_is_not_null = (filted == size);
206
58.9k
                }
207
71.1k
            }
208
71.1k
            return Status::OK();
209
71.1k
        };
210
211
126k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
212
115k
            result_column = std::move(*arg_column).mutate();
213
115k
            if (result_is_nullable && !result_column->is_nullable()) {
214
3.15k
                result_column = make_nullable(result_column);
215
3.15k
            }
216
115k
        };
217
218
126k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
219
126k
                                          const uint8_t* __restrict null_map_data) {
220
21.1k
            if (null_map_data == nullptr) {
221
652
                null_map_column = ColumnUInt8::create(size, 0);
222
652
                null_map_data =
223
652
                        assert_cast<const ColumnUInt8*>(null_map_column.get())->get_data().data();
224
652
            }
225
21.1k
            return null_map_data;
226
21.1k
        };
227
228
126k
        auto vector_vector = [&]<bool is_and_op>() {
229
370
            MutableColumnPtr mutable_result_column;
230
370
            uint8_t* __restrict result_data_column = nullptr;
231
370
            const uint8_t* __restrict other_data_column = rhs_data_column;
232
370
            if (lhs_column->use_count() == 1) {
233
366
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
234
366
                result_data_column =
235
366
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
236
366
            } 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
3
            } else {
242
3
                mutable_result_column = lhs_column->clone_resized(size);
243
3
                result_data_column =
244
3
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
245
3
            }
246
247
370
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
248
370
            result_column = std::move(mutable_result_column);
249
370
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb1EEEDav
Line
Count
Source
228
280
        auto vector_vector = [&]<bool is_and_op>() {
229
280
            MutableColumnPtr mutable_result_column;
230
280
            uint8_t* __restrict result_data_column = nullptr;
231
280
            const uint8_t* __restrict other_data_column = rhs_data_column;
232
280
            if (lhs_column->use_count() == 1) {
233
280
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
234
280
                result_data_column =
235
280
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
236
280
            } 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
280
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
248
280
            result_column = std::move(mutable_result_column);
249
280
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb0EEEDav
Line
Count
Source
228
90
        auto vector_vector = [&]<bool is_and_op>() {
229
90
            MutableColumnPtr mutable_result_column;
230
90
            uint8_t* __restrict result_data_column = nullptr;
231
90
            const uint8_t* __restrict other_data_column = rhs_data_column;
232
90
            if (lhs_column->use_count() == 1) {
233
86
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
234
86
                result_data_column =
235
86
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
236
86
            } 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
3
            } else {
242
3
                mutable_result_column = lhs_column->clone_resized(size);
243
3
                result_data_column =
244
3
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
245
3
            }
246
247
90
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
248
90
            result_column = std::move(mutable_result_column);
249
90
        };
250
126k
        auto vector_vector_null = [&]<bool is_and_op>() {
251
10.5k
            auto col_res = ColumnUInt8::create(size);
252
10.5k
            auto col_nulls = ColumnUInt8::create(size);
253
254
10.5k
            auto* __restrict res_datas = col_res->get_data().data();
255
10.5k
            auto* __restrict res_nulls = col_nulls->get_data().data();
256
10.5k
            ColumnPtr temp_null_map = nullptr;
257
            // maybe both children are nullable / or one of children is nullable
258
10.5k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
259
10.5k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
260
10.5k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
261
10.5k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
262
263
10.5k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
264
10.5k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
265
266
10.5k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
267
10.5k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
250
6.29k
        auto vector_vector_null = [&]<bool is_and_op>() {
251
6.29k
            auto col_res = ColumnUInt8::create(size);
252
6.29k
            auto col_nulls = ColumnUInt8::create(size);
253
254
6.29k
            auto* __restrict res_datas = col_res->get_data().data();
255
6.29k
            auto* __restrict res_nulls = col_nulls->get_data().data();
256
6.29k
            ColumnPtr temp_null_map = nullptr;
257
            // maybe both children are nullable / or one of children is nullable
258
6.29k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
259
6.29k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
260
6.29k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
261
6.29k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
262
263
6.29k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
264
6.29k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
265
266
6.29k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
267
6.29k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
250
4.25k
        auto vector_vector_null = [&]<bool is_and_op>() {
251
4.25k
            auto col_res = ColumnUInt8::create(size);
252
4.25k
            auto col_nulls = ColumnUInt8::create(size);
253
254
4.25k
            auto* __restrict res_datas = col_res->get_data().data();
255
4.25k
            auto* __restrict res_nulls = col_nulls->get_data().data();
256
4.25k
            ColumnPtr temp_null_map = nullptr;
257
            // maybe both children are nullable / or one of children is nullable
258
4.25k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
259
4.25k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
260
4.25k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
261
4.25k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
262
263
4.25k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
264
4.25k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
265
266
4.25k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
267
4.25k
        };
268
269
        // false and NULL ----> 0
270
        // true  and NULL ----> NULL
271
126k
        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
69.0k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
275
                // false and any = false, return lhs
276
51.3k
                return_result_column_id(lhs_column);
277
51.3k
            } else {
278
17.6k
                RETURN_IF_ERROR(get_rhs_colum());
279
280
17.6k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
281
17.6k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
282
                                                             // true and any = any, return rhs
283
284
1.51k
                    return_result_column_id(rhs_column);
285
16.1k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
286
16.1k
                           (rhs_all_false && rhs_all_is_not_null)) {
287
                    // any and false = false, return rhs
288
1.84k
                    return_result_column_id(rhs_column);
289
14.3k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
290
14.3k
                           (rhs_all_true && rhs_all_is_not_null)) {
291
                    // any and true = any, return lhs
292
7.78k
                    return_result_column_id(lhs_column);
293
7.78k
                } else {
294
6.55k
                    if (!result_is_nullable) {
295
280
                        vector_vector.template operator()<true>();
296
6.27k
                    } else {
297
6.27k
                        vector_vector_null.template operator()<true>();
298
6.27k
                    }
299
6.55k
                }
300
17.6k
            }
301
69.0k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
302
            // true  or NULL ----> 1
303
            // false or NULL ----> NULL
304
57.4k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
305
                // true or any = true, return lhs
306
3.96k
                return_result_column_id(lhs_column);
307
53.4k
            } else {
308
53.4k
                RETURN_IF_ERROR(get_rhs_colum());
309
53.4k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
310
                    // false or any = any, return rhs
311
44.2k
                    return_result_column_id(rhs_column);
312
44.2k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
313
9.22k
                           (rhs_all_true && rhs_all_is_not_null)) {
314
                    // any or true = true, return rhs
315
714
                    return_result_column_id(rhs_column);
316
8.50k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
317
8.50k
                           (rhs_all_false && rhs_all_is_not_null)) {
318
                    // any or false = any, return lhs
319
4.17k
                    return_result_column_id(lhs_column);
320
4.33k
                } else {
321
4.33k
                    if (!result_is_nullable) {
322
90
                        vector_vector.template operator()<false>();
323
4.24k
                    } else {
324
4.24k
                        vector_vector_null.template operator()<false>();
325
4.24k
                    }
326
4.33k
                }
327
53.4k
            }
328
57.4k
        } else {
329
27
            return Status::InternalError("Compound operator must be AND or OR.");
330
27
        }
331
332
126k
        DCHECK_EQ(result_column->size(), count);
333
126k
        return Status::OK();
334
126k
    }
335
336
1.29k
    double execute_cost() const override {
337
1.29k
        double cost = 0.3;
338
2.09k
        for (const auto& child : _children) {
339
2.09k
            cost += child->execute_cost();
340
2.09k
        }
341
1.29k
        return cost;
342
1.29k
    }
343
344
private:
345
92.1k
    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
92.1k
        return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b));
348
92.1k
    }
349
283k
    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
283k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
352
283k
    }
353
354
    template <bool is_and>
355
    void static do_not_null_pred(uint8_t* __restrict lhs, const uint8_t* __restrict rhs,
356
370
                                 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
42.7k
        for (size_t i = 0; i < size; ++i) {
365
42.4k
            if constexpr (is_and) {
366
38.1k
                lhs[i] &= rhs[i];
367
38.1k
            } else {
368
4.22k
                lhs[i] |= rhs[i];
369
4.22k
            }
370
42.4k
        }
371
370
    }
_ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhPKhm
Line
Count
Source
356
280
                                 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
38.4k
        for (size_t i = 0; i < size; ++i) {
365
38.1k
            if constexpr (is_and) {
366
38.1k
                lhs[i] &= rhs[i];
367
            } else {
368
                lhs[i] |= rhs[i];
369
            }
370
38.1k
        }
371
280
    }
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhPKhm
Line
Count
Source
356
90
                                 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
4.31k
        for (size_t i = 0; i < size; ++i) {
365
            if constexpr (is_and) {
366
                lhs[i] &= rhs[i];
367
4.22k
            } else {
368
4.22k
                lhs[i] |= rhs[i];
369
4.22k
            }
370
4.22k
        }
371
90
    }
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.5k
                             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
386k
        for (size_t i = 0; i < size; ++i) {
386
375k
            if constexpr (is_and) {
387
92.1k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
388
92.1k
                res_data[i] = lhs_data[i] & rhs_data[i];
389
283k
            } else {
390
283k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
391
283k
                res_data[i] = lhs_data[i] | rhs_data[i];
392
283k
            }
393
375k
        }
394
10.5k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
377
6.29k
                             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
98.4k
        for (size_t i = 0; i < size; ++i) {
386
92.1k
            if constexpr (is_and) {
387
92.1k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
388
92.1k
                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
92.1k
        }
394
6.29k
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
377
4.25k
                             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
287k
        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
283k
            } else {
390
283k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
391
283k
                res_data[i] = lhs_data[i] | rhs_data[i];
392
283k
            }
393
283k
        }
394
4.25k
    }
395
396
126k
    bool _has_const_child() const {
397
126k
        return std::ranges::any_of(_children,
398
253k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
399
126k
    }
400
401
    std::pair<const uint8_t*, const uint8_t*> _get_raw_data_and_null_map(
402
197k
            const ColumnPtr& column, bool has_nullable_column) const {
403
197k
        if (has_nullable_column) {
404
173k
            const auto* nullable_column = assert_cast<const ColumnNullable*>(column.get());
405
173k
            auto* data_column =
406
173k
                    assert_cast<const ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
407
173k
                            ->get_data()
408
173k
                            .data();
409
173k
            auto* null_map = nullable_column->get_null_map_column_ptr()->get_data().data();
410
173k
            return std::make_pair(data_column, null_map);
411
173k
        } else {
412
23.6k
            auto* data_column = assert_cast<const ColumnUInt8*>(column.get())->get_data().data();
413
23.6k
            return std::make_pair(data_column, nullptr);
414
23.6k
        }
415
197k
    }
416
417
    TExprOpcode::type _op;
418
};
419
420
} // namespace doris