Coverage Report

Created: 2026-04-18 15:51

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
3.11k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
36
3.11k
    if (op == TExprOpcode::COMPOUND_AND) {
37
1.00k
        return "and";
38
2.11k
    } else if (op == TExprOpcode::COMPOUND_OR) {
39
1.62k
        return "or";
40
1.62k
    } else {
41
485
        return "not";
42
485
    }
43
3.11k
}
44
45
class VCompoundPred : public VectorizedFnCall {
46
    ENABLE_FACTORY_CREATOR(VCompoundPred);
47
48
public:
49
3.11k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
50
3.11k
        _op = node.opcode;
51
3.11k
        _fn.name.function_name = compound_operator_to_string(_op);
52
3.11k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
53
3.11k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
54
3.11k
    }
55
56
#ifdef BE_TEST
57
    VCompoundPred() = default;
58
#endif
59
60
1.70k
    const std::string& expr_name() const override { return _expr_name; }
61
62
4.43k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
63
4.43k
        segment_v2::InvertedIndexResultBitmap res;
64
4.43k
        bool all_pass = true;
65
66
4.43k
        switch (_op) {
67
2.93k
        case TExprOpcode::COMPOUND_OR: {
68
5.68k
            for (const auto& child : _children) {
69
5.68k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
70
5.68k
                    !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
5.50k
                auto inverted_index_context = context->get_index_context();
77
5.50k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
78
2.84k
                    const auto* index_result =
79
2.84k
                            inverted_index_context->get_index_result_for_expr(child.get());
80
2.84k
                    if (res.is_empty()) {
81
2.00k
                        res = *index_result;
82
2.00k
                    } else {
83
842
                        res |= *index_result;
84
842
                    }
85
2.84k
                    if (inverted_index_context->get_score_runtime() == nullptr) {
86
2.84k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
87
284
                            break; // Early exit if result is full
88
284
                        }
89
2.84k
                    }
90
2.84k
                } else {
91
2.66k
                    all_pass = false;
92
2.66k
                }
93
5.50k
            }
94
2.93k
            break;
95
0
        }
96
5.22k
        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
33
                    LOG(ERROR) << "expr:" << child->expr_name()
101
33
                               << " evaluate_inverted_index error:" << st.to_string();
102
33
                    all_pass = false;
103
33
                    continue;
104
33
                }
105
1.33k
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
106
235
                    const auto* index_result =
107
235
                            context->get_index_context()->get_index_result_for_expr(child.get());
108
235
                    if (res.is_empty()) {
109
171
                        res = *index_result;
110
171
                    } else {
111
64
                        res &= *index_result;
112
64
                    }
113
114
235
                    if (res.get_data_bitmap()->isEmpty()) {
115
97
                        break; // Early exit if result is empty
116
97
                    }
117
1.10k
                } else {
118
1.10k
                    all_pass = false;
119
1.10k
                }
120
1.33k
            }
121
725
            break;
122
0
        }
123
1.23k
        case TExprOpcode::COMPOUND_NOT: {
124
785
            const auto& child = _children[0];
125
785
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
126
785
            if (!st.ok()) {
127
36
                LOG(ERROR) << "expr:" << child->expr_name()
128
36
                           << " evaluate_inverted_index error:" << st.to_string();
129
36
                return st;
130
36
            }
131
132
749
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
133
530
                const auto* index_result =
134
530
                        context->get_index_context()->get_index_result_for_expr(child.get());
135
530
                roaring::Roaring full_result;
136
530
                full_result.addRange(0, segment_num_rows);
137
530
                res = index_result->op_not(&full_result);
138
530
            } else {
139
219
                all_pass = false;
140
219
            }
141
749
            break;
142
785
        }
143
0
        default:
144
0
            return Status::NotSupported(
145
0
                    "Compound operator must be AND, OR, or NOT to execute with inverted index.");
146
4.43k
        }
147
148
4.41k
        if (all_pass && !res.is_empty()) {
149
1.70k
            context->get_index_context()->set_index_result_for_expr(this, res);
150
1.70k
        }
151
4.41k
        return Status::OK();
152
4.43k
    }
