Coverage Report

Created: 2026-06-30 21:21

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
5.89k
inline std::string compound_operator_to_string(TExprOpcode::type op) {
38
5.89k
    if (op == TExprOpcode::COMPOUND_AND) {
39
1.03k
        return "and";
40
4.85k
    } else if (op == TExprOpcode::COMPOUND_OR) {
41
4.31k
        return "or";
42
4.31k
    } else {
43
544
        return "not";
44
544
    }
45
5.89k
}
46
47
class VCompoundPred : public VectorizedFnCall {
48
    ENABLE_FACTORY_CREATOR(VCompoundPred);
49
50
public:
51
5.89k
    VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) {
52
5.89k
        _op = node.opcode;
53
5.89k
        _fn.name.function_name = compound_operator_to_string(_op);
54
5.89k
        _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})",
55
5.89k
                                 _fn.name.function_name, get_child_names(), _data_type->get_name());
56
5.89k
    }
57
58
#ifdef BE_TEST
59
    VCompoundPred() = default;
60
#endif
61
62
13.8k
    const std::string& expr_name() const override { return _expr_name; }
63
398
    Status clone_node(VExprSPtr* cloned_expr) const override {
64
398
        DORIS_CHECK(cloned_expr != nullptr);
65
398
        *cloned_expr = VCompoundPred::create_shared(clone_texpr_node());
66
398
        return Status::OK();
67
398
    }
68
69
14.1k
    bool can_evaluate_zonemap_filter() const override {
70
14.1k
        switch (_op) {
71
2.43k
        case TExprOpcode::COMPOUND_AND:
72
2.87k
            return std::ranges::any_of(_children, [](const VExprSPtr& child) {
73
2.87k
                return child->can_evaluate_zonemap_filter();
74
2.87k
            });
75
8.96k
        case TExprOpcode::COMPOUND_OR:
76
14.7k
            return !_children.empty() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
77
14.7k
                return child->can_evaluate_zonemap_filter();
78
14.7k
            });
79
2.72k
        case TExprOpcode::COMPOUND_NOT:
80
2.72k
            return false;
81
0
        default:
82
0
            return false;
83
14.1k
        }
84
14.1k
    }
85
86
2.61k
    ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const override {
87
2.61k
        switch (_op) {
88
329
        case TExprOpcode::COMPOUND_AND: {
89
583
            for (const auto& child : _children) {
90
583
                if (!child->can_evaluate_zonemap_filter()) {
91
42
                    continue;
92
42
                }
93
541
                if (child->evaluate_zonemap_filter(ctx) == ZoneMapFilterResult::kNoMatch) {
94
120
                    return ZoneMapFilterResult::kNoMatch;
95
120
                }
96
541
            }
97
209
            return ZoneMapFilterResult::kMayMatch;
98
329
        }
99
2.28k
        case TExprOpcode::COMPOUND_OR: {
100
3.85k
            for (const auto& child : _children) {
101
3.85k
                DORIS_CHECK(child->can_evaluate_zonemap_filter());
102
3.85k
                if (child->evaluate_zonemap_filter(ctx) != ZoneMapFilterResult::kNoMatch) {
103
1.91k
                    return ZoneMapFilterResult::kMayMatch;
104
1.91k
                }
105
3.85k
            }
106
366
            return ZoneMapFilterResult::kNoMatch;
107
2.28k
        }
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.61k
        }
113
2.61k
    }
