Coverage Report

Created: 2026-07-02 15:50

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/logging.h"
25
#include "common/status.h"
26
#include "core/assert_cast.h"
27
#include "core/column/column.h"
28
#include "core/column/column_nullable.h"
29
#include "exprs/vectorized_fn_call.h"
30
#include "exprs/vexpr_context.h"
31
#include "exprs/vexpr_fwd.h"
32
#include "storage/index/zone_map/zonemap_eval_context.h"
33
#include "util/simd/bits.h"
34
35
namespace doris {
36
37
4.92k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
38
4.92k
    if (op == TExprOpcode::COMPOUND_AND) {
39
923
        return "and";
40
3.99k
    } else if (op == TExprOpcode::COMPOUND_OR) {
41
3.43k
        return "or";
42
3.43k
    } else {
43
565
        return "not";
44
565
    }
45
4.92k
}
46
47
class VCompoundPred : public VectorizedFnCall {
48
    ENABLE_FACTORY_CREATOR(VCompoundPred);
49
50
public:
51
4.92k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
52
4.92k
        _op = node.opcode;
53
4.92k
        _fn.name.function_name = compound_operator_to_string(_op);
54
4.92k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
55
4.92k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
56
4.92k
    }
57
58
#ifdef BE_TEST
59
    VCompoundPred() = default;
60
#endif
61
62
11.8k
    const std::string& expr_name() const override { return _expr_name; }
63
0
    Status clone_node(VExprSPtr* cloned_expr) const override {
64
0
        DORIS_CHECK(cloned_expr != nullptr);
65
0
        *cloned_expr = VCompoundPred::create_shared(clone_texpr_node());
66
0
        return Status::OK();
67
0
    }
68
69
14.9k
    bool can_evaluate_zonemap_filter() const override {
70
14.9k
        switch (_op) {
71
2.53k
        case TExprOpcode::COMPOUND_AND:
72
3.16k
            return std::ranges::any_of(_children, [](const VExprSPtr& child) {
73
3.16k
                return child->can_evaluate_zonemap_filter();
74
3.16k
            });
75
9.18k
        case TExprOpcode::COMPOUND_OR:
76
14.9k
            return !_children.empty() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
77
14.9k
                return child->can_evaluate_zonemap_filter();
78
14.9k
            });
79
3.16k
        case TExprOpcode::COMPOUND_NOT:
80
3.16k
            return false;
81
0
        default:
82
0
            return false;
83
14.9k
        }
84
14.9k
    }
85
86
2.63k
    ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const override {
87
2.63k
        switch (_op) {
88
365
        case TExprOpcode::COMPOUND_AND: {
89
659
            for (const auto& child : _children) {
90
659
                if (!child->can_evaluate_zonemap_filter()) {
91
89
                    continue;
92
89
                }
93
570
                if (child->evaluate_zonemap_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
94
130
                    return ZoneMapFilterResult::kNoMatch;
95
130
                }
96
570
            }
97
235
            return ZoneMapFilterResult::kMayMatch;
98
365
        }
99
2.27k
        case TExprOpcode::COMPOUND_OR: {
100
3.82k
            for (const auto& child : _children) {
101
3.82k
                DORIS_CHECK(child->can_evaluate_zonemap_filter());
102
3.82k
                if (child->evaluate_zonemap_filter(ctx) != ZoneMapFilterResult::kNoMatch) {
103
1.93k
                    return ZoneMapFilterResult::kMayMatch;
104
1.93k
                }
105
3.82k
            }
106
339
            return ZoneMapFilterResult::kNoMatch;
107
2.27k
        }
108
1
        case TExprOpcode::COMPOUND_NOT:
109
1
            return unsupported_zonemap_filter(ctx);
110
0
        default:
111
0
            return unsupported_zonemap_filter(ctx);
112
2.63k
        }
113
2.63k
    }
114
115
5.07k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
116
5.07k
        segment_v2::InvertedIndexResultBitmap res;
117
5.07k
        bool all_pass = true;