153
154
    Status execute_column(VExprContext* context, const Block* block, Selector* selector,
155
11.6k
                          size_t count, ColumnPtr& result_column) const override {
156
11.6k
        if (fast_execute(context, selector, count, result_column)) {
157
62
            return Status::OK();
158
62
        }
159
11.5k
        if (get_num_children() == 1 || _has_const_child()) {
160
987
            return VectorizedFnCall::execute_column(context, block, selector, count, result_column);
161
987
        }
162
163
10.6k
        ColumnPtr lhs_column;
164
10.6k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
165
10.6k
        lhs_column = lhs_column->convert_to_full_column_if_const();
166
10.6k
        size_t size = lhs_column->size();
167
168
10.6k
        bool lhs_is_nullable = lhs_column->is_nullable();
169
10.6k
        auto [lhs_data_column, lhs_null_map] =
170
10.6k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
171
10.6k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
172
10.6k
        bool lhs_all_true = (filted == 0);
173
10.6k
        bool lhs_all_false = (filted == size);
174
175
10.6k
        bool lhs_all_is_not_null = false;
176
10.6k
        if (lhs_is_nullable) {
177
7.49k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
178
7.49k
            lhs_all_is_not_null = (filted == size);
179
7.49k
        }
180
181
10.6k
        ColumnPtr rhs_column = nullptr;
182
10.6k
        uint8_t* __restrict rhs_data_column = nullptr;
183
10.6k
        uint8_t* __restrict rhs_null_map = nullptr;
184
10.6k
        bool rhs_is_nullable = false;
185
10.6k
        bool rhs_all_true = false;
186
10.6k
        bool rhs_all_false = false;
187
10.6k
        bool rhs_all_is_not_null = false;
188
10.6k
        bool result_is_nullable = _data_type->is_nullable();
189
190
10.6k
        auto get_rhs_colum = [&]() {
191
7.81k
            if (!rhs_column) {
192
7.81k
                RETURN_IF_ERROR(
193
7.81k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
194
7.81k
                rhs_column = rhs_column->convert_to_full_column_if_const();
195
7.81k
                rhs_is_nullable = rhs_column->is_nullable();
196
7.81k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
197
7.81k
                rhs_data_column = rhs_nullable_column.first;
198
7.81k
                rhs_null_map = rhs_nullable_column.second;
199
7.81k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
200
7.81k
                rhs_all_true = (filted == 0);
201
7.81k
                rhs_all_false = (filted == size);
202
7.81k
                if (rhs_is_nullable) {
203
5.92k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
204
5.92k
                    rhs_all_is_not_null = (filted == size);
205
5.92k
                }
206
7.81k
            }
207
7.81k
            return Status::OK();
208
7.81k
        };
209
210
10.6k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
211
8.62k
            result_column = std::move(*arg_column).mutate();
212
8.62k
            if (result_is_nullable && !result_column->is_nullable()) {
213
564
                result_column = make_nullable(result_column);
214
564
            }
215
8.62k
        };
216
217
10.6k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
218
10.6k
                                          uint8_t* __restrict null_map_data) {
219
2.96k
            if (null_map_data == nullptr) {
220
227
                null_map_column = ColumnUInt8::create(size, 0);
221
227
                null_map_data = assert_cast<ColumnUInt8*>(null_map_column->assume_mutable().get())
222
227
                                        ->get_data()
223
227
                                        .data();
224
227
            }
225
2.96k
            return null_map_data;
226
2.96k
        };