114
115
4.80k
    Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override {
116
4.80k
        segment_v2::InvertedIndexResultBitmap res;
117
4.80k
        bool all_pass = true;
118
119
4.80k
        switch (_op) {
120
2.97k
        case TExprOpcode::COMPOUND_OR: {
121
5.75k
            for (const auto& child : _children) {
122
5.75k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
123
5.75k
                    !st.ok()) {
124
183
                    LOG(ERROR) << "expr:" << child->expr_name()
125
183
                               << " evaluate_inverted_index error:" << st.to_string();
126
183
                    all_pass = false;
127
183
                    continue;
128
183
                }
129
5.57k
                auto inverted_index_context = context->get_index_context();
130
5.57k
                if (inverted_index_context->has_index_result_for_expr(child.get())) {
131
2.95k
                    const auto* index_result =
132
2.95k
                            inverted_index_context->get_index_result_for_expr(child.get());
133
2.95k
                    if (res.is_empty()) {
134
1.96k
                        res = *index_result;
135
1.96k
                    } else {
136
981
                        res |= *index_result;
137
981
                    }
138
2.95k
                    if (inverted_index_context->get_score_runtime() == nullptr) {
139
2.95k
                        if (res.get_data_bitmap()->cardinality() == segment_num_rows) {
140
336
                            break; // Early exit if result is full
141
336
                        }
142
2.95k
                    }
143
2.95k
                } else {
144
2.62k
                    all_pass = false;
145
2.62k
                }
146
5.57k
            }
147
2.97k
            break;
148
0
        }
149
5.23k
        case TExprOpcode::COMPOUND_AND: {
150
1.32k
            for (const auto& child : _children) {
151
1.32k
                if (Status st = child->evaluate_inverted_index(context, segment_num_rows);
152
1.32k
                    !st.ok()) {
153
25
                    LOG(ERROR) << "expr:" << child->expr_name()
154
25
                               << " evaluate_inverted_index error:" << st.to_string();
155
25
                    all_pass = false;
156
25
                    continue;
157
25
                }
158
1.30k
                if (context->get_index_context()->has_index_result_for_expr(child.get())) {
159
202
                    const auto* index_result =
160
202
                            context->get_index_context()->get_index_result_for_expr(child.get());
161
202
                    if (res.is_empty()) {
162
142
                        res = *index_result;
163
142
                    } else {
164
60
                        res &= *index_result;
165
60
                    }
166
167
202
                    if (res.get_data_bitmap()->isEmpty()) {
168
59
                        break; // Early exit if result is empty
169
59
                    }
170
1.09k
                } else {
171
1.09k
                    all_pass = false;
172
1.09k
                }
173
1.30k
            }
174
688
            break;
175
0
        }
176
1.24k
        case TExprOpcode::COMPOUND_NOT: {
177
1.13k
            const auto& child = _children[0];
178
1.13k
            Status st = child->evaluate_inverted_index(context, segment_num_rows);
179
1.13k
            if (!st.ok()) {
180
40
                LOG(ERROR) << "expr:" << child->expr_name()
181
40
                           << " evaluate_inverted_index error:" << st.to_string();
182
40
                return st;
183
40
            }
184
185
1.09k
            if (context->get_index_context()->has_index_result_for_expr(child.get())) {
186
643
                const auto* index_result =
187
643
                        context->get_index_context()->get_index_result_for_expr(child.get());
188
643
                roaring::Roaring full_result;
189
643
                full_result.addRange(0, segment_num_rows);
190
643
                res = index_result->op_not(&full_result);
191
643
            } else {
192
455
                all_pass = false;
193
455
            }
194
1.09k
            break;
195
1.13k
        }
196
0
        default:
197
0
            return Status::NotSupported(
198
0
                    "Compound operator must be AND, OR, or NOT to execute with inverted index.");
199
4.80k
        }
200
201
4.78k
        if (all_pass && !res.is_empty()) {
202
1.94k
            context->get_index_context()->set_index_result_for_expr(this, res);
203
1.94k
        }
204
4.78k
        return Status::OK();
205
4.80k
    }
206
207
    Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector,
208
27.9k
                               size_t count, ColumnPtr& result_column) const override {
209
27.9k
        if (fast_execute(context, selector, count, result_column)) {
210
59
            return Status::OK();
211
59
        }
212
27.8k
        if (get_num_children() == 1 || _has_const_child()) {
213
969
            return VectorizedFnCall::execute_column_impl(context, block, selector, count,
214
969
                                                         result_column);
215
969
        }
216
217
26.8k
        ColumnPtr lhs_column;
218
26.8k
        RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column));
219
26.8k
        lhs_column = lhs_column->convert_to_full_column_if_const();
220
26.8k
        size_t size = lhs_column->size();
221
222
26.8k
        bool lhs_is_nullable = lhs_column->is_nullable();
223
26.8k
        auto [lhs_data_column, lhs_null_map] =
224
26.8k
                _get_raw_data_and_null_map(lhs_column, lhs_is_nullable);
225
26.8k
        size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size);
226
26.8k
        bool lhs_all_true = (filted == 0);
227
26.8k
        bool lhs_all_false = (filted == size);
228
229
26.8k
        bool lhs_all_is_not_null = false;
230
26.8k
        if (lhs_is_nullable) {
231
15.0k
            filted = simd::count_zero_num((int8_t*)lhs_null_map, size);
232
15.0k
            lhs_all_is_not_null = (filted == size);
233
15.0k
        }
234
235
26.8k
        ColumnPtr rhs_column = nullptr;
236
26.8k
        const uint8_t* __restrict rhs_data_column = nullptr;
237
26.8k
        const uint8_t* __restrict rhs_null_map = nullptr;
238
26.8k
        bool rhs_is_nullable = false;