118
119
5.07k
        switch (_op) {
120
3.06k
        case TExprOpcode::COMPOUND_OR: {
121
5.92k
            for (const auto& child : _children) {
122
5.92k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
123
5.92k
                    !st.ok()) {
124
174
                    LOG(ERROR) << "expr:" << child->expr_name()
125
174
                               << " evaluate_inverted_index error:" << st.to_string();
126
174
                    all_pass = false;
127
174
                    continue;
128
174
                }
129
5.74k
                auto inverted_index_context = context->get_index_context();
130
5.74k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
131
3.02k
                    const auto* index_result =
132
3.02k
                            inverted_index_context->get_index_result_for_expr(child.get());
133
3.02k
                    if (res.is_empty()) {
134
2.04k
                        res = *index_result;
135
2.04k
                    } else {
136
985
                        res |= *index_result;
137
985
                    }
138
3.02k
                    if (inverted_index_context->get_score_runtime() == nullptr) {
139
3.02k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
140
348
                            break; // Early exit if result is full
141
348
                        }
142
3.02k
                    }
143
3.02k
                } else {
144
2.72k
                    all_pass = false;
145
2.72k
                }
146
5.74k
            }
147
3.06k
            break;
148
0
        }
149
5.40k
        case TExprOpcode::COMPOUND_AND: {
150
1.34k
            for (const auto& child : _children) {
151
1.34k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
152
1.34k
                    !st.ok()) {
153
26
                    LOG(ERROR) << "expr:" << child->expr_name()
154
26
                               << " evaluate_inverted_index error:" << st.to_string();
155
26
                    all_pass = false;
156
26
                    continue;
157
26
                }
158
1.32k
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
159
241
                    const auto* index_result =
160
241
                            context->get_index_context()->get_index_result_for_expr(child.get());
161
241
                    if (res.is_empty()) {
162
181
                        res = *index_result;
163
181
                    } else {
164
60
                        res &= *index_result;
165
60
                    }
166
167
241
                    if (res.get_data_bitmap()->isEmpty()) {
168
92
                        break; // Early exit if result is empty
169
92
                    }
170
1.08k
                } else {
171
1.08k
                    all_pass = false;
172
1.08k
                }
173
1.32k
            }
174
719
            break;
175
0
        }
176
1.29k
        case TExprOpcode::COMPOUND_NOT: {
177
1.29k
            const auto& child = _children[0];
178
1.29k
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
179
1.29k
            if (!st.ok()) {
180
39
                LOG(ERROR) << "expr:" << child->expr_name()
181
39
                           << " evaluate_inverted_index error:" << st.to_string();
182
39
                return st;
183
39
            }
184
185
1.25k
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
186
719
                const auto* index_result =
187
719
                        context->get_index_context()->get_index_result_for_expr(child.get());
188
719
                roaring::Roaring full_result;
189
719
                full_result.addRange(0, segment_num_rows);
190
719
                res = index_result->op_not(&full_result);
191
719
            } else {
192
538
                all_pass = false;
193
538
            }
194
1.25k
            break;
195
1.29k
        }
196
0
        default:
197
0
            return Status::NotSupported(
198
0
                    "Compound operator must be AND, OR, or NOT to execute with inverted index.");
199
5.07k
        }
200
201
5.07k
        if (all_pass && !res.is_empty()) {
202
2.06k
            context->get_index_context()->set_index_result_for_expr(this, res);
203
2.06k
        }
204
5.07k
        return Status::OK();
205
5.07k
    }
