Coverage Report

Created: 2026-04-14 10:07

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.26k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
36
3.26k
    if (op == TExprOpcode::COMPOUND_AND) {
37
1.03k
        return "and";
38
2.22k
    } else if (op == TExprOpcode::COMPOUND_OR) {
39
1.67k
        return "or";
40
1.67k
    } else {
41
553
        return "not";
42
553
    }
43
3.26k
}
44
45
class VCompoundPred : public VectorizedFnCall {
46
    ENABLE_FACTORY_CREATOR(VCompoundPred);
47
48
public:
49
3.26k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
50
3.26k
        _op = node.opcode;
51
3.26k
        _fn.name.function_name = compound_operator_to_string(_op);
52
3.26k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
53
3.26k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
54
3.26k
    }
55
56
#ifdef BE_TEST
57
    VCompoundPred() = default;
58
#endif
59
60
1.81k
    const std::string& expr_name() const override { return _expr_name; }
61
62
4.33k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
63
4.33k
        segment_v2::InvertedIndexResultBitmap res;
64
4.33k
        bool all_pass = true;
65
66
4.33k
        switch (_op) {
67
2.85k
        case TExprOpcode::COMPOUND_OR: {
68
5.53k
            for (const auto& child : _children) {
69
5.53k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
70
5.53k
                    !st.ok()) {
71
168
                    LOG(ERROR) << "expr:" << child->expr_name()
72
168
                               << " evaluate_inverted_index error:" << st.to_string();
73
168
                    all_pass = false;
74
168
                    continue;
75
168
                }
76
5.36k
                auto inverted_index_context = context->get_index_context();
77
5.36k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
78
2.93k
                    const auto* index_result =
79
2.93k
                            inverted_index_context->get_index_result_for_expr(child.get());
80
2.93k
                    if (res.is_empty()) {
81
2.06k
                        res = *index_result;
82
2.06k
                    } else {
83
864
                        res |= *index_result;
84
864
                    }
85
2.93k
                    if (inverted_index_context->get_score_runtime() == nullptr) {
86
2.93k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
87
282
                            break; // Early exit if result is full
88
282
                        }
89
2.93k
                    }
90
2.93k
                } else {
91
2.43k
                    all_pass = false;
92
2.43k
                }
93
5.36k
            }
94
2.85k
            break;
95
0
        }
96
5.08k
        case TExprOpcode::COMPOUND_AND: {
97
904
            for (const auto& child : _children) {
98
904
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
99
904
                    !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
871
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
106
216
                    const auto* index_result =
107
216
                            context->get_index_context()->get_index_result_for_expr(child.get());
108
216
                    if (res.is_empty()) {
109
173
                        res = *index_result;
110
173
                    } else {
111
43
                        res &= *index_result;
112
43
                    }
113
114
216
                    if (res.get_data_bitmap()->isEmpty()) {
115
115
                        break; // Early exit if result is empty
116
115
                    }
117
655
                } else {
118
655
                    all_pass = false;
119
655
                }
120
871
            }
121
502
            break;
122
0
        }
123
982
        case TExprOpcode::COMPOUND_NOT: {
124
982
            const auto& child = _children[0];
125
982
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
126
982
            if (!st.ok()) {
127
39
                LOG(ERROR) << "expr:" << child->expr_name()
128
39
                           << " evaluate_inverted_index error:" << st.to_string();
129
39
                return st;
130
39
            }
131
132
943
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
133
620
                const auto* index_result =
134
620
                        context->get_index_context()->get_index_result_for_expr(child.get());
135
620
                roaring::Roaring full_result;
136
620
                full_result.addRange(0, segment_num_rows);
137
620
                res = index_result->op_not(&full_result);
138
620
            } else {
139
323
                all_pass = false;
140
323
            }
141
943
            break;
142
982
        }
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.33k
        }
147
148
4.31k
        if (all_pass && !res.is_empty()) {
149
1.81k
            context->get_index_context()->set_index_result_for_expr(this, res);
150
1.81k
        }
151
4.31k
        return Status::OK();
152
4.33k
    }
