Coverage Report

Created: 2026-04-20 08:20

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.37k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
36
3.37k
    if (op == TExprOpcode::COMPOUND_AND) {
37
1.03k
        return "and";
38
2.34k
    } else if (op == TExprOpcode::COMPOUND_OR) {
39
1.71k
        return "or";
40
1.71k
    } else {
41
621
        return "not";
42
621
    }
43
3.37k
}
44
45
class VCompoundPred : public VectorizedFnCall {
46
    ENABLE_FACTORY_CREATOR(VCompoundPred);
47
48
public:
49
3.37k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
50
3.37k
        _op = node.opcode;
51
3.37k
        _fn.name.function_name = compound_operator_to_string(_op);
52
3.37k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
53
3.37k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
54
3.37k
    }
55
56
#ifdef BE_TEST
57
    VCompoundPred() = default;
58
#endif
59
60
2.04k
    const std::string& expr_name() const override { return _expr_name; }
61
62
4.25k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
63
4.25k
        segment_v2::InvertedIndexResultBitmap res;
64
4.25k
        bool all_pass = true;
65
66
4.25k
        switch (_op) {
67
2.82k
        case TExprOpcode::COMPOUND_OR: {
68
5.47k
            for (const auto& child : _children) {
69
5.47k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
70
5.47k
                    !st.ok()) {
71
159
                    LOG(ERROR) << "expr:" << child->expr_name()
72
159
                               << " evaluate_inverted_index error:" << st.to_string();
73
159
                    all_pass = false;
74
159
                    continue;
75
159
                }
76
5.31k
                auto inverted_index_context = context->get_index_context();
77
5.31k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
78
2.86k
                    const auto* index_result =
79
2.86k
                            inverted_index_context->get_index_result_for_expr(child.get());
80
2.86k
                    if (res.is_empty()) {
81
2.03k
                        res = *index_result;
82
2.03k
                    } else {
83
829
                        res |= *index_result;
84
829
                    }
85
2.86k
                    if (inverted_index_context->get_score_runtime() == nullptr) {
86
2.85k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
87
258
                            break; // Early exit if result is full
88
258
                        }
89
2.85k
                    }
90
2.86k
                } else {
91
2.45k
                    all_pass = false;
92
2.45k
                }
93
5.31k
            }
94
2.82k
            break;
95
0
        }
96
5.05k
        case TExprOpcode::COMPOUND_AND: {
97
852
            for (const auto& child : _children) {
98
852
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
99
852
                    !st.ok()) {
100
32
                    LOG(ERROR) << "expr:" << child->expr_name()
101
32
                               << " evaluate_inverted_index error:" << st.to_string();
102
32
                    all_pass = false;
103
32
                    continue;
104
32
                }
105
820
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
106
231
                    const auto* index_result =
107
231
                            context->get_index_context()->get_index_result_for_expr(child.get());
108
231
                    if (res.is_empty()) {
109
188
                        res = *index_result;
110
188
                    } else {
111
43
                        res &= *index_result;
112
43
                    }
113
114
231
                    if (res.get_data_bitmap()->isEmpty()) {
115
125
                        break; // Early exit if result is empty
116
125
                    }
117
589
                } else {
118
589
                    all_pass = false;
119
589
                }
120
820
            }
121
479
            break;
122
0
        }
123
961
        case TExprOpcode::COMPOUND_NOT: {
124
961
            const auto& child = _children[0];
125
961
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
126
961
            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
925
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
133
606
                const auto* index_result =
134
606
                        context->get_index_context()->get_index_result_for_expr(child.get());
135
606
                roaring::Roaring full_result;
136
606
                full_result.addRange(0, segment_num_rows);
137
606
                res = index_result->op_not(&full_result);
138
606
            } else {
139
319
                all_pass = false;
140
319
            }
141
925
            break;
142
961
        }
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.25k
        }