206
207
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
208
23.3k
                               size_t count, ColumnPtr& result_column) const override {
209
23.3k
        if (fast_execute(context, selector, count, result_column)) {
210
101
            return Status::OK();
211
101
        }
212
23.2k
        if (get_num_children() == 1 || _has_const_child()) {
213
1.06k
            return VectorizedFnCall::execute_column_impl(context, block, selector, count,
214
1.06k
                                                         result_column);
215
1.06k
        }
216
217
22.1k
        ColumnPtr lhs_column;
218
22.1k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
219
22.1k
        lhs_column = lhs_column->convert_to_full_column_if_const();
220
22.1k
        size_t size = lhs_column->size();
221
222
22.1k
        bool lhs_is_nullable = lhs_column->is_nullable();
223
22.1k
        auto [lhs_data_column, lhs_null_map] =
224
22.1k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
225
22.1k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
226
22.1k
        bool lhs_all_true = (filted == 0);
227
22.1k
        bool lhs_all_false = (filted == size);
228
229
22.1k
        bool lhs_all_is_not_null = false;
230
22.1k
        if (lhs_is_nullable) {
231
12.1k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
232
12.1k
            lhs_all_is_not_null = (filted == size);
233
12.1k
        }
234
235
22.1k
        ColumnPtr rhs_column = nullptr;
236
22.1k
        const uint8_t* __restrict rhs_data_column = nullptr;
237
22.1k
        const uint8_t* __restrict rhs_null_map = nullptr;
238
22.1k
        bool rhs_is_nullable = false;
239
22.1k
        bool rhs_all_true = false;
240
22.1k
        bool rhs_all_false = false;
241
22.1k
        bool rhs_all_is_not_null = false;
242
22.1k
        bool result_is_nullable = _data_type->is_nullable();
243
244
22.1k
        auto get_rhs_colum = [&]() {
245
16.3k
            if (!rhs_column) {
246
16.3k
                RETURN_IF_ERROR(
247
16.3k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
248
16.3k
                rhs_column = rhs_column->convert_to_full_column_if_const();
249
16.3k
                rhs_is_nullable = rhs_column->is_nullable();
250
16.3k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
251
16.3k
                rhs_data_column = rhs_nullable_column.first;
252
16.3k
                rhs_null_map = rhs_nullable_column.second;
253
16.3k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
254
16.3k
                rhs_all_true = (filted == 0);
255
16.3k
                rhs_all_false = (filted == size);
256
16.3k
                if (rhs_is_nullable) {
257
11.7k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
258
11.7k
                    rhs_all_is_not_null = (filted == size);
259
11.7k
                }
260
16.3k
            }
261
16.3k
            return Status::OK();
262
16.3k
        };
263
264
22.1k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
265
18.0k
            result_column = std::move(*arg_column).mutate();
266
18.0k
            if (result_is_nullable && !result_column->is_nullable()) {
267
2.76k
                result_column = make_nullable(result_column);
268
2.76k
            }
269
18.0k
        };
270
271
22.1k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
272
22.1k
                                          const uint8_t* __restrict null_map_data) {
273
7.18k
            if (null_map_data == nullptr) {
274
587
                null_map_column = ColumnUInt8::create(size, 0);
275
587
                null_map_data =
276
587
                        assert_cast<const ColumnUInt8*>(null_map_column.get())->get_data().data();
277
587
            }
278
7.18k
            return null_map_data;
279
7.18k
        };