153
154
    Status execute_column(VExprContext* context, const Block* block, Selector* selector,
155
11.3k
                          size_t count, ColumnPtr& result_column) const override {
156
11.3k
        if (fast_execute(context, selector, count, result_column)) {
157
89
            return Status::OK();
158
89
        }
159
11.2k
        if (get_num_children() == 1 || _has_const_child()) {
160
1.07k
            return VectorizedFnCall::execute_column(context, block, selector, count, result_column);
161
1.07k
        }
162
163
10.1k
        ColumnPtr lhs_column;
164
10.1k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
165
10.1k
        lhs_column = lhs_column->convert_to_full_column_if_const();
166
10.1k
        size_t size = lhs_column->size();
167
168
10.1k
        bool lhs_is_nullable = lhs_column->is_nullable();
169
10.1k
        auto [lhs_data_column, lhs_null_map] =
170
10.1k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
171
10.1k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
172
10.1k
        bool lhs_all_true = (filted == 0);
173
10.1k
        bool lhs_all_false = (filted == size);
174
175
10.1k
        bool lhs_all_is_not_null = false;
176
10.1k
        if (lhs_is_nullable) {
177
7.30k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
178
7.30k
            lhs_all_is_not_null = (filted == size);
179
7.30k
        }
180
181
10.1k
        ColumnPtr rhs_column = nullptr;
182
10.1k
        uint8_t* __restrict rhs_data_column = nullptr;
183
10.1k
        uint8_t* __restrict rhs_null_map = nullptr;
184
10.1k
        bool rhs_is_nullable = false;
185
10.1k
        bool rhs_all_true = false;
186
10.1k
        bool rhs_all_false = false;
187
10.1k
        bool rhs_all_is_not_null = false;
188
10.1k
        bool result_is_nullable = _data_type->is_nullable();
189
190
10.1k
        auto get_rhs_colum = [&]() {
191
7.57k
            if (!rhs_column) {
192
7.57k
                RETURN_IF_ERROR(
193
7.57k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
194
7.57k
                rhs_column = rhs_column->convert_to_full_column_if_const();
195
7.57k
                rhs_is_nullable = rhs_column->is_nullable();
196
7.57k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
197
7.57k
                rhs_data_column = rhs_nullable_column.first;
198
7.57k
                rhs_null_map = rhs_nullable_column.second;
199
7.57k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
200
7.57k
                rhs_all_true = (filted == 0);
201
7.57k
                rhs_all_false = (filted == size);
202
7.57k
                if (rhs_is_nullable) {
203
5.81k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
204
5.81k
                    rhs_all_is_not_null = (filted == size);
205
5.81k
                }
206
7.57k
            }
207
7.57k
            return Status::OK();
208
7.57k
        };
209
210
10.1k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
211
8.18k
            result_column = std::move(*arg_column).mutate();
212
8.18k
            if (result_is_nullable && !result_column->is_nullable()) {
213
575
                result_column = make_nullable(result_column);
214
575
            }
215
8.18k
        };
216
217
10.1k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
218
10.1k
                                          uint8_t* __restrict null_map_data) {
219
3.10k
            if (null_map_data == nullptr) {
220
223
                null_map_column = ColumnUInt8::create(size, 0);
221
223
                null_map_data = assert_cast<ColumnUInt8*>(null_map_column->assume_mutable().get())
222
223
                                        ->get_data()
223
223
                                        .data();
224
223
            }
225
3.10k
            return null_map_data;
226
3.10k
        };
227
228
10.1k
        auto vector_vector = [&]<bool is_and_op>() {
229
438
            if (lhs_column->use_count() == 1) {
230
433
                result_column = lhs_column;
231
433
            } 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
4
            } else {
237
4
                auto col_res = lhs_column->clone_resized(size);
238
4
                lhs_data_column = assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
239
4
                result_column = std::move(col_res);
240
4
            }
241
242
438
            do_not_null_pred<is_and_op>(lhs_data_column, rhs_data_column, size);
243
438
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE_clILb1EEEDav
Line
Count
Source
228
341
        auto vector_vector = [&]<bool is_and_op>() {
229
342
            if (lhs_column->use_count() == 1) {
230
342
                result_column = lhs_column;
231
18.4E
            } 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
18.4E
            } else {
237
18.4E
                auto col_res = lhs_column->clone_resized(size);
238
18.4E
                lhs_data_column = assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
239
18.4E
                result_column = std::move(col_res);
240
18.4E
            }
241
242
341
            do_not_null_pred<is_and_op>(lhs_data_column, rhs_data_column, size);