147
148
4.25k
        if (all_pass && !res.is_empty()) {
149
1.76k
            context->get_index_context()->set_index_result_for_expr(this, res);
150
1.76k
        }
151
4.25k
        return Status::OK();
152
4.25k
    }
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
96
            return Status::OK();
158
96
        }
159
11.2k
        if (get_num_children() == 1 || _has_const_child()) {
160
1.27k
            return VectorizedFnCall::execute_column(context, block, selector, count, result_column);
161
1.27k
        }
162
163
9.98k
        ColumnPtr lhs_column;
164
9.98k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
165
9.98k
        lhs_column = lhs_column->convert_to_full_column_if_const();
166
9.98k
        size_t size = lhs_column->size();
167
168
9.98k
        bool lhs_is_nullable = lhs_column->is_nullable();
169
9.98k
        auto [lhs_data_column, lhs_null_map] =
170
9.98k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
171
9.98k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
172
9.98k
        bool lhs_all_true = (filted == 0);
173
9.98k
        bool lhs_all_false = (filted == size);
174
175
9.98k
        bool lhs_all_is_not_null = false;
176
9.98k
        if (lhs_is_nullable) {
177
6.91k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
178
6.91k
            lhs_all_is_not_null = (filted == size);
179
6.91k
        }
180
181
9.98k
        ColumnPtr rhs_column = nullptr;
182
9.98k
        uint8_t* __restrict rhs_data_column = nullptr;
183
9.98k
        uint8_t* __restrict rhs_null_map = nullptr;
184
9.98k
        bool rhs_is_nullable = false;
185
9.98k
        bool rhs_all_true = false;
186
9.98k
        bool rhs_all_false = false;
187
9.98k
        bool rhs_all_is_not_null = false;
188
9.98k
        bool result_is_nullable = _data_type->is_nullable();
189
190
9.98k
        auto get_rhs_colum = [&]() {
191
7.47k
            if (!rhs_column) {
192
7.47k
                RETURN_IF_ERROR(
193
7.47k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
194
7.47k
                rhs_column = rhs_column->convert_to_full_column_if_const();
195
7.47k
                rhs_is_nullable = rhs_column->is_nullable();
196
7.47k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
197
7.47k
                rhs_data_column = rhs_nullable_column.first;
198
7.47k
                rhs_null_map = rhs_nullable_column.second;
199
7.47k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
200
7.47k
                rhs_all_true = (filted == 0);
201
7.47k
                rhs_all_false = (filted == size);
202
7.47k
                if (rhs_is_nullable) {
203
5.61k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
204
5.61k
                    rhs_all_is_not_null = (filted == size);
205
5.61k
                }
206
7.47k
            }
207
7.47k
            return Status::OK();
208
7.47k
        };
209
210
9.98k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
211
7.82k
            result_column = std::move(*arg_column).mutate();
212
7.82k
            if (result_is_nullable && !result_column->is_nullable()) {
213
535
                result_column = make_nullable(result_column);
214
535
            }
215
7.82k
        };
216
217
9.98k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
218
9.98k
                                          uint8_t* __restrict null_map_data) {
219
3.32k
            if (null_map_data == nullptr) {
220
238
                null_map_column = ColumnUInt8::create(size, 0);
221
238
                null_map_data = assert_cast<ColumnUInt8*>(null_map_column->assume_mutable().get())
222
238
                                        ->get_data()
223
238
                                        .data();
224
238
            }
225
3.32k
            return null_map_data;
226
3.32k
        };
227
228
9.98k
        auto vector_vector = [&]<bool is_and_op>() {
229
494
            if (lhs_column->use_count() == 1) {
230
488
                result_column = lhs_column;
231
488
            } 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
494
            do_not_null_pred<is_and_op>(lhs_data_column, rhs_data_column, size);
243
494
        };