280
281
22.1k
        auto vector_vector = [&]<bool is_and_op>() {
282
530
            MutableColumnPtr mutable_result_column;
283
530
            uint8_t* __restrict result_data_column = nullptr;
284
530
            const uint8_t* __restrict other_data_column = rhs_data_column;
285
530
            if (lhs_column->use_count() == 1) {
286
530
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
287
530
                result_data_column =
288
530
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
289
530
            } else if (rhs_column->use_count() == 1) {
290
1
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
291
1
                result_data_column =
292
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
293
1
                other_data_column = lhs_data_column;
294
18.4E
            } else {
295
18.4E
                mutable_result_column = lhs_column->clone_resized(size);
296
18.4E
                result_data_column =
297
18.4E
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
298
18.4E
            }
299
300
530
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
301
530
            result_column = std::move(mutable_result_column);
302
530
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb1EEEDav
Line
Count
Source
281
406
        auto vector_vector = [&]<bool is_and_op>() {
282
406
            MutableColumnPtr mutable_result_column;
283
406
            uint8_t* __restrict result_data_column = nullptr;
284
406
            const uint8_t* __restrict other_data_column = rhs_data_column;
285
408
            if (lhs_column->use_count() == 1) {
286
408
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
287
408
                result_data_column =
288
408
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
289
18.4E
            } else if (rhs_column->use_count() == 1) {
290
0
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
291
0
                result_data_column =
292
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
293
0
                other_data_column = lhs_data_column;
294
18.4E
            } else {
295
18.4E
                mutable_result_column = lhs_column->clone_resized(size);
296
18.4E
                result_data_column =
297
18.4E
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
298
18.4E
            }
299
300
406
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
301
406
            result_column = std::move(mutable_result_column);
302
406
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb0EEEDav
Line
Count
Source
281
124
        auto vector_vector = [&]<bool is_and_op>() {
282
124
            MutableColumnPtr mutable_result_column;
283
124
            uint8_t* __restrict result_data_column = nullptr;
284
124
            const uint8_t* __restrict other_data_column = rhs_data_column;
285
124
            if (lhs_column->use_count() == 1) {
286
122
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
287
122
                result_data_column =
288
122
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
289
122
            } else if (rhs_column->use_count() == 1) {
290
1
                mutable_result_column = IColumn::mutate(std::move(rhs_column));
291
1
                result_data_column =
292
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
293
1
                other_data_column = lhs_data_column;
294
1
            } else {
295
1
                mutable_result_column = lhs_column->clone_resized(size);
296
1
                result_data_column =
297
1
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
298
1
            }
299
300
124
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
301
124
            result_column = std::move(mutable_result_column);
302
124
        };
303
22.1k
        auto vector_vector_null = [&]<bool is_and_op>() {
304
3.59k
            auto col_res = ColumnUInt8::create(size);
305
3.59k
            auto col_nulls = ColumnUInt8::create(size);
306
307
3.59k
            auto* __restrict res_datas = col_res->get_data().data();
308
3.59k
            auto* __restrict res_nulls = col_nulls->get_data().data();
309
3.59k
            ColumnPtr temp_null_map = nullptr;
310
            // maybe both children are nullable / or one of children is nullable
311
3.59k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
312
3.59k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
313
3.59k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
314
3.59k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
315
316
3.59k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
317
3.59k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
318
319
3.59k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
320
3.59k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
303
460
        auto vector_vector_null = [&]<bool is_and_op>() {
304
460
            auto col_res = ColumnUInt8::create(size);
305
460
            auto col_nulls = ColumnUInt8::create(size);
306
307
460
            auto* __restrict res_datas = col_res->get_data().data();
308
460
            auto* __restrict res_nulls = col_nulls->get_data().data();
309
460
            ColumnPtr temp_null_map = nullptr;
310
            // maybe both children are nullable / or one of children is nullable
311
460
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
312
460
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
313
460
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
314
460
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
315
316
460
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
317
460
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
318
319
460
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
320
460
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
303
3.13k
        auto vector_vector_null = [&]<bool is_and_op>() {
304
3.13k
            auto col_res = ColumnUInt8::create(size);
305
3.13k
            auto col_nulls = ColumnUInt8::create(size);
306
307
3.13k
            auto* __restrict res_datas = col_res->get_data().data();
308
3.13k
            auto* __restrict res_nulls = col_nulls->get_data().data();
309
3.13k
            ColumnPtr temp_null_map = nullptr;
310
            // maybe both children are nullable / or one of children is nullable
311
3.13k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
312
3.13k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
313
3.13k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
314
3.13k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
315
316
3.13k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
317
3.13k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
318
319
3.13k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
320
3.13k
        };
321
322
        // false and NULL ----> 0
323
        // true  and NULL ----> NULL
324
22.1k
        if (_op == TExprOpcode::COMPOUND_AND) {
325
            //1. not null column: all data is false
326
            //2. nullable column: null map all is not null
327
4.00k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
328
                // false and any = false, return lhs
329
2.00k
                return_result_column_id(lhs_column);
330
2.00k
            } else {
331
2.00k
                RETURN_IF_ERROR(get_rhs_colum());
332
333
2.00k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
334
2.00k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
335
                                                             // true and any = any, return rhs
336
337
709
                    return_result_column_id(rhs_column);
338
1.29k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
339
1.29k
                           (rhs_all_false && rhs_all_is_not_null)) {
340
                    // any and false = false, return rhs
341
187
                    return_result_column_id(rhs_column);
342
1.10k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
343
1.10k
                           (rhs_all_true && rhs_all_is_not_null)) {
344
                    // any and true = any, return lhs
345
238
                    return_result_column_id(lhs_column);
346
868
                } else {
347
868
                    if (!result_is_nullable) {
348
408
                        vector_vector.template operator()<true>();
349
460
                    } else {
350
460
                        vector_vector_null.template operator()<true>();
351
460
                    }
352
868
                }
353
2.00k
            }
354
18.1k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
355
            // true  or NULL ----> 1
356
            // false or NULL ----> NULL
357
18.1k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
358
                // true or any = true, return lhs
359
3.76k
                return_result_column_id(lhs_column);
360
14.3k
            } else {
361
14.3k
                RETURN_IF_ERROR(get_rhs_colum());
362
14.3k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
363
                    // false or any = any, return rhs
364
9.87k
                    return_result_column_id(rhs_column);
365
9.87k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
366
4.51k
                           (rhs_all_true && rhs_all_is_not_null)) {
367
                    // any or true = true, return rhs
368
720
                    return_result_column_id(rhs_column);
369
3.79k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
370
3.79k
                           (rhs_all_false && rhs_all_is_not_null)) {
371
                    // any or false = any, return lhs
372
537
                    return_result_column_id(lhs_column);
373
3.25k
                } else {
374
3.25k
                    if (!result_is_nullable) {
375
124
                        vector_vector.template operator()<false>();
376
3.13k
                    } else {
377
3.13k
                        vector_vector_null.template operator()<false>();
378
3.13k
                    }
379
3.25k
                }
380
14.3k
            }
381
18.4E
        } else {
382
18.4E
            return Status::InternalError("Compound operator must be AND or OR.");
383
18.4E
        }