243
341
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE_clILb0EEEDav
Line
Count
Source
228
97
        auto vector_vector = [&]<bool is_and_op>() {
229
97
            if (lhs_column->use_count() == 1) {
230
91
                result_column = lhs_column;
231
91
            } 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
97
            do_not_null_pred<is_and_op>(lhs_data_column, rhs_data_column, size);
243
97
        };
244
10.1k
        auto vector_vector_null = [&]<bool is_and_op>() {
245
1.55k
            auto col_res = ColumnUInt8::create(size);
246
1.55k
            auto col_nulls = ColumnUInt8::create(size);
247
248
1.55k
            auto* __restrict res_datas =
249
1.55k
                    assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
250
1.55k
            auto* __restrict res_nulls =
251
1.55k
                    assert_cast<ColumnUInt8*>(col_nulls.get())->get_data().data();
252
1.55k
            ColumnPtr temp_null_map = nullptr;
253
            // maybe both children are nullable / or one of children is nullable
254
1.55k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
255
1.55k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
256
1.55k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
257
1.55k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
258
259
1.55k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
260
1.55k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
261
262
1.55k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
263
1.55k
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
244
317
        auto vector_vector_null = [&]<bool is_and_op>() {
245
317
            auto col_res = ColumnUInt8::create(size);
246
317
            auto col_nulls = ColumnUInt8::create(size);
247
248
317
            auto* __restrict res_datas =
249
317
                    assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
250
317
            auto* __restrict res_nulls =
251
317
                    assert_cast<ColumnUInt8*>(col_nulls.get())->get_data().data();
252
317
            ColumnPtr temp_null_map = nullptr;
253
            // maybe both children are nullable / or one of children is nullable
254
317
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
255
317
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
256
317
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
257
317
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
258
259
317
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
260
317
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
261
262
317
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
263
317
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
244
1.23k
        auto vector_vector_null = [&]<bool is_and_op>() {
245
1.23k
            auto col_res = ColumnUInt8::create(size);
246
1.23k
            auto col_nulls = ColumnUInt8::create(size);
247
248
1.23k
            auto* __restrict res_datas =
249
1.23k
                    assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
250
1.23k
            auto* __restrict res_nulls =
251
1.23k
                    assert_cast<ColumnUInt8*>(col_nulls.get())->get_data().data();
252
1.23k
            ColumnPtr temp_null_map = nullptr;
253
            // maybe both children are nullable / or one of children is nullable
254
1.23k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
255
1.23k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
256
1.23k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
257
1.23k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
258
259
1.23k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
260
1.23k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
261
262
1.23k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
263
1.23k
        };
264
265
        // false and NULL ----> 0
266
        // true  and NULL ----> NULL
267
10.1k
        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
2.98k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
271
                // false and any = false, return lhs
272
1.25k
                return_result_column_id(lhs_column);
273
1.72k
            } else {
274
1.72k
                RETURN_IF_ERROR(get_rhs_colum());
275
276
1.72k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
277
1.72k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
278
                                                             // true and any = any, return rhs
279
280
705
                    return_result_column_id(rhs_column);
281
1.02k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
282
1.02k
                           (rhs_all_false && rhs_all_is_not_null)) {
283
                    // any and false = false, return rhs
284
180
                    return_result_column_id(rhs_column);
285
842
                } else if ((rhs_all_true && !rhs_is_nullable) ||
286
842
                           (rhs_all_true && rhs_all_is_not_null)) {
287
                    // any and true = any, return lhs
288
183
                    return_result_column_id(lhs_column);
289
659
                } else {
290
659
                    if (!result_is_nullable) {
291
342
                        vector_vector.template operator()<true>();
292
342
                    } else {
293
317
                        vector_vector_null.template operator()<true>();
294
317
                    }
295
659
                }
296
1.72k
            }
297
7.19k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
298
            // true  or NULL ----> 1
299
            // false or NULL ----> NULL
300
7.19k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
301
                // true or any = true, return lhs
302
1.34k
                return_result_column_id(lhs_column);