227
228
10.6k
        auto vector_vector = [&]<bool is_and_op>() {
229
493
            if (lhs_column->use_count() == 1) {
230
487
                result_column = lhs_column;
231
487
            } else if (rhs_column->use_count() == 1) {
232
1
                result_column = rhs_column;
233
1
                auto tmp_column = rhs_data_column;
234
1
                rhs_data_column = lhs_data_column;
235
1
                lhs_data_column = tmp_column;
236
5
            } else {
237
5
                auto col_res = lhs_column->clone_resized(size);
238
5
                lhs_data_column = assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
239
5
                result_column = std::move(col_res);
240
5
            }
241
242
493
            do_not_null_pred<is_and_op>(lhs_data_column, rhs_data_column, size);
243
493
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE_clILb1EEEDav
Line
Count
Source
228
394
        auto vector_vector = [&]<bool is_and_op>() {
229
394
            if (lhs_column->use_count() == 1) {
230
394
                result_column = lhs_column;
231
394
            } else if (rhs_column->use_count() == 1) {
232
0
                result_column = rhs_column;
233
0
                auto tmp_column = rhs_data_column;
234
0
                rhs_data_column = lhs_data_column;
235
0
                lhs_data_column = tmp_column;
236
0
            } else {
237
0
                auto col_res = lhs_column->clone_resized(size);
238
0
                lhs_data_column = assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
239
0
                result_column = std::move(col_res);
240
0
            }
241
242
394
            do_not_null_pred<is_and_op>(lhs_data_column, rhs_data_column, size);
243
394
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE_clILb0EEEDav
Line
Count
Source
228
99
        auto vector_vector = [&]<bool is_and_op>() {
229
99
            if (lhs_column->use_count() == 1) {
230
93
                result_column = lhs_column;
231
93
            } else if (rhs_column->use_count() == 1) {
232
1
                result_column = rhs_column;
233
1
                auto tmp_column = rhs_data_column;
234
1
                rhs_data_column = lhs_data_column;
235
1
                lhs_data_column = tmp_column;
236
5
            } else {
237
5
                auto col_res = lhs_column->clone_resized(size);
238
5
                lhs_data_column = assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
239
5
                result_column = std::move(col_res);
240
5
            }
241
242
99
            do_not_null_pred<is_and_op>(lhs_data_column, rhs_data_column, size);
243
99
        };
244
10.6k
        auto vector_vector_null = [&]<bool is_and_op>() {
245
1.48k
            auto col_res = ColumnUInt8::create(size);
246
1.48k
            auto col_nulls = ColumnUInt8::create(size);
247
248
1.48k
            auto* __restrict res_datas =
249
1.48k
                    assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
250
1.48k
            auto* __restrict res_nulls =
251
1.48k
                    assert_cast<ColumnUInt8*>(col_nulls.get())->get_data().data();
252
1.48k
            ColumnPtr temp_null_map = nullptr;
253
            // maybe both children are nullable / or one of children is nullable
254
1.48k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
255
1.48k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
256
1.48k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
257
1.48k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
258
259
1.48k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
260
1.48k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
261
262
1.48k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
263
1.48k
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
244
300
        auto vector_vector_null = [&]<bool is_and_op>() {
245
300
            auto col_res = ColumnUInt8::create(size);
246
300
            auto col_nulls = ColumnUInt8::create(size);
247
248
300
            auto* __restrict res_datas =
249
300
                    assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
250
300
            auto* __restrict res_nulls =
251
300
                    assert_cast<ColumnUInt8*>(col_nulls.get())->get_data().data();
252
300
            ColumnPtr temp_null_map = nullptr;
253
            // maybe both children are nullable / or one of children is nullable
254
300
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
255
300
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
256
300
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
257
300
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
258
259
300
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
260
300
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
261
262
300
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
263
300
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
244
1.18k
        auto vector_vector_null = [&]<bool is_and_op>() {
245
1.18k
            auto col_res = ColumnUInt8::create(size);
246
1.18k
            auto col_nulls = ColumnUInt8::create(size);
247
248
1.18k
            auto* __restrict res_datas =
249
1.18k
                    assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
250
1.18k
            auto* __restrict res_nulls =
251
1.18k
                    assert_cast<ColumnUInt8*>(col_nulls.get())->get_data().data();
252
1.18k
            ColumnPtr temp_null_map = nullptr;
253
            // maybe both children are nullable / or one of children is nullable
254
1.18k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
255
1.18k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
256
1.18k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
257
1.18k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
258
259
1.18k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
260
1.18k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
261
262
1.18k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
263
1.18k
        };
264
265
        // false and NULL ----> 0
266
        // true  and NULL ----> NULL
267
10.6k
        if (_op == TExprOpcode::COMPOUND_AND) {
268
            //1. not null column: all data is false
269
            //2. nullable column: null map all is not null
270
3.15k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
271
                // false and any = false, return lhs
272
1.36k
                return_result_column_id(lhs_column);
273
1.78k
            } else {
274
1.78k
                RETURN_IF_ERROR(get_rhs_colum());
275
276
1.78k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
277
1.78k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
278
                                                             // true and any = any, return rhs
279
280
730
                    return_result_column_id(rhs_column);
281
1.05k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
282
1.05k
                           (rhs_all_false && rhs_all_is_not_null)) {
283
                    // any and false = false, return rhs
284
191
                    return_result_column_id(rhs_column);
285
868
                } else if ((rhs_all_true && !rhs_is_nullable) ||
286
868
                           (rhs_all_true && rhs_all_is_not_null)) {
287
                    // any and true = any, return lhs
288
175
                    return_result_column_id(lhs_column);
289
693
                } else {
290
693
                    if (!result_is_nullable) {
291
394
                        vector_vector.template operator()<true>();
292
394
                    } else {
293
299
                        vector_vector_null.template operator()<true>();
294
299
                    }
295
693
                }
296
1.78k
            }
297
7.44k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
298
            // true  or NULL ----> 1
299
            // false or NULL ----> NULL
300
7.43k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
301
                // true or any = true, return lhs
302
1.41k
                return_result_column_id(lhs_column);
303
6.02k
            } else {
304
6.02k
                RETURN_IF_ERROR(get_rhs_colum());
305
6.02k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
306
                    // false or any = any, return rhs
307
3.71k
                    return_result_column_id(rhs_column);
308
3.71k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
309
2.31k
                           (rhs_all_true && rhs_all_is_not_null)) {
310
                    // any or true = true, return rhs
311
445
                    return_result_column_id(rhs_column);
312
1.86k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
313
1.86k
                           (rhs_all_false && rhs_all_is_not_null)) {
314
                    // any or false = any, return lhs
315
588
                    return_result_column_id(lhs_column);
316
1.27k
                } else {
317
1.27k
                    if (!result_is_nullable) {
318
99
                        vector_vector.template operator()<false>();
319
1.17k
                    } else {
320
1.17k
                        vector_vector_null.template operator()<false>();
321
1.17k
                    }
322
1.27k
                }
323
6.02k
            }
324
7.43k
        } else {
325
4
            return Status::InternalError("Compound operator must be AND or OR.");
326
4
        }