239
26.8k
        bool rhs_all_true = false;
240
26.8k
        bool rhs_all_false = false;
241
26.8k
        bool rhs_all_is_not_null = false;
242
26.8k
        bool result_is_nullable = _data_type->is_nullable();
243
244
26.8k
        auto get_rhs_colum = [&]() {
245
20.7k
            if (!rhs_column) {
246
20.7k
                RETURN_IF_ERROR(
247
20.7k
                        _children[1]->execute_column(context, block, selector, count, rhs_column));
248
20.7k
                rhs_column = rhs_column->convert_to_full_column_if_const();
249
20.7k
                rhs_is_nullable = rhs_column->is_nullable();
250
20.7k
                auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable);
251
20.7k
                rhs_data_column = rhs_nullable_column.first;
252
20.7k
                rhs_null_map = rhs_nullable_column.second;
253
20.7k
                size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size);
254
20.7k
                rhs_all_true = (filted == 0);
255
20.7k
                rhs_all_false = (filted == size);
256
20.7k
                if (rhs_is_nullable) {
257
15.8k
                    filted = simd::count_zero_num((int8_t*)rhs_null_map, size);
258
15.8k
                    rhs_all_is_not_null = (filted == size);
259
15.8k
                }
260
20.7k
            }
261
20.7k
            return Status::OK();
262
20.7k
        };
263
264
26.8k
        auto return_result_column_id = [&](ColumnPtr& arg_column) {
265
23.8k
            result_column = std::move(*arg_column).mutate();
266
23.8k
            if (result_is_nullable && !result_column->is_nullable()) {
267
3.03k
                result_column = make_nullable(result_column);
268
3.03k
            }
269
23.8k
        };
270
271
26.8k
        auto create_null_map_column = [&](ColumnPtr& null_map_column,
272
26.8k
                                          const uint8_t* __restrict null_map_data) {
273
4.94k
            if (null_map_data == nullptr) {
274
674
                null_map_column = ColumnUInt8::create(size, 0);
275
674
                null_map_data =
276
674
                        assert_cast<const ColumnUInt8*>(null_map_column.get())->get_data().data();
277
674
            }
278
4.94k
            return null_map_data;
279
4.94k
        };
280
281
26.8k
        auto vector_vector = [&]<bool is_and_op>() {
282
524
            MutableColumnPtr mutable_result_column;
283
524
            uint8_t* __restrict result_data_column = nullptr;
284
524
            const uint8_t* __restrict other_data_column = rhs_data_column;
285
524
            if (lhs_column->use_count() == 1) {
286
520
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
287
520
                result_data_column =
288
520
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
289
520
            } 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
3
            } else {
295
3
                mutable_result_column = lhs_column->clone_resized(size);
296
3
                result_data_column =
297
3
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
298
3
            }
299
300
524
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
301
524
            result_column = std::move(mutable_result_column);
302
524
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb1EEEDav
Line
Count
Source
281
402
        auto vector_vector = [&]<bool is_and_op>() {
282
402
            MutableColumnPtr mutable_result_column;
283
402
            uint8_t* __restrict result_data_column = nullptr;
284
402
            const uint8_t* __restrict other_data_column = rhs_data_column;
285
402
            if (lhs_column->use_count() == 1) {
286
402
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
287
402
                result_data_column =
288
402
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
289
402
            } 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
0
            } else {
295
0
                mutable_result_column = lhs_column->clone_resized(size);
296
0
                result_data_column =
297
0
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
298
0
            }
299
300
402
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
301
402
            result_column = std::move(mutable_result_column);
302
402
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb0EEEDav
Line
Count
Source
281
122
        auto vector_vector = [&]<bool is_and_op>() {
282
122
            MutableColumnPtr mutable_result_column;
283
122
            uint8_t* __restrict result_data_column = nullptr;
284
122
            const uint8_t* __restrict other_data_column = rhs_data_column;
285
122
            if (lhs_column->use_count() == 1) {
286
118
                mutable_result_column = IColumn::mutate(std::move(lhs_column));
287
118
                result_data_column =
288
118
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
289
118
            } 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
3
            } else {
295
3
                mutable_result_column = lhs_column->clone_resized(size);
296
3
                result_data_column =
297
3
                        assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data();
298
3
            }
299
300
122
            do_not_null_pred<is_and_op>(result_data_column, other_data_column, size);
301
122
            result_column = std::move(mutable_result_column);
302
122
        };
