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