327
328
10.6k
        DCHECK_EQ(result_column->size(), count);
329
10.5k
        return Status::OK();
330
10.6k
    }
331
332
1.19k
    double execute_cost() const override {
333
1.19k
        double cost = 0.3;
334
1.92k
        for (const auto& child : _children) {
335
1.92k
            cost += child->execute_cost();
336
1.92k
        }
337
1.19k
        return cost;
338
1.19k
    }
339
340
private:
341
162k
    static inline constexpr uint8_t apply_and_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
342
        // (<> && false) is false, (true && NULL) is NULL
343
162k
        return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b));
344
162k
    }
345
545k
    static inline constexpr uint8_t apply_or_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
346
        // (<> || true) is true, (false || NULL) is NULL
347
545k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
348
545k
    }
349
350
    template <bool is_and>
351
493
    void static do_not_null_pred(uint8_t* __restrict lhs, uint8_t* __restrict rhs, size_t size) {
352
#ifdef NDEBUG
353
#if defined(__clang__)
354
#pragma clang loop vectorize(enable)
355
#elif defined(__GNUC__) && (__GNUC__ >= 5)
356
#pragma GCC ivdep
357
#endif
358
#endif
359
70.0k
        for (size_t i = 0; i < size; ++i) {
360
69.5k
            if constexpr (is_and) {
361
65.6k
                lhs[i] &= rhs[i];
362
65.6k
            } else {
363
3.93k
                lhs[i] |= rhs[i];
364
3.93k
            }
365
69.5k
        }
366
493
    }
_ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhS2_m
Line
Count
Source
351
394
    void static do_not_null_pred(uint8_t* __restrict lhs, uint8_t* __restrict rhs, size_t size) {
352
#ifdef NDEBUG
353
#if defined(__clang__)
354
#pragma clang loop vectorize(enable)
355
#elif defined(__GNUC__) && (__GNUC__ >= 5)
356
#pragma GCC ivdep
357
#endif
358
#endif
359
66.0k
        for (size_t i = 0; i < size; ++i) {
360
65.6k
            if constexpr (is_and) {
361
65.6k
                lhs[i] &= rhs[i];
362
            } else {
363
                lhs[i] |= rhs[i];
364
            }
365
65.6k
        }
366
394
    }
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhS2_m
Line
Count
Source
351
99
    void static do_not_null_pred(uint8_t* __restrict lhs, uint8_t* __restrict rhs, size_t size) {
352
#ifdef NDEBUG
353
#if defined(__clang__)
354
#pragma clang loop vectorize(enable)
355
#elif defined(__GNUC__) && (__GNUC__ >= 5)
356
#pragma GCC ivdep
357
#endif
358
#endif
359
4.03k
        for (size_t i = 0; i < size; ++i) {
360
            if constexpr (is_and) {
361
                lhs[i] &= rhs[i];
362
3.93k
            } else {
363
3.93k
                lhs[i] |= rhs[i];
364
3.93k
            }
365
3.93k
        }
366
99
    }