384
385
22.1k
        DCHECK_EQ(result_column->size(), count);
386
22.1k
        return Status::OK();
387
22.1k
    }
388
389
1.00k
    double execute_cost() const override {
390
1.00k
        double cost = 0.3;
391
1.58k
        for (const auto& child : _children) {
392
1.58k
            cost += child->execute_cost();
393
1.58k
        }
394
1.00k
        return cost;
395
1.00k
    }
396
397
private:
398
4.73k
    static inline constexpr uint8_t apply_and_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
399
        // (<> && false) is false, (true && NULL) is NULL
400
4.73k
        return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b));
401
4.73k
    }
402
50.0k
    static inline constexpr uint8_t apply_or_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) {
403
        // (<> || true) is true, (false || NULL) is NULL
404
50.0k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
405
50.0k
    }
406
407
    template <bool is_and>
408
    void static do_not_null_pred(uint8_t* __restrict lhs, const uint8_t* __restrict rhs,
409
532
                                 size_t size) {
410
#ifdef NDEBUG
411
#if defined(__clang__)
412
#pragma clang loop vectorize(enable)
413
#elif defined(__GNUC__) && (__GNUC__ >= 5)
414
#pragma GCC ivdep
415
#endif
416
#endif
417
14.4k
        for (size_t i = 0; i < size; ++i) {
418
13.9k
            if constexpr (is_and) {
419
9.97k
                lhs[i] &= rhs[i];
420
9.97k
            } else {
421
3.94k
                lhs[i] |= rhs[i];
422
3.94k
            }
423
13.9k
        }
424
532
    }
_ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhPKhm
Line
Count
Source
409
408
                                 size_t size) {
410
#ifdef NDEBUG
411
#if defined(__clang__)
412
#pragma clang loop vectorize(enable)
413
#elif defined(__GNUC__) && (__GNUC__ >= 5)
414
#pragma GCC ivdep
415
#endif
416
#endif
417
10.3k
        for (size_t i = 0; i < size; ++i) {
418
9.97k
            if constexpr (is_and) {
419
9.97k
                lhs[i] &= rhs[i];
420
            } else {
421
                lhs[i] |= rhs[i];
422
            }
423
9.97k
        }
424
408
    }
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhPKhm
Line
Count
Source
409
124
                                 size_t size) {
410
#ifdef NDEBUG
411
#if defined(__clang__)
412
#pragma clang loop vectorize(enable)
413
#elif defined(__GNUC__) && (__GNUC__ >= 5)
414
#pragma GCC ivdep
415
#endif
416
#endif
417
4.06k
        for (size_t i = 0; i < size; ++i) {
418
            if constexpr (is_and) {
419
                lhs[i] &= rhs[i];
420
3.94k
            } else {
421
3.94k
                lhs[i] |= rhs[i];
422
3.94k
            }
423
3.94k
        }
424
124
    }