_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
100
        auto vector_vector = [&]<bool is_and_op>() {
229
100
            if (lhs_column->use_count() == 1) {
230
94
                result_column = lhs_column;
231
94
            } 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
100
            do_not_null_pred<is_and_op>(lhs_data_column, rhs_data_column, size);
243
100
        };
244
9.98k
        auto vector_vector_null = [&]<bool is_and_op>() {
245
1.66k
            auto col_res = ColumnUInt8::create(size);
246
1.66k
            auto col_nulls = ColumnUInt8::create(size);
247
248
1.66k
            auto* __restrict res_datas =
249
1.66k
                    assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
250
1.66k
            auto* __restrict res_nulls =
251
1.66k
                    assert_cast<ColumnUInt8*>(col_nulls.get())->get_data().data();
252
1.66k
            ColumnPtr temp_null_map = nullptr;
253
            // maybe both children are nullable / or one of children is nullable
254
1.66k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
255
1.66k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
256
1.66k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
257
1.66k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
258
259
1.66k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
260
1.66k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
261
262
1.66k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
263
1.66k
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
244
355
        auto vector_vector_null = [&]<bool is_and_op>() {
245
355
            auto col_res = ColumnUInt8::create(size);
246
355
            auto col_nulls = ColumnUInt8::create(size);
247
248
355
            auto* __restrict res_datas =
249
355
                    assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
250
355
            auto* __restrict res_nulls =
251
355
                    assert_cast<ColumnUInt8*>(col_nulls.get())->get_data().data();
252
355
            ColumnPtr temp_null_map = nullptr;
253
            // maybe both children are nullable / or one of children is nullable
254
355
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
255
355
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
256
355
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
257
355
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
258
259
355
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
260
355
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
261
262
355
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
263
355
        };
_ZZNK5doris13VCompoundPred14execute_columnEPNS_12VExprContextEPKNS_5BlockEPNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISD_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
244
1.30k
        auto vector_vector_null = [&]<bool is_and_op>() {
245
1.30k
            auto col_res = ColumnUInt8::create(size);
246
1.30k
            auto col_nulls = ColumnUInt8::create(size);
247
248
1.30k
            auto* __restrict res_datas =
249
1.30k
                    assert_cast<ColumnUInt8*>(col_res.get())->get_data().data();
250
1.30k
            auto* __restrict res_nulls =
251
1.30k
                    assert_cast<ColumnUInt8*>(col_nulls.get())->get_data().data();
252
1.30k
            ColumnPtr temp_null_map = nullptr;
253
            // maybe both children are nullable / or one of children is nullable
254
1.30k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
255
1.30k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
256
1.30k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
257
1.30k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
258
259
1.30k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
260
1.30k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
261
262
1.30k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
263
1.30k
        };
264
265
        // false and NULL ----> 0
266
        // true  and NULL ----> NULL
267
9.98k
        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.10k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
271
                // false and any = false, return lhs
272
1.33k
                return_result_column_id(lhs_column);
273
1.77k
            } else {
274
1.77k
                RETURN_IF_ERROR(get_rhs_colum());
275
276
1.77k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
277
1.77k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
278
                                                             // true and any = any, return rhs
279
280
724
                    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
153
                    return_result_column_id(rhs_column);
285
897
                } else if ((rhs_all_true && !rhs_is_nullable) ||
286
897
                           (rhs_all_true && rhs_all_is_not_null)) {
287
                    // any and true = any, return lhs
288
148
                    return_result_column_id(lhs_column);
289
749
                } else {
290
749
                    if (!result_is_nullable) {
291
394
                        vector_vector.template operator()<true>();
292
394
                    } else {
293
355
                        vector_vector_null.template operator()<true>();
294
355
                    }
295
749
                }
296
1.77k
            }
297
6.87k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
298
            // true  or NULL ----> 1
299
            // false or NULL ----> NULL
300
6.87k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
301
                // true or any = true, return lhs
302
1.17k
                return_result_column_id(lhs_column);