303
26.8k
        auto vector_vector_null = [&]<bool is_and_op>() {
304
2.47k
            auto col_res = ColumnUInt8::create(size);
305
2.47k
            auto col_nulls = ColumnUInt8::create(size);
306
307
2.47k
            auto* __restrict res_datas = col_res->get_data().data();
308
2.47k
            auto* __restrict res_nulls = col_nulls->get_data().data();
309
2.47k
            ColumnPtr temp_null_map = nullptr;
310
            // maybe both children are nullable / or one of children is nullable
311
2.47k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
312
2.47k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
313
2.47k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
314
2.47k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
315
316
2.47k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
317
2.47k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
318
319
2.47k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
320
2.47k
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb1EEEDav
Line
Count
Source
303
505
        auto vector_vector_null = [&]<bool is_and_op>() {
304
505
            auto col_res = ColumnUInt8::create(size);
305
505
            auto col_nulls = ColumnUInt8::create(size);
306
307
505
            auto* __restrict res_datas = col_res->get_data().data();
308
505
            auto* __restrict res_nulls = col_nulls->get_data().data();
309
505
            ColumnPtr temp_null_map = nullptr;
310
            // maybe both children are nullable / or one of children is nullable
311
505
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
312
505
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
313
505
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
314
505
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
315
316
505
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
317
505
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
318
319
505
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
320
505
        };
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb0EEEDav
Line
Count
Source
303
1.96k
        auto vector_vector_null = [&]<bool is_and_op>() {
304
1.96k
            auto col_res = ColumnUInt8::create(size);
305
1.96k
            auto col_nulls = ColumnUInt8::create(size);
306
307
1.96k
            auto* __restrict res_datas = col_res->get_data().data();
308
1.96k
            auto* __restrict res_nulls = col_nulls->get_data().data();
309
1.96k
            ColumnPtr temp_null_map = nullptr;
310
            // maybe both children are nullable / or one of children is nullable
311
1.96k
            auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map);
312
1.96k
            auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map);
313
1.96k
            auto* __restrict lhs_data_column_tmp = lhs_data_column;
314
1.96k
            auto* __restrict rhs_data_column_tmp = rhs_data_column;
315
316
1.96k
            do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp,
317
1.96k
                                    rhs_null_map_tmp, res_datas, res_nulls, size);
318
319
1.96k
            result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls));
320
1.96k
        };
321
322
        // false and NULL ----> 0
323
        // true  and NULL ----> NULL
324
26.8k
        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.14k
            if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
328
                // false and any = false, return lhs
329
2.10k
                return_result_column_id(lhs_column);
330
2.10k
            } else {
331
2.04k
                RETURN_IF_ERROR(get_rhs_colum());
332
333
2.04k
                if ((lhs_all_true && !lhs_is_nullable) ||    //not null column
334
2.04k
                    (lhs_all_true && lhs_all_is_not_null)) { //nullable column
335
                                                             // true and any = any, return rhs
336
337
672
                    return_result_column_id(rhs_column);
338
1.37k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
339
1.37k
                           (rhs_all_false && rhs_all_is_not_null)) {
340
                    // any and false = false, return rhs
341
214
                    return_result_column_id(rhs_column);
342
1.15k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
343
1.15k
                           (rhs_all_true && rhs_all_is_not_null)) {
344
                    // any and true = any, return lhs
345
248
                    return_result_column_id(lhs_column);
346
908
                } else {
347
908
                    if (!result_is_nullable) {
348
402
                        vector_vector.template operator()<true>();
349
506
                    } else {
350
506
                        vector_vector_null.template operator()<true>();
351
506
                    }
352
908
                }
353
2.04k
            }
354
22.7k
        } else if (_op == TExprOpcode::COMPOUND_OR) {
355
            // true  or NULL ----> 1
356
            // false or NULL ----> NULL
357
22.7k
            if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) {
358
                // true or any = true, return lhs
359
3.99k
                return_result_column_id(lhs_column);
360
18.7k
            } else {
361
18.7k
                RETURN_IF_ERROR(get_rhs_colum());
362
18.7k
                if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) {
363
                    // false or any = any, return rhs
364
15.3k
                    return_result_column_id(rhs_column);
365
15.3k
                } else if ((rhs_all_true && !rhs_is_nullable) ||
366
3.40k
                           (rhs_all_true && rhs_all_is_not_null)) {
367
                    // any or true = true, return rhs
368
740
                    return_result_column_id(rhs_column);
369
2.66k
                } else if ((rhs_all_false && !rhs_is_nullable) ||
370
2.66k
                           (rhs_all_false && rhs_all_is_not_null)) {
371
                    // any or false = any, return lhs
372
579
                    return_result_column_id(lhs_column);
373
2.08k
                } else {
374
2.08k
                    if (!result_is_nullable) {
375
122
                        vector_vector.template operator()<false>();
376
1.96k
                    } else {
377
1.96k
                        vector_vector_null.template operator()<false>();
378
1.96k
                    }
379
2.08k
                }
