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