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 | 4.76k | inline std::string compound_operator_to_string(TExprOpcode::type op) { |
36 | 4.76k | if (op == TExprOpcode::COMPOUND_AND) { |
37 | 894 | return "and"; |
38 | 3.86k | } else if (op == TExprOpcode::COMPOUND_OR) { |
39 | 3.37k | return "or"; |
40 | 3.37k | } else { |
41 | 495 | return "not"; |
42 | 495 | } |
43 | 4.76k | } |
44 | | |
45 | | class VCompoundPred : public VectorizedFnCall { |
46 | | ENABLE_FACTORY_CREATOR(VCompoundPred); |
47 | | |
48 | | public: |
49 | 4.76k | VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) { |
50 | 4.76k | _op = node.opcode; |
51 | 4.76k | _fn.name.function_name = compound_operator_to_string(_op); |
52 | 4.76k | _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})", |
53 | 4.76k | _fn.name.function_name, get_child_names(), _data_type->get_name()); |
54 | 4.76k | } |
55 | | |
56 | | #ifdef BE_TEST |
57 | | VCompoundPred() = default; |
58 | | #endif |
59 | | |
60 | 11.7k | const std::string& expr_name() const override { return _expr_name; } |
61 | 0 | Status clone_node(VExprSPtr* cloned_expr) const override { |
62 | 0 | DORIS_CHECK(cloned_expr != nullptr); |
63 | 0 | *cloned_expr = VCompoundPred::create_shared(clone_texpr_node()); |
64 | 0 | return Status::OK(); |
65 | 0 | } |
66 | | |
67 | 5.15k | Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override { |
68 | 5.15k | segment_v2::InvertedIndexResultBitmap res; |
69 | 5.15k | bool all_pass = true; |
70 | | |
71 | 5.15k | switch (_op) { |
72 | 3.30k | case TExprOpcode::COMPOUND_OR: { |
73 | 6.38k | for (const auto& child : _children) { |
74 | 6.38k | if (Status st = child->evaluate_inverted_index(context, segment_num_rows); |
75 | 6.38k | !st.ok()) { |
76 | 177 | LOG(ERROR) << "expr:" << child->expr_name() |
77 | 177 | << " evaluate_inverted_index error:" << st.to_string(); |
78 | 177 | all_pass = false; |
79 | 177 | continue; |
80 | 177 | } |
81 | 6.20k | auto inverted_index_context = context->get_index_context(); |
82 | 6.20k | if (inverted_index_context->has_index_result_for_expr(child.get())) { |
83 | 3.24k | const auto* index_result = |
84 | 3.24k | inverted_index_context->get_index_result_for_expr(child.get()); |
85 | 3.24k | if (res.is_empty()) { |
86 | 2.24k | res = *index_result; |
87 | 2.24k | } else { |
88 | 999 | res |= *index_result; |
89 | 999 | } |
90 | 3.24k | if (inverted_index_context->get_score_runtime() == nullptr) { |
91 | 3.23k | if (res.get_data_bitmap()->cardinality() == segment_num_rows) { |
92 | 350 | break; // Early exit if result is full |
93 | 350 | } |
94 | 3.23k | } |
95 | 3.24k | } else { |
96 | 2.95k | all_pass = false; |
97 | 2.95k | } |
98 | 6.20k | } |
99 | 3.30k | break; |
100 | 0 | } |
101 | 5.85k | case TExprOpcode::COMPOUND_AND: { |
102 | 1.30k | for (const auto& child : _children) { |
103 | 1.30k | if (Status st = child->evaluate_inverted_index(context, segment_num_rows); |
104 | 1.30k | !st.ok()) { |
105 | 34 | LOG(ERROR) << "expr:" << child->expr_name() |
106 | 34 | << " evaluate_inverted_index error:" << st.to_string(); |
107 | 34 | all_pass = false; |
108 | 34 | continue; |
109 | 34 | } |
110 | 1.26k | if (context->get_index_context()->has_index_result_for_expr(child.get())) { |
111 | 265 | const auto* index_result = |
112 | 265 | context->get_index_context()->get_index_result_for_expr(child.get()); |
113 | 265 | if (res.is_empty()) { |
114 | 199 | res = *index_result; |
115 | 199 | } else { |
116 | 66 | res &= *index_result; |
117 | 66 | } |
118 | | |
119 | 265 | if (res.get_data_bitmap()->isEmpty()) { |
120 | 114 | break; // Early exit if result is empty |
121 | 114 | } |
122 | 1.00k | } else { |
123 | 1.00k | all_pass = false; |
124 | 1.00k | } |
125 | 1.26k | } |
126 | 697 | break; |
127 | 0 | } |
128 | 1.16k | case TExprOpcode::COMPOUND_NOT: { |
129 | 1.16k | const auto& child = _children[0]; |
130 | 1.16k | Status st = child->evaluate_inverted_index(context, segment_num_rows); |
131 | 1.16k | if (!st.ok()) { |
132 | 40 | LOG(ERROR) << "expr:" << child->expr_name() |
133 | 40 | << " evaluate_inverted_index error:" << st.to_string(); |
134 | 40 | return st; |
135 | 40 | } |
136 | | |
137 | 1.12k | if (context->get_index_context()->has_index_result_for_expr(child.get())) { |
138 | 661 | const auto* index_result = |
139 | 661 | context->get_index_context()->get_index_result_for_expr(child.get()); |
140 | 661 | roaring::Roaring full_result; |
141 | 661 | full_result.addRange(0, segment_num_rows); |
142 | 661 | res = index_result->op_not(&full_result); |
143 | 661 | } else { |
144 | 460 | all_pass = false; |
145 | 460 | } |
146 | 1.12k | break; |
147 | 1.16k | } |
148 | 0 | default: |
149 | 0 | return Status::NotSupported( |
150 | 0 | "Compound operator must be AND, OR, or NOT to execute with inverted index."); |
151 | 5.15k | } |
152 | | |
153 | 5.15k | if (all_pass && !res.is_empty()) { |
154 | 2.04k | context->get_index_context()->set_index_result_for_expr(this, res); |
155 | 2.04k | } |
156 | 5.15k | return Status::OK(); |
157 | 5.15k | } |
158 | | |
159 | | Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector, |
160 | 20.0k | size_t count, ColumnPtr& result_column) const override { |
161 | 20.0k | if (fast_execute(context, selector, count, result_column)) { |
162 | 102 | return Status::OK(); |
163 | 102 | } |
164 | 19.9k | if (get_num_children() == 1 || _has_const_child()) { |
165 | 941 | return VectorizedFnCall::execute_column_impl(context, block, selector, count, |
166 | 941 | result_column); |
167 | 941 | } |
168 | | |
169 | 19.0k | ColumnPtr lhs_column; |
170 | 19.0k | RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column)); |
171 | 19.0k | lhs_column = lhs_column->convert_to_full_column_if_const(); |
172 | 19.0k | size_t size = lhs_column->size(); |
173 | | |
174 | 19.0k | bool lhs_is_nullable = lhs_column->is_nullable(); |
175 | 19.0k | auto [lhs_data_column, lhs_null_map] = |
176 | 19.0k | _get_raw_data_and_null_map(lhs_column, lhs_is_nullable); |
177 | 19.0k | size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size); |
178 | 19.0k | bool lhs_all_true = (filted == 0); |
179 | 19.0k | bool lhs_all_false = (filted == size); |
180 | | |
181 | 19.0k | bool lhs_all_is_not_null = false; |
182 | 19.0k | if (lhs_is_nullable) { |
183 | 9.19k | filted = simd::count_zero_num((int8_t*)lhs_null_map, size); |
184 | 9.19k | lhs_all_is_not_null = (filted == size); |
185 | 9.19k | } |
186 | | |
187 | 19.0k | ColumnPtr rhs_column = nullptr; |
188 | 19.0k | const uint8_t* __restrict rhs_data_column = nullptr; |
189 | 19.0k | const uint8_t* __restrict rhs_null_map = nullptr; |
190 | 19.0k | bool rhs_is_nullable = false; |
191 | 19.0k | bool rhs_all_true = false; |
192 | 19.0k | bool rhs_all_false = false; |
193 | 19.0k | bool rhs_all_is_not_null = false; |
194 | 19.0k | bool result_is_nullable = _data_type->is_nullable(); |
195 | | |
196 | 19.0k | auto get_rhs_colum = [&]() { |
197 | 13.4k | if (!rhs_column) { |
198 | 13.4k | RETURN_IF_ERROR( |
199 | 13.4k | _children[1]->execute_column(context, block, selector, count, rhs_column)); |
200 | 13.4k | rhs_column = rhs_column->convert_to_full_column_if_const(); |
201 | 13.4k | rhs_is_nullable = rhs_column->is_nullable(); |
202 | 13.4k | auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable); |
203 | 13.4k | rhs_data_column = rhs_nullable_column.first; |
204 | 13.4k | rhs_null_map = rhs_nullable_column.second; |
205 | 13.4k | size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size); |
206 | 13.4k | rhs_all_true = (filted == 0); |
207 | 13.4k | rhs_all_false = (filted == size); |
208 | 13.4k | if (rhs_is_nullable) { |
209 | 9.25k | filted = simd::count_zero_num((int8_t*)rhs_null_map, size); |
210 | 9.25k | rhs_all_is_not_null = (filted == size); |
211 | 9.25k | } |
212 | 13.4k | } |
213 | 13.4k | return Status::OK(); |
214 | 13.4k | }; |
215 | | |
216 | 19.0k | auto return_result_column_id = [&](ColumnPtr& arg_column) { |
217 | 16.9k | result_column = std::move(*arg_column).mutate(); |
218 | 16.9k | if (result_is_nullable && !result_column->is_nullable()) { |
219 | 2.60k | result_column = make_nullable(result_column); |
220 | 2.60k | } |
221 | 16.9k | }; |
222 | | |
223 | 19.0k | auto create_null_map_column = [&](ColumnPtr& null_map_column, |
224 | 19.0k | const uint8_t* __restrict null_map_data) { |
225 | 3.48k | if (null_map_data == nullptr) { |
226 | 591 | null_map_column = ColumnUInt8::create(size, 0); |
227 | 591 | null_map_data = |
228 | 591 | assert_cast<const ColumnUInt8*>(null_map_column.get())->get_data().data(); |
229 | 591 | } |
230 | 3.48k | return null_map_data; |
231 | 3.48k | }; |
232 | | |
233 | 19.0k | auto vector_vector = [&]<bool is_and_op>() { |
234 | 375 | MutableColumnPtr mutable_result_column; |
235 | 375 | uint8_t* __restrict result_data_column = nullptr; |
236 | 375 | const uint8_t* __restrict other_data_column = rhs_data_column; |
237 | 375 | if (lhs_column->use_count() == 1) { |
238 | 373 | mutable_result_column = IColumn::mutate(std::move(lhs_column)); |
239 | 373 | result_data_column = |
240 | 373 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); |
241 | 373 | } else if (rhs_column->use_count() == 1) { |
242 | 1 | mutable_result_column = IColumn::mutate(std::move(rhs_column)); |
243 | 1 | result_data_column = |
244 | 1 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); |
245 | 1 | other_data_column = lhs_data_column; |
246 | 1 | } else { |
247 | 1 | mutable_result_column = lhs_column->clone_resized(size); |
248 | 1 | result_data_column = |
249 | 1 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); |
250 | 1 | } |
251 | | |
252 | 375 | do_not_null_pred<is_and_op>(result_data_column, other_data_column, size); |
253 | 375 | result_column = std::move(mutable_result_column); |
254 | 375 | }; _ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb1EEEDav Line | Count | Source | 233 | 287 | auto vector_vector = [&]<bool is_and_op>() { | 234 | 287 | MutableColumnPtr mutable_result_column; | 235 | 287 | uint8_t* __restrict result_data_column = nullptr; | 236 | 287 | const uint8_t* __restrict other_data_column = rhs_data_column; | 237 | 287 | if (lhs_column->use_count() == 1) { | 238 | 287 | mutable_result_column = IColumn::mutate(std::move(lhs_column)); | 239 | 287 | result_data_column = | 240 | 287 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 241 | 287 | } else if (rhs_column->use_count() == 1) { | 242 | 0 | mutable_result_column = IColumn::mutate(std::move(rhs_column)); | 243 | 0 | result_data_column = | 244 | 0 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 245 | 0 | other_data_column = lhs_data_column; | 246 | 0 | } else { | 247 | 0 | mutable_result_column = lhs_column->clone_resized(size); | 248 | 0 | result_data_column = | 249 | 0 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 250 | 0 | } | 251 | | | 252 | 287 | do_not_null_pred<is_and_op>(result_data_column, other_data_column, size); | 253 | 287 | result_column = std::move(mutable_result_column); | 254 | 287 | }; |
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb0EEEDav Line | Count | Source | 233 | 88 | auto vector_vector = [&]<bool is_and_op>() { | 234 | 88 | MutableColumnPtr mutable_result_column; | 235 | 88 | uint8_t* __restrict result_data_column = nullptr; | 236 | 88 | const uint8_t* __restrict other_data_column = rhs_data_column; | 237 | 88 | if (lhs_column->use_count() == 1) { | 238 | 86 | mutable_result_column = IColumn::mutate(std::move(lhs_column)); | 239 | 86 | result_data_column = | 240 | 86 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 241 | 86 | } else if (rhs_column->use_count() == 1) { | 242 | 1 | mutable_result_column = IColumn::mutate(std::move(rhs_column)); | 243 | 1 | result_data_column = | 244 | 1 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 245 | 1 | other_data_column = lhs_data_column; | 246 | 1 | } else { | 247 | 1 | mutable_result_column = lhs_column->clone_resized(size); | 248 | 1 | result_data_column = | 249 | 1 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 250 | 1 | } | 251 | | | 252 | 88 | do_not_null_pred<is_and_op>(result_data_column, other_data_column, size); | 253 | 88 | result_column = std::move(mutable_result_column); | 254 | 88 | }; |
|
255 | 19.0k | auto vector_vector_null = [&]<bool is_and_op>() { |
256 | 1.74k | auto col_res = ColumnUInt8::create(size); |
257 | 1.74k | auto col_nulls = ColumnUInt8::create(size); |
258 | | |
259 | 1.74k | auto* __restrict res_datas = col_res->get_data().data(); |
260 | 1.74k | auto* __restrict res_nulls = col_nulls->get_data().data(); |
261 | 1.74k | ColumnPtr temp_null_map = nullptr; |
262 | | // maybe both children are nullable / or one of children is nullable |
263 | 1.74k | auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map); |
264 | 1.74k | auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map); |
265 | 1.74k | auto* __restrict lhs_data_column_tmp = lhs_data_column; |
266 | 1.74k | auto* __restrict rhs_data_column_tmp = rhs_data_column; |
267 | | |
268 | 1.74k | do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp, |
269 | 1.74k | rhs_null_map_tmp, res_datas, res_nulls, size); |
270 | | |
271 | 1.74k | result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls)); |
272 | 1.74k | }; _ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb1EEEDav Line | Count | Source | 255 | 451 | auto vector_vector_null = [&]<bool is_and_op>() { | 256 | 451 | auto col_res = ColumnUInt8::create(size); | 257 | 451 | auto col_nulls = ColumnUInt8::create(size); | 258 | | | 259 | 451 | auto* __restrict res_datas = col_res->get_data().data(); | 260 | 451 | auto* __restrict res_nulls = col_nulls->get_data().data(); | 261 | 451 | ColumnPtr temp_null_map = nullptr; | 262 | | // maybe both children are nullable / or one of children is nullable | 263 | 451 | auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map); | 264 | 451 | auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map); | 265 | 451 | auto* __restrict lhs_data_column_tmp = lhs_data_column; | 266 | 451 | auto* __restrict rhs_data_column_tmp = rhs_data_column; | 267 | | | 268 | 451 | do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp, | 269 | 451 | rhs_null_map_tmp, res_datas, res_nulls, size); | 270 | | | 271 | 451 | result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls)); | 272 | 451 | }; |
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb0EEEDav Line | Count | Source | 255 | 1.29k | auto vector_vector_null = [&]<bool is_and_op>() { | 256 | 1.29k | auto col_res = ColumnUInt8::create(size); | 257 | 1.29k | auto col_nulls = ColumnUInt8::create(size); | 258 | | | 259 | 1.29k | auto* __restrict res_datas = col_res->get_data().data(); | 260 | 1.29k | auto* __restrict res_nulls = col_nulls->get_data().data(); | 261 | 1.29k | ColumnPtr temp_null_map = nullptr; | 262 | | // maybe both children are nullable / or one of children is nullable | 263 | 1.29k | auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map); | 264 | 1.29k | auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map); | 265 | 1.29k | auto* __restrict lhs_data_column_tmp = lhs_data_column; | 266 | 1.29k | auto* __restrict rhs_data_column_tmp = rhs_data_column; | 267 | | | 268 | 1.29k | do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp, | 269 | 1.29k | rhs_null_map_tmp, res_datas, res_nulls, size); | 270 | | | 271 | 1.29k | result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls)); | 272 | 1.29k | }; |
|
273 | | |
274 | | // false and NULL ----> 0 |
275 | | // true and NULL ----> NULL |
276 | 19.0k | if (_op == TExprOpcode::COMPOUND_AND) { |
277 | | //1. not null column: all data is false |
278 | | //2. nullable column: null map all is not null |
279 | 3.62k | if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) { |
280 | | // false and any = false, return lhs |
281 | 1.82k | return_result_column_id(lhs_column); |
282 | 1.82k | } else { |
283 | 1.79k | RETURN_IF_ERROR(get_rhs_colum()); |
284 | | |
285 | 1.79k | if ((lhs_all_true && !lhs_is_nullable) || //not null column |
286 | 1.79k | (lhs_all_true && lhs_all_is_not_null)) { //nullable column |
287 | | // true and any = any, return rhs |
288 | | |
289 | 602 | return_result_column_id(rhs_column); |
290 | 1.19k | } else if ((rhs_all_false && !rhs_is_nullable) || |
291 | 1.19k | (rhs_all_false && rhs_all_is_not_null)) { |
292 | | // any and false = false, return rhs |
293 | 203 | return_result_column_id(rhs_column); |
294 | 987 | } else if ((rhs_all_true && !rhs_is_nullable) || |
295 | 987 | (rhs_all_true && rhs_all_is_not_null)) { |
296 | | // any and true = any, return lhs |
297 | 249 | return_result_column_id(lhs_column); |
298 | 738 | } else { |
299 | 738 | if (!result_is_nullable) { |
300 | 287 | vector_vector.template operator()<true>(); |
301 | 451 | } else { |
302 | 451 | vector_vector_null.template operator()<true>(); |
303 | 451 | } |
304 | 738 | } |
305 | 1.79k | } |
306 | 15.3k | } else if (_op == TExprOpcode::COMPOUND_OR) { |
307 | | // true or NULL ----> 1 |
308 | | // false or NULL ----> NULL |
309 | 15.3k | if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) { |
310 | | // true or any = true, return lhs |
311 | 3.70k | return_result_column_id(lhs_column); |
312 | 11.6k | } else { |
313 | 11.6k | RETURN_IF_ERROR(get_rhs_colum()); |
314 | 11.6k | if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) { |
315 | | // false or any = any, return rhs |
316 | 9.02k | return_result_column_id(rhs_column); |
317 | 9.02k | } else if ((rhs_all_true && !rhs_is_nullable) || |
318 | 2.66k | (rhs_all_true && rhs_all_is_not_null)) { |
319 | | // any or true = true, return rhs |
320 | 734 | return_result_column_id(rhs_column); |
321 | 1.93k | } else if ((rhs_all_false && !rhs_is_nullable) || |
322 | 1.93k | (rhs_all_false && rhs_all_is_not_null)) { |
323 | | // any or false = any, return lhs |
324 | 557 | return_result_column_id(lhs_column); |
325 | 1.37k | } else { |
326 | 1.37k | if (!result_is_nullable) { |
327 | 88 | vector_vector.template operator()<false>(); |
328 | 1.29k | } else { |
329 | 1.29k | vector_vector_null.template operator()<false>(); |
330 | 1.29k | } |
331 | 1.37k | } |
332 | 11.6k | } |
333 | 18.4E | } else { |
334 | 18.4E | return Status::InternalError("Compound operator must be AND or OR."); |
335 | 18.4E | } |
336 | | |
337 | 19.0k | DCHECK_EQ(result_column->size(), count); |
338 | 19.0k | return Status::OK(); |
339 | 19.0k | } |
340 | | |
341 | 936 | double execute_cost() const override { |
342 | 936 | double cost = 0.3; |
343 | 1.48k | for (const auto& child : _children) { |
344 | 1.48k | cost += child->execute_cost(); |
345 | 1.48k | } |
346 | 936 | return cost; |
347 | 936 | } |
348 | | |
349 | | private: |
350 | 4.70k | static inline constexpr uint8_t apply_and_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) { |
351 | | // (<> && false) is false, (true && NULL) is NULL |
352 | 4.70k | return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b)); |
353 | 4.70k | } |
354 | 46.0k | static inline constexpr uint8_t apply_or_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) { |
355 | | // (<> || true) is true, (false || NULL) is NULL |
356 | 46.0k | return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b)); |
357 | 46.0k | } |
358 | | |
359 | | template <bool is_and> |
360 | | void static do_not_null_pred(uint8_t* __restrict lhs, const uint8_t* __restrict rhs, |
361 | 375 | size_t size) { |
362 | | #ifdef NDEBUG |
363 | | #if defined(__clang__) |
364 | | #pragma clang loop vectorize(enable) |
365 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) |
366 | | #pragma GCC ivdep |
367 | | #endif |
368 | | #endif |
369 | 14.6k | for (size_t i = 0; i < size; ++i) { |
370 | 14.2k | if constexpr (is_and) { |
371 | 10.0k | lhs[i] &= rhs[i]; |
372 | 10.0k | } else { |
373 | 4.17k | lhs[i] |= rhs[i]; |
374 | 4.17k | } |
375 | 14.2k | } |
376 | 375 | } _ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhPKhm Line | Count | Source | 361 | 287 | size_t size) { | 362 | | #ifdef NDEBUG | 363 | | #if defined(__clang__) | 364 | | #pragma clang loop vectorize(enable) | 365 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) | 366 | | #pragma GCC ivdep | 367 | | #endif | 368 | | #endif | 369 | 10.3k | for (size_t i = 0; i < size; ++i) { | 370 | 10.0k | if constexpr (is_and) { | 371 | 10.0k | lhs[i] &= rhs[i]; | 372 | | } else { | 373 | | lhs[i] |= rhs[i]; | 374 | | } | 375 | 10.0k | } | 376 | 287 | } |
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhPKhm Line | Count | Source | 361 | 88 | size_t size) { | 362 | | #ifdef NDEBUG | 363 | | #if defined(__clang__) | 364 | | #pragma clang loop vectorize(enable) | 365 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) | 366 | | #pragma GCC ivdep | 367 | | #endif | 368 | | #endif | 369 | 4.26k | for (size_t i = 0; i < size; ++i) { | 370 | | if constexpr (is_and) { | 371 | | lhs[i] &= rhs[i]; | 372 | 4.17k | } else { | 373 | 4.17k | lhs[i] |= rhs[i]; | 374 | 4.17k | } | 375 | 4.17k | } | 376 | 88 | } |
|
377 | | |
378 | | template <bool is_and> |
379 | | void static do_null_pred(const uint8_t* __restrict lhs_data, const uint8_t* __restrict lhs_null, |
380 | | const uint8_t* __restrict rhs_data, const uint8_t* __restrict rhs_null, |
381 | | uint8_t* __restrict res_data, uint8_t* __restrict res_null, |
382 | 1.74k | size_t size) { |
383 | | #ifdef NDEBUG |
384 | | #if defined(__clang__) |
385 | | #pragma clang loop vectorize(enable) |
386 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) |
387 | | #pragma GCC ivdep |
388 | | #endif |
389 | | #endif |
390 | 52.4k | for (size_t i = 0; i < size; ++i) { |
391 | 50.7k | if constexpr (is_and) { |
392 | 4.70k | res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); |
393 | 4.70k | res_data[i] = lhs_data[i] & rhs_data[i]; |
394 | 46.0k | } else { |
395 | 46.0k | res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); |
396 | 46.0k | res_data[i] = lhs_data[i] | rhs_data[i]; |
397 | 46.0k | } |
398 | 50.7k | } |
399 | 1.74k | } _ZN5doris13VCompoundPred12do_null_predILb1EEEvPKhS3_S3_S3_PhS4_m Line | Count | Source | 382 | 451 | size_t size) { | 383 | | #ifdef NDEBUG | 384 | | #if defined(__clang__) | 385 | | #pragma clang loop vectorize(enable) | 386 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) | 387 | | #pragma GCC ivdep | 388 | | #endif | 389 | | #endif | 390 | 5.15k | for (size_t i = 0; i < size; ++i) { | 391 | 4.70k | if constexpr (is_and) { | 392 | 4.70k | res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); | 393 | 4.70k | res_data[i] = lhs_data[i] & rhs_data[i]; | 394 | | } else { | 395 | | res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); | 396 | | res_data[i] = lhs_data[i] | rhs_data[i]; | 397 | | } | 398 | 4.70k | } | 399 | 451 | } |
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPKhS3_S3_S3_PhS4_m Line | Count | Source | 382 | 1.29k | size_t size) { | 383 | | #ifdef NDEBUG | 384 | | #if defined(__clang__) | 385 | | #pragma clang loop vectorize(enable) | 386 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) | 387 | | #pragma GCC ivdep | 388 | | #endif | 389 | | #endif | 390 | 47.3k | for (size_t i = 0; i < size; ++i) { | 391 | | if constexpr (is_and) { | 392 | | res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); | 393 | | res_data[i] = lhs_data[i] & rhs_data[i]; | 394 | 46.0k | } else { | 395 | 46.0k | res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); | 396 | 46.0k | res_data[i] = lhs_data[i] | rhs_data[i]; | 397 | 46.0k | } | 398 | 46.0k | } | 399 | 1.29k | } |
|
400 | | |
401 | 19.0k | bool _has_const_child() const { |
402 | 19.0k | return std::ranges::any_of(_children, |
403 | 38.0k | [](const VExprSPtr& arg) -> bool { return arg->is_constant(); }); |
404 | 19.0k | } |
405 | | |
406 | | std::pair<const uint8_t*, const uint8_t*> _get_raw_data_and_null_map( |
407 | 32.5k | const ColumnPtr& column, bool has_nullable_column) const { |
408 | 32.5k | if (has_nullable_column) { |
409 | 18.4k | const auto* nullable_column = assert_cast<const ColumnNullable*>(column.get()); |
410 | 18.4k | auto* data_column = |
411 | 18.4k | assert_cast<const ColumnUInt8*>(nullable_column->get_nested_column_ptr().get()) |
412 | 18.4k | ->get_data() |
413 | 18.4k | .data(); |
414 | 18.4k | auto* null_map = nullable_column->get_null_map_column_ptr()->get_data().data(); |
415 | 18.4k | return std::make_pair(data_column, null_map); |
416 | 18.4k | } else { |
417 | 14.0k | auto* data_column = assert_cast<const ColumnUInt8*>(column.get())->get_data().data(); |
418 | 14.0k | return std::make_pair(data_column, nullptr); |
419 | 14.0k | } |
420 | 32.5k | } |
421 | | |
422 | | TExprOpcode::type _op; |
423 | | }; |
424 | | |
425 | | } // namespace doris |