425
426
    template <bool is_and>
427
    void static do_null_pred(const uint8_t* __restrict lhs_data, const uint8_t* __restrict lhs_null,
428
                             const uint8_t* __restrict rhs_data, const uint8_t* __restrict rhs_null,
429
                             uint8_t* __restrict res_data, uint8_t* __restrict res_null,
430
3.59k
                             size_t size) {
431
#ifdef NDEBUG
432
#if defined(__clang__)
433
#pragma clang loop vectorize(enable)
434
#elif defined(__GNUC__) && (__GNUC__ >= 5)
435
#pragma GCC ivdep
436
#endif
437
#endif
438
58.3k
        for (size_t i = 0; i < size; ++i) {
439
54.7k
            if constexpr (is_and) {
440
4.73k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
441
4.73k
                res_data[i] = lhs_data[i] & rhs_data[i];
442
50.0k
            } else {
443
50.0k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
444
50.0k
                res_data[i] = lhs_data[i] | rhs_data[i];
445
50.0k
            }
446
54.7k
        }
447
3.59k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
430
460
                             size_t size) {
431
#ifdef NDEBUG
432
#if defined(__clang__)
433
#pragma clang loop vectorize(enable)
434
#elif defined(__GNUC__) && (__GNUC__ >= 5)
435
#pragma GCC ivdep
436
#endif
437
#endif
438
5.19k
        for (size_t i = 0; i < size; ++i) {
439
4.73k
            if constexpr (is_and) {
440
4.73k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
441
4.73k
                res_data[i] = lhs_data[i] & rhs_data[i];
442
            } else {
443
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
444
                res_data[i] = lhs_data[i] | rhs_data[i];
445
            }
446
4.73k
        }
447
460
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
430
3.13k
                             size_t size) {
431
#ifdef NDEBUG
432
#if defined(__clang__)
433
#pragma clang loop vectorize(enable)
434
#elif defined(__GNUC__) && (__GNUC__ >= 5)
435
#pragma GCC ivdep
436
#endif
437
#endif
438
53.1k
        for (size_t i = 0; i < size; ++i) {
439
            if constexpr (is_and) {
440
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
441
                res_data[i] = lhs_data[i] & rhs_data[i];
442
50.0k
            } else {
443
50.0k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
444
50.0k
                res_data[i] = lhs_data[i] | rhs_data[i];
445
50.0k
            }
446
50.0k
        }
447
3.13k
    }
448
449
22.1k
    bool _has_const_child() const {
450
22.1k
        return std::ranges::any_of(_children,
451
44.3k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
452
22.1k
    }
453
454
    std::pair<const uint8_t*, const uint8_t*> _get_raw_data_and_null_map(
455
38.5k
            const ColumnPtr& column, bool has_nullable_column) const {
456
38.5k
        if (has_nullable_column) {
457
23.9k
            const auto* nullable_column = assert_cast<const ColumnNullable*>(column.get());
458
23.9k
            auto* data_column =
459
23.9k
                    assert_cast<const ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
460
23.9k
                            ->get_data()
461
23.9k
                            .data();
462
23.9k
            auto* null_map = nullable_column->get_null_map_column_ptr()->get_data().data();
463
23.9k
            return std::make_pair(data_column, null_map);
464
23.9k
        } else {
465
14.5k
            auto* data_column = assert_cast<const ColumnUInt8*>(column.get())->get_data().data();
466
14.5k
            return std::make_pair(data_column, nullptr);
467
14.5k
        }
468
38.5k
    }
469
470
    TExprOpcode::type _op;
471
};
472
473
} // namespace doris