367
368
    template <bool is_and>
369
    void static do_null_pred(uint8_t* __restrict lhs_data, uint8_t* __restrict lhs_null,
370
                             uint8_t* __restrict rhs_data, uint8_t* __restrict rhs_null,
371
                             uint8_t* __restrict res_data, uint8_t* __restrict res_null,
372
1.48k
                             size_t size) {
373
#ifdef NDEBUG
374
#if defined(__clang__)
375
#pragma clang loop vectorize(enable)
376
#elif defined(__GNUC__) && (__GNUC__ >= 5)
377
#pragma GCC ivdep
378
#endif
379
#endif
380
709k
        for (size_t i = 0; i < size; ++i) {
381
707k
            if constexpr (is_and) {
382
162k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
383
162k
                res_data[i] = lhs_data[i] & rhs_data[i];
384
545k
            } else {
385
545k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
386
545k
                res_data[i] = lhs_data[i] | rhs_data[i];
387
545k
            }
388
707k
        }
389
1.48k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPhS2_S2_S2_S2_S2_m
Line
Count
Source
372
300
                             size_t size) {
373
#ifdef NDEBUG
374
#if defined(__clang__)
375
#pragma clang loop vectorize(enable)
376
#elif defined(__GNUC__) && (__GNUC__ >= 5)
377
#pragma GCC ivdep
378
#endif
379
#endif
380
162k
        for (size_t i = 0; i < size; ++i) {
381
162k
            if constexpr (is_and) {
382
162k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
383
162k
                res_data[i] = lhs_data[i] & rhs_data[i];
384
            } else {
385
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
386
                res_data[i] = lhs_data[i] | rhs_data[i];
387
            }
388
162k
        }
389
300
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPhS2_S2_S2_S2_S2_m
Line
Count
Source
372
1.18k
                             size_t size) {
373
#ifdef NDEBUG
374
#if defined(__clang__)
375
#pragma clang loop vectorize(enable)
376
#elif defined(__GNUC__) && (__GNUC__ >= 5)
377
#pragma GCC ivdep
378
#endif
379
#endif
380
546k
        for (size_t i = 0; i < size; ++i) {
381
            if constexpr (is_and) {
382
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
383
                res_data[i] = lhs_data[i] & rhs_data[i];
384
545k
            } else {
385
545k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
386
545k
                res_data[i] = lhs_data[i] | rhs_data[i];
387
545k
            }
388
545k
        }
389
1.18k
    }
390
391
10.6k
    bool _has_const_child() const {
392
10.6k
        return std::ranges::any_of(_children,
393
21.2k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
394
10.6k
    }
395
396
    std::pair<uint8_t*, uint8_t*> _get_raw_data_and_null_map(ColumnPtr column,
397
18.4k
                                                             bool has_nullable_column) const {
398
18.4k
        if (has_nullable_column) {
399
13.4k
            auto* nullable_column = assert_cast<ColumnNullable*>(column->assume_mutable().get());
400
13.4k
            auto* data_column =
401
13.4k
                    assert_cast<ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
402
13.4k
                            ->get_data()
403
13.4k
                            .data();
404
13.4k
            auto* null_map =
405
13.4k
                    assert_cast<ColumnUInt8*>(nullable_column->get_null_map_column_ptr().get())
406
13.4k
                            ->get_data()
407
13.4k
                            .data();
408
13.4k
            return std::make_pair(data_column, null_map);
409
13.4k
        } else {
410
5.00k
            auto* data_column =
411
5.00k
                    assert_cast<ColumnUInt8*>(column->assume_mutable().get())->get_data().data();
412
5.00k
            return std::make_pair(data_column, nullptr);
413
5.00k
        }
414
18.4k
    }
415
416
    TExprOpcode::type _op;
417
};
418
419
} // namespace doris