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