303
5.70k
            } else {
304
5.70k
                RETURN_IF_ERROR(get_rhs_colum());
305
5.70k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
306
                    // false or any = any, return rhs
307
3.34k
                    return_result_column_id(rhs_column);
308
3.34k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
309
2.36k
                           (rhs_all_true && rhs_all_is_not_null)) {
310
                    // any or true = true, return rhs
311
420
                    return_result_column_id(rhs_column);
312
1.94k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
313
1.94k
                           (rhs_all_false && rhs_all_is_not_null)) {
314
                    // any or false = any, return lhs
315
535
                    return_result_column_id(lhs_column);
316
1.40k
                } else {
317
1.40k
                    if (!result_is_nullable) {
318
100
                        vector_vector.template operator()<false>();
319
1.30k
                    } else {
320
1.30k
                        vector_vector_null.template operator()<false>();
321
1.30k
                    }
322
1.40k
                }
323
5.70k
            }
324
18.4E
        } else {
325
18.4E
            return Status::InternalError("Compound operator must be AND or OR.");
326
18.4E
        }
327
328
9.98k
        DCHECK_EQ(result_column->size(), count);
329
9.98k
        return Status::OK();
330
9.98k
    }
331
332
1.39k
    double execute_cost() const override {
333
1.39k
        double cost = 0.3;
334
2.26k
        for (const auto& child : _children) {
335
2.26k
            cost += child->execute_cost();
336
2.26k
        }
337
1.39k
        return cost;
338
1.39k
    }
339
340
private:
341
163k
    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
163k
        return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b));
344
163k
    }
345
555k
    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
555k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
348
555k
    }
349
350
    template <bool is_and>
351
494
    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
494
    }
_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
100
    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
100
    }
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.66k
                             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
720k
        for (size_t i = 0; i < size; ++i) {
381
719k
            if constexpr (is_and) {
382
163k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
383
163k
                res_data[i] = lhs_data[i] & rhs_data[i];
384
555k
            } else {
385
555k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
386
555k
                res_data[i] = lhs_data[i] | rhs_data[i];
387
555k
            }
388
719k
        }
389
1.66k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPhS2_S2_S2_S2_S2_m
Line
Count
Source
372
355
                             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
163k
            if constexpr (is_and) {
382
163k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
383
163k
                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
163k
        }
389
355
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPhS2_S2_S2_S2_S2_m
Line
Count
Source
372
1.30k
                             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
557k
        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
555k
            } else {
385
555k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
386
555k
                res_data[i] = lhs_data[i] | rhs_data[i];
387
555k
            }
388
555k
        }
389
1.30k
    }
390
391
10.0k
    bool _has_const_child() const {
392
10.0k
        return std::ranges::any_of(_children,
393
20.0k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
394
10.0k
    }
395
396
    std::pair<uint8_t*, uint8_t*> _get_raw_data_and_null_map(ColumnPtr column,
397
17.4k
                                                             bool has_nullable_column) const {
398
17.4k
        if (has_nullable_column) {
399
12.5k
            auto* nullable_column = assert_cast<ColumnNullable*>(column->assume_mutable().get());
400
12.5k
            auto* data_column =
401
12.5k
                    assert_cast<ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
402
12.5k
                            ->get_data()
403
12.5k
                            .data();
404
12.5k
            auto* null_map =
405
12.5k
                    assert_cast<ColumnUInt8*>(nullable_column->get_null_map_column_ptr().get())
406
12.5k
                            ->get_data()
407
12.5k
                            .data();
408
12.5k
            return std::make_pair(data_column, null_map);
409
12.5k
        } else {
410
4.93k
            auto* data_column =
411
4.93k
                    assert_cast<ColumnUInt8*>(column->assume_mutable().get())->get_data().data();
412
4.93k
            return std::make_pair(data_column, nullptr);
413
4.93k
        }
414
17.4k
    }
415
416
    TExprOpcode::type _op;
417
};
418
419
} // namespace doris