303
5.84k
            } else {
304
5.84k
                RETURN_IF_ERROR(get_rhs_colum());
305
5.84k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
306
                    // false or any = any, return rhs
307
3.50k
                    return_result_column_id(rhs_column);
308
3.50k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
309
2.33k
                           (rhs_all_true && rhs_all_is_not_null)) {
310
                    // any or true = true, return rhs
311
462
                    return_result_column_id(rhs_column);
312
1.87k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
313
1.87k
                           (rhs_all_false && rhs_all_is_not_null)) {
314
                    // any or false = any, return lhs
315
545
                    return_result_column_id(lhs_column);
316
1.33k
                } else {
317
1.33k
                    if (!result_is_nullable) {
318
97
                        vector_vector.template operator()<false>();
319
1.23k
                    } else {
320
1.23k
                        vector_vector_null.template operator()<false>();
321
1.23k
                    }
322
1.33k
                }
323
5.84k
            }
324
7.19k
        } else {
325
0
            return Status::InternalError("Compound operator must be AND or OR.");
326
0
        }
327
328
10.1k
        DCHECK_EQ(result_column->size(), count);
329
10.1k
        return Status::OK();
330
10.1k
    }
331
332
1.47k
    double execute_cost() const override {
333
1.47k
        double cost = 0.3;
334
2.27k
        for (const auto& child : _children) {
335
2.27k
            cost += child->execute_cost();
336
2.27k
        }
337
1.47k
        return cost;
338
1.47k
    }
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
551k
    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
551k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
348
551k
    }
349
350
    template <bool is_and>
351
439
    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.6k
        for (size_t i = 0; i < size; ++i) {
360
70.1k
            if constexpr (is_and) {
361
65.9k
                lhs[i] &= rhs[i];
362
65.9k
            } else {
363
4.19k
                lhs[i] |= rhs[i];
364
4.19k
            }
365
70.1k
        }
366
439
    }
_ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhS2_m
Line
Count
Source
351
342
    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.3k
        for (size_t i = 0; i < size; ++i) {
360
65.9k
            if constexpr (is_and) {
361
65.9k
                lhs[i] &= rhs[i];
362
            } else {
363
                lhs[i] |= rhs[i];
364
            }
365
65.9k
        }
366
342
    }
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhS2_m
Line
Count
Source
351
97
    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.29k
        for (size_t i = 0; i < size; ++i) {
360
            if constexpr (is_and) {
361
                lhs[i] &= rhs[i];
362
4.19k
            } else {
363
4.19k
                lhs[i] |= rhs[i];
364
4.19k
            }
365
4.19k
        }
366
97
    }
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.55k
                             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
715k
        for (size_t i = 0; i < size; ++i) {
381
714k
            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
551k
            } else {
385
551k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
386
551k
                res_data[i] = lhs_data[i] | rhs_data[i];
387
551k
            }
388
714k
        }
389
1.55k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPhS2_S2_S2_S2_S2_m
Line
Count
Source
372
317
                             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
163k
        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
317
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPhS2_S2_S2_S2_S2_m
Line
Count
Source
372
1.23k
                             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
552k
        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
551k
            } else {
385
551k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
386
551k
                res_data[i] = lhs_data[i] | rhs_data[i];
387
551k
            }
388
551k
        }
389
1.23k
    }
390
391
10.2k
    bool _has_const_child() const {
392
10.2k
        return std::ranges::any_of(_children,
393
20.3k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
394
10.2k
    }
395
396
    std::pair<uint8_t*, uint8_t*> _get_raw_data_and_null_map(ColumnPtr column,
397
17.7k
                                                             bool has_nullable_column) const {
398
17.7k
        if (has_nullable_column) {
399
13.1k
            auto* nullable_column = assert_cast<ColumnNullable*>(column->assume_mutable().get());
400
13.1k
            auto* data_column =
401
13.1k
                    assert_cast<ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
402
13.1k
                            ->get_data()
403
13.1k
                            .data();
404
13.1k
            auto* null_map =
405
13.1k
                    assert_cast<ColumnUInt8*>(nullable_column->get_null_map_column_ptr().get())
406
13.1k
                            ->get_data()
407
13.1k
                            .data();
408
13.1k
            return std::make_pair(data_column, null_map);
409
13.1k
        } else {
410
4.62k
            auto* data_column =
411
4.62k
                    assert_cast<ColumnUInt8*>(column->assume_mutable().get())->get_data().data();
412
4.62k
            return std::make_pair(data_column, nullptr);
413
4.62k
        }
414
17.7k
    }
415
416
    TExprOpcode::type _op;
417
};
418
419
} // namespace doris