380
18.7k
            }
381
18.4E
        } else {
382
18.4E
            return Status::InternalError("Compound operator must be AND or OR.");
383
18.4E
        }
384
385
26.8k
        DCHECK_EQ(result_column->size(), count);
386
26.8k
        return Status::OK();
387
26.8k
    }
388
389
972
    double execute_cost() const override {
390
972
        double cost = 0.3;
391
1.55k
        for (const auto& child : _children) {
392
1.55k
            cost += child->execute_cost();
393
1.55k
        }
394
972
        return cost;
395
972
    }
396
397
private:
398
78.7k
    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
78.7k
        return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b));
401
78.7k
    }
402
289k
    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
289k
        return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b));
405
289k
    }
406
407
    template <bool is_and>
408
    void static do_not_null_pred(uint8_t* __restrict lhs, const uint8_t* __restrict rhs,
409
524
                                 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
42.4k
        for (size_t i = 0; i < size; ++i) {
418
41.8k
            if constexpr (is_and) {
419
37.9k
                lhs[i] &= rhs[i];
420
37.9k
            } else {
421
3.97k
                lhs[i] |= rhs[i];
422
3.97k
            }
423
41.8k
        }
424
524
    }
_ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhPKhm
Line
Count
Source
409
402
                                 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
38.3k
        for (size_t i = 0; i < size; ++i) {
418
37.9k
            if constexpr (is_and) {
419
37.9k
                lhs[i] &= rhs[i];
420
            } else {
421
                lhs[i] |= rhs[i];
422
            }
423
37.9k
        }
424
402
    }
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhPKhm
Line
Count
Source
409
122
                                 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.09k
        for (size_t i = 0; i < size; ++i) {
418
            if constexpr (is_and) {
419
                lhs[i] &= rhs[i];
420
3.97k
            } else {
421
3.97k
                lhs[i] |= rhs[i];
422
3.97k
            }
423
3.97k
        }
424
122
    }
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
2.47k
                             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
371k
        for (size_t i = 0; i < size; ++i) {
439
368k
            if constexpr (is_and) {
440
78.7k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
441
78.7k
                res_data[i] = lhs_data[i] & rhs_data[i];
442
289k
            } else {
443
289k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
444
289k
                res_data[i] = lhs_data[i] | rhs_data[i];
445
289k
            }
446
368k
        }
447
2.47k
    }
_ZN5doris13VCompoundPred12do_null_predILb1EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
430
505
                             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
79.2k
        for (size_t i = 0; i < size; ++i) {
439
78.7k
            if constexpr (is_and) {
440
78.7k
                res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
441
78.7k
                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
78.7k
        }
447
505
    }
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPKhS3_S3_S3_PhS4_m
Line
Count
Source
430
1.96k
                             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
291k
        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
289k
            } else {
443
289k
                res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]);
444
289k
                res_data[i] = lhs_data[i] | rhs_data[i];
445
289k
            }
446
289k
        }
447
1.96k
    }
448
449
26.9k
    bool _has_const_child() const {
450
26.9k
        return std::ranges::any_of(_children,
451
53.7k
                                   [](const VExprSPtr& arg) -> bool { return arg->is_constant(); });
452
26.9k
    }
453
454
    std::pair<const uint8_t*, const uint8_t*> _get_raw_data_and_null_map(
455
47.6k
            const ColumnPtr& column, bool has_nullable_column) const {
456
47.6k
        if (has_nullable_column) {
457
30.8k
            const auto* nullable_column = assert_cast<const ColumnNullable*>(column.get());
458
30.8k
            auto* data_column =
459
30.8k
                    assert_cast<const ColumnUInt8*>(nullable_column->get_nested_column_ptr().get())
460
30.8k
                            ->get_data()
461
30.8k
                            .data();
462
30.8k
            auto* null_map = nullable_column->get_null_map_column_ptr()->get_data().data();
463
30.8k
            return std::make_pair(data_column, null_map);
464
30.8k
        } else {
465
16.8k
            auto* data_column = assert_cast<const ColumnUInt8*>(column.get())->get_data().data();
466
16.8k
            return std::make_pair(data_column, nullptr);
467
16.8k
        }
468
47.6k
    }
469
470
    TExprOpcode::type _op;
471
};
472
473
} // namespace doris