Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | #include <gen_cpp/Opcodes_types.h> |
20 | | |
21 | | #include <algorithm> |
22 | | #include <cstdint> |
23 | | |
24 | | #include "common/logging.h" |
25 | | #include "common/status.h" |
26 | | #include "core/assert_cast.h" |
27 | | #include "core/column/column.h" |
28 | | #include "core/column/column_nullable.h" |
29 | | #include "exprs/vectorized_fn_call.h" |
30 | | #include "exprs/vexpr_context.h" |
31 | | #include "exprs/vexpr_fwd.h" |
32 | | #include "storage/index/zone_map/zonemap_eval_context.h" |
33 | | #include "util/simd/bits.h" |
34 | | |
35 | | namespace doris { |
36 | | |
37 | 718 | inline std::string compound_operator_to_string(TExprOpcode::type op) { |
38 | 718 | if (op == TExprOpcode::COMPOUND_AND) { |
39 | 93 | return "and"; |
40 | 625 | } else if (op == TExprOpcode::COMPOUND_OR) { |
41 | 591 | return "or"; |
42 | 591 | } else { |
43 | 34 | return "not"; |
44 | 34 | } |
45 | 718 | } |
46 | | |
47 | | class VCompoundPred : public VectorizedFnCall { |
48 | | ENABLE_FACTORY_CREATOR(VCompoundPred); |
49 | | |
50 | | public: |
51 | 718 | VCompoundPred(const TExprNode& node) : VectorizedFnCall(node) { |
52 | 718 | _op = node.opcode; |
53 | 718 | _fn.name.function_name = compound_operator_to_string(_op); |
54 | 718 | _expr_name = fmt::format("VCompoundPredicate[{}](arguments={},return={})", |
55 | 718 | _fn.name.function_name, get_child_names(), _data_type->get_name()); |
56 | 718 | } |
57 | | |
58 | | #ifdef BE_TEST |
59 | | VCompoundPred() = default; |
60 | | #endif |
61 | | |
62 | 1.82k | const std::string& expr_name() const override { return _expr_name; } |
63 | | |
64 | 243 | bool can_evaluate_zonemap_filter() const override { |
65 | 243 | switch (_op) { |
66 | 39 | case TExprOpcode::COMPOUND_AND: |
67 | 39 | return std::ranges::any_of(_children, [](const VExprSPtr& child) { |
68 | 39 | return child->can_evaluate_zonemap_filter(); |
69 | 39 | }); |
70 | 204 | case TExprOpcode::COMPOUND_OR: |
71 | 405 | return !_children.empty() && std::ranges::all_of(_children, [](const VExprSPtr& child) { |
72 | 405 | return child->can_evaluate_zonemap_filter(); |
73 | 405 | }); |
74 | 0 | case TExprOpcode::COMPOUND_NOT: |
75 | 0 | return false; |
76 | 0 | default: |
77 | 0 | return false; |
78 | 243 | } |
79 | 243 | } |
80 | | |
81 | 87 | ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const override { |
82 | 87 | switch (_op) { |
83 | 7 | case TExprOpcode::COMPOUND_AND: { |
84 | 14 | for (const auto& child : _children) { |
85 | 14 | if (!child->can_evaluate_zonemap_filter()) { |
86 | 3 | continue; |
87 | 3 | } |
88 | 11 | if (child->evaluate_zonemap_filter(ctx) == ZoneMapFilterResult::kNoMatch) { |
89 | 2 | return ZoneMapFilterResult::kNoMatch; |
90 | 2 | } |
91 | 11 | } |
92 | 5 | return ZoneMapFilterResult::kMayMatch; |
93 | 7 | } |
94 | 79 | case TExprOpcode::COMPOUND_OR: { |
95 | 97 | for (const auto& child : _children) { |
96 | 97 | DORIS_CHECK(child->can_evaluate_zonemap_filter()); |
97 | 97 | if (child->evaluate_zonemap_filter(ctx) != ZoneMapFilterResult::kNoMatch) { |
98 | 70 | return ZoneMapFilterResult::kMayMatch; |
99 | 70 | } |
100 | 97 | } |
101 | 9 | return ZoneMapFilterResult::kNoMatch; |
102 | 79 | } |
103 | 1 | case TExprOpcode::COMPOUND_NOT: |
104 | 1 | return unsupported_zonemap_filter(ctx); |
105 | 0 | default: |
106 | 0 | return unsupported_zonemap_filter(ctx); |
107 | 87 | } |
108 | 87 | } |
109 | | |
110 | 0 | Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) override { |
111 | 0 | segment_v2::InvertedIndexResultBitmap res; |
112 | 0 | bool all_pass = true; |
113 | |
|
114 | 0 | switch (_op) { |
115 | 0 | case TExprOpcode::COMPOUND_OR: { |
116 | 0 | for (const auto& child : _children) { |
117 | 0 | if (Status st = child->evaluate_inverted_index(context, segment_num_rows); |
118 | 0 | !st.ok()) { |
119 | 0 | LOG(ERROR) << "expr:" << child->expr_name() |
120 | 0 | << " evaluate_inverted_index error:" << st.to_string(); |
121 | 0 | all_pass = false; |
122 | 0 | continue; |
123 | 0 | } |
124 | 0 | auto inverted_index_context = context->get_index_context(); |
125 | 0 | if (inverted_index_context->has_index_result_for_expr(child.get())) { |
126 | 0 | const auto* index_result = |
127 | 0 | inverted_index_context->get_index_result_for_expr(child.get()); |
128 | 0 | if (res.is_empty()) { |
129 | 0 | res = *index_result; |
130 | 0 | } else { |
131 | 0 | res |= *index_result; |
132 | 0 | } |
133 | 0 | if (inverted_index_context->get_score_runtime() == nullptr) { |
134 | 0 | if (res.get_data_bitmap()->cardinality() == segment_num_rows) { |
135 | 0 | break; // Early exit if result is full |
136 | 0 | } |
137 | 0 | } |
138 | 0 | } else { |
139 | 0 | all_pass = false; |
140 | 0 | } |
141 | 0 | } |
142 | 0 | break; |
143 | 0 | } |
144 | 0 | case TExprOpcode::COMPOUND_AND: { |
145 | 0 | for (const auto& child : _children) { |
146 | 0 | if (Status st = child->evaluate_inverted_index(context, segment_num_rows); |
147 | 0 | !st.ok()) { |
148 | 0 | LOG(ERROR) << "expr:" << child->expr_name() |
149 | 0 | << " evaluate_inverted_index error:" << st.to_string(); |
150 | 0 | all_pass = false; |
151 | 0 | continue; |
152 | 0 | } |
153 | 0 | if (context->get_index_context()->has_index_result_for_expr(child.get())) { |
154 | 0 | const auto* index_result = |
155 | 0 | context->get_index_context()->get_index_result_for_expr(child.get()); |
156 | 0 | if (res.is_empty()) { |
157 | 0 | res = *index_result; |
158 | 0 | } else { |
159 | 0 | res &= *index_result; |
160 | 0 | } |
161 | |
|
162 | 0 | if (res.get_data_bitmap()->isEmpty()) { |
163 | 0 | break; // Early exit if result is empty |
164 | 0 | } |
165 | 0 | } else { |
166 | 0 | all_pass = false; |
167 | 0 | } |
168 | 0 | } |
169 | 0 | break; |
170 | 0 | } |
171 | 0 | case TExprOpcode::COMPOUND_NOT: { |
172 | 0 | const auto& child = _children[0]; |
173 | 0 | Status st = child->evaluate_inverted_index(context, segment_num_rows); |
174 | 0 | if (!st.ok()) { |
175 | 0 | LOG(ERROR) << "expr:" << child->expr_name() |
176 | 0 | << " evaluate_inverted_index error:" << st.to_string(); |
177 | 0 | return st; |
178 | 0 | } |
179 | | |
180 | 0 | if (context->get_index_context()->has_index_result_for_expr(child.get())) { |
181 | 0 | const auto* index_result = |
182 | 0 | context->get_index_context()->get_index_result_for_expr(child.get()); |
183 | 0 | roaring::Roaring full_result; |
184 | 0 | full_result.addRange(0, segment_num_rows); |
185 | 0 | res = index_result->op_not(&full_result); |
186 | 0 | } else { |
187 | 0 | all_pass = false; |
188 | 0 | } |
189 | 0 | break; |
190 | 0 | } |
191 | 0 | default: |
192 | 0 | return Status::NotSupported( |
193 | 0 | "Compound operator must be AND, OR, or NOT to execute with inverted index."); |
194 | 0 | } |
195 | | |
196 | 0 | if (all_pass && !res.is_empty()) { |
197 | 0 | context->get_index_context()->set_index_result_for_expr(this, res); |
198 | 0 | } |
199 | 0 | return Status::OK(); |
200 | 0 | } |
201 | | |
202 | | Status execute_column_impl(VExprContext* context, const Block* block, const Selector* selector, |
203 | 7.05k | size_t count, ColumnPtr& result_column) const override { |
204 | 7.05k | if (fast_execute(context, selector, count, result_column)) { |
205 | 0 | return Status::OK(); |
206 | 0 | } |
207 | 7.05k | if (get_num_children() == 1 || _has_const_child()) { |
208 | 32 | return VectorizedFnCall::execute_column_impl(context, block, selector, count, |
209 | 32 | result_column); |
210 | 32 | } |
211 | | |
212 | 7.02k | ColumnPtr lhs_column; |
213 | 7.02k | RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, lhs_column)); |
214 | 7.02k | lhs_column = lhs_column->convert_to_full_column_if_const(); |
215 | 7.02k | size_t size = lhs_column->size(); |
216 | | |
217 | 7.02k | bool lhs_is_nullable = lhs_column->is_nullable(); |
218 | 7.02k | auto [lhs_data_column, lhs_null_map] = |
219 | 7.02k | _get_raw_data_and_null_map(lhs_column, lhs_is_nullable); |
220 | 7.02k | size_t filted = simd::count_zero_num((int8_t*)lhs_data_column, size); |
221 | 7.02k | bool lhs_all_true = (filted == 0); |
222 | 7.02k | bool lhs_all_false = (filted == size); |
223 | | |
224 | 7.02k | bool lhs_all_is_not_null = false; |
225 | 7.02k | if (lhs_is_nullable) { |
226 | 5.32k | filted = simd::count_zero_num((int8_t*)lhs_null_map, size); |
227 | 5.32k | lhs_all_is_not_null = (filted == size); |
228 | 5.32k | } |
229 | | |
230 | 7.02k | ColumnPtr rhs_column = nullptr; |
231 | 7.02k | const uint8_t* __restrict rhs_data_column = nullptr; |
232 | 7.02k | const uint8_t* __restrict rhs_null_map = nullptr; |
233 | 7.02k | bool rhs_is_nullable = false; |
234 | 7.02k | bool rhs_all_true = false; |
235 | 7.02k | bool rhs_all_false = false; |
236 | 7.02k | bool rhs_all_is_not_null = false; |
237 | 7.02k | bool result_is_nullable = _data_type->is_nullable(); |
238 | | |
239 | 7.02k | auto get_rhs_colum = [&]() { |
240 | 6.55k | if (!rhs_column) { |
241 | 6.55k | RETURN_IF_ERROR( |
242 | 6.55k | _children[1]->execute_column(context, block, selector, count, rhs_column)); |
243 | 6.55k | rhs_column = rhs_column->convert_to_full_column_if_const(); |
244 | 6.55k | rhs_is_nullable = rhs_column->is_nullable(); |
245 | 6.55k | auto rhs_nullable_column = _get_raw_data_and_null_map(rhs_column, rhs_is_nullable); |
246 | 6.55k | rhs_data_column = rhs_nullable_column.first; |
247 | 6.55k | rhs_null_map = rhs_nullable_column.second; |
248 | 6.55k | size_t filted = simd::count_zero_num((int8_t*)rhs_data_column, size); |
249 | 6.55k | rhs_all_true = (filted == 0); |
250 | 6.55k | rhs_all_false = (filted == size); |
251 | 6.55k | if (rhs_is_nullable) { |
252 | 6.27k | filted = simd::count_zero_num((int8_t*)rhs_null_map, size); |
253 | 6.27k | rhs_all_is_not_null = (filted == size); |
254 | 6.27k | } |
255 | 6.55k | } |
256 | 6.55k | return Status::OK(); |
257 | 6.55k | }; |
258 | | |
259 | 7.02k | auto return_result_column_id = [&](ColumnPtr& arg_column) { |
260 | 6.77k | result_column = std::move(*arg_column).mutate(); |
261 | 6.77k | if (result_is_nullable && !result_column->is_nullable()) { |
262 | 283 | result_column = make_nullable(result_column); |
263 | 283 | } |
264 | 6.77k | }; |
265 | | |
266 | 7.02k | auto create_null_map_column = [&](ColumnPtr& null_map_column, |
267 | 7.02k | const uint8_t* __restrict null_map_data) { |
268 | 472 | if (null_map_data == nullptr) { |
269 | 79 | null_map_column = ColumnUInt8::create(size, 0); |
270 | 79 | null_map_data = |
271 | 79 | assert_cast<const ColumnUInt8*>(null_map_column.get())->get_data().data(); |
272 | 79 | } |
273 | 472 | return null_map_data; |
274 | 472 | }; |
275 | | |
276 | 7.02k | auto vector_vector = [&]<bool is_and_op>() { |
277 | 12 | MutableColumnPtr mutable_result_column; |
278 | 12 | uint8_t* __restrict result_data_column = nullptr; |
279 | 12 | const uint8_t* __restrict other_data_column = rhs_data_column; |
280 | 12 | if (lhs_column->use_count() == 1) { |
281 | 10 | mutable_result_column = IColumn::mutate(std::move(lhs_column)); |
282 | 10 | result_data_column = |
283 | 10 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); |
284 | 10 | } else if (rhs_column->use_count() == 1) { |
285 | 0 | mutable_result_column = IColumn::mutate(std::move(rhs_column)); |
286 | 0 | result_data_column = |
287 | 0 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); |
288 | 0 | other_data_column = lhs_data_column; |
289 | 2 | } else { |
290 | 2 | mutable_result_column = lhs_column->clone_resized(size); |
291 | 2 | result_data_column = |
292 | 2 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); |
293 | 2 | } |
294 | | |
295 | 12 | do_not_null_pred<is_and_op>(result_data_column, other_data_column, size); |
296 | 12 | result_column = std::move(mutable_result_column); |
297 | 12 | }; _ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb1EEEDav Line | Count | Source | 276 | 9 | auto vector_vector = [&]<bool is_and_op>() { | 277 | 9 | MutableColumnPtr mutable_result_column; | 278 | 9 | uint8_t* __restrict result_data_column = nullptr; | 279 | 9 | const uint8_t* __restrict other_data_column = rhs_data_column; | 280 | 9 | if (lhs_column->use_count() == 1) { | 281 | 9 | mutable_result_column = IColumn::mutate(std::move(lhs_column)); | 282 | 9 | result_data_column = | 283 | 9 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 284 | 9 | } else if (rhs_column->use_count() == 1) { | 285 | 0 | mutable_result_column = IColumn::mutate(std::move(rhs_column)); | 286 | 0 | result_data_column = | 287 | 0 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 288 | 0 | other_data_column = lhs_data_column; | 289 | 0 | } else { | 290 | 0 | mutable_result_column = lhs_column->clone_resized(size); | 291 | 0 | result_data_column = | 292 | 0 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 293 | 0 | } | 294 | | | 295 | 9 | do_not_null_pred<is_and_op>(result_data_column, other_data_column, size); | 296 | 9 | result_column = std::move(mutable_result_column); | 297 | 9 | }; |
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE_clILb0EEEDav Line | Count | Source | 276 | 3 | auto vector_vector = [&]<bool is_and_op>() { | 277 | 3 | MutableColumnPtr mutable_result_column; | 278 | 3 | uint8_t* __restrict result_data_column = nullptr; | 279 | 3 | const uint8_t* __restrict other_data_column = rhs_data_column; | 280 | 3 | if (lhs_column->use_count() == 1) { | 281 | 1 | mutable_result_column = IColumn::mutate(std::move(lhs_column)); | 282 | 1 | result_data_column = | 283 | 1 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 284 | 2 | } else if (rhs_column->use_count() == 1) { | 285 | 0 | mutable_result_column = IColumn::mutate(std::move(rhs_column)); | 286 | 0 | result_data_column = | 287 | 0 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 288 | 0 | other_data_column = lhs_data_column; | 289 | 2 | } else { | 290 | 2 | mutable_result_column = lhs_column->clone_resized(size); | 291 | 2 | result_data_column = | 292 | 2 | assert_cast<ColumnUInt8*>(mutable_result_column.get())->get_data().data(); | 293 | 2 | } | 294 | | | 295 | 3 | do_not_null_pred<is_and_op>(result_data_column, other_data_column, size); | 296 | 3 | result_column = std::move(mutable_result_column); | 297 | 3 | }; |
|
298 | 7.02k | auto vector_vector_null = [&]<bool is_and_op>() { |
299 | 236 | auto col_res = ColumnUInt8::create(size); |
300 | 236 | auto col_nulls = ColumnUInt8::create(size); |
301 | | |
302 | 236 | auto* __restrict res_datas = col_res->get_data().data(); |
303 | 236 | auto* __restrict res_nulls = col_nulls->get_data().data(); |
304 | 236 | ColumnPtr temp_null_map = nullptr; |
305 | | // maybe both children are nullable / or one of children is nullable |
306 | 236 | auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map); |
307 | 236 | auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map); |
308 | 236 | auto* __restrict lhs_data_column_tmp = lhs_data_column; |
309 | 236 | auto* __restrict rhs_data_column_tmp = rhs_data_column; |
310 | | |
311 | 236 | do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp, |
312 | 236 | rhs_null_map_tmp, res_datas, res_nulls, size); |
313 | | |
314 | 236 | result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls)); |
315 | 236 | }; _ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb1EEEDav Line | Count | Source | 298 | 44 | auto vector_vector_null = [&]<bool is_and_op>() { | 299 | 44 | auto col_res = ColumnUInt8::create(size); | 300 | 44 | auto col_nulls = ColumnUInt8::create(size); | 301 | | | 302 | 44 | auto* __restrict res_datas = col_res->get_data().data(); | 303 | 44 | auto* __restrict res_nulls = col_nulls->get_data().data(); | 304 | 44 | ColumnPtr temp_null_map = nullptr; | 305 | | // maybe both children are nullable / or one of children is nullable | 306 | 44 | auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map); | 307 | 44 | auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map); | 308 | 44 | auto* __restrict lhs_data_column_tmp = lhs_data_column; | 309 | 44 | auto* __restrict rhs_data_column_tmp = rhs_data_column; | 310 | | | 311 | 44 | do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp, | 312 | 44 | rhs_null_map_tmp, res_datas, res_nulls, size); | 313 | | | 314 | 44 | result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls)); | 315 | 44 | }; |
_ZZNK5doris13VCompoundPred19execute_column_implEPNS_12VExprContextEPKNS_5BlockEPKNS_8PODArrayIjLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEEmRNS_3COWINS_7IColumnEE13immutable_ptrISE_EEENKUlTnbvE0_clILb0EEEDav Line | Count | Source | 298 | 192 | auto vector_vector_null = [&]<bool is_and_op>() { | 299 | 192 | auto col_res = ColumnUInt8::create(size); | 300 | 192 | auto col_nulls = ColumnUInt8::create(size); | 301 | | | 302 | 192 | auto* __restrict res_datas = col_res->get_data().data(); | 303 | 192 | auto* __restrict res_nulls = col_nulls->get_data().data(); | 304 | 192 | ColumnPtr temp_null_map = nullptr; | 305 | | // maybe both children are nullable / or one of children is nullable | 306 | 192 | auto* __restrict lhs_null_map_tmp = create_null_map_column(temp_null_map, lhs_null_map); | 307 | 192 | auto* __restrict rhs_null_map_tmp = create_null_map_column(temp_null_map, rhs_null_map); | 308 | 192 | auto* __restrict lhs_data_column_tmp = lhs_data_column; | 309 | 192 | auto* __restrict rhs_data_column_tmp = rhs_data_column; | 310 | | | 311 | 192 | do_null_pred<is_and_op>(lhs_data_column_tmp, lhs_null_map_tmp, rhs_data_column_tmp, | 312 | 192 | rhs_null_map_tmp, res_datas, res_nulls, size); | 313 | | | 314 | 192 | result_column = ColumnNullable::create(std::move(col_res), std::move(col_nulls)); | 315 | 192 | }; |
|
316 | | |
317 | | // false and NULL ----> 0 |
318 | | // true and NULL ----> NULL |
319 | 7.02k | if (_op == TExprOpcode::COMPOUND_AND) { |
320 | | //1. not null column: all data is false |
321 | | //2. nullable column: null map all is not null |
322 | 272 | if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) { |
323 | | // false and any = false, return lhs |
324 | 186 | return_result_column_id(lhs_column); |
325 | 186 | } else { |
326 | 86 | RETURN_IF_ERROR(get_rhs_colum()); |
327 | | |
328 | 86 | if ((lhs_all_true && !lhs_is_nullable) || //not null column |
329 | 86 | (lhs_all_true && lhs_all_is_not_null)) { //nullable column |
330 | | // true and any = any, return rhs |
331 | | |
332 | 10 | return_result_column_id(rhs_column); |
333 | 76 | } else if ((rhs_all_false && !rhs_is_nullable) || |
334 | 76 | (rhs_all_false && rhs_all_is_not_null)) { |
335 | | // any and false = false, return rhs |
336 | 17 | return_result_column_id(rhs_column); |
337 | 59 | } else if ((rhs_all_true && !rhs_is_nullable) || |
338 | 59 | (rhs_all_true && rhs_all_is_not_null)) { |
339 | | // any and true = any, return lhs |
340 | 6 | return_result_column_id(lhs_column); |
341 | 53 | } else { |
342 | 53 | if (!result_is_nullable) { |
343 | 9 | vector_vector.template operator()<true>(); |
344 | 44 | } else { |
345 | 44 | vector_vector_null.template operator()<true>(); |
346 | 44 | } |
347 | 53 | } |
348 | 86 | } |
349 | 6.75k | } else if (_op == TExprOpcode::COMPOUND_OR) { |
350 | | // true or NULL ----> 1 |
351 | | // false or NULL ----> NULL |
352 | 6.75k | if ((lhs_all_true && !lhs_is_nullable) || (lhs_all_true && lhs_all_is_not_null)) { |
353 | | // true or any = true, return lhs |
354 | 277 | return_result_column_id(lhs_column); |
355 | 6.47k | } else { |
356 | 6.47k | RETURN_IF_ERROR(get_rhs_colum()); |
357 | 6.47k | if ((lhs_all_false && !lhs_is_nullable) || (lhs_all_false && lhs_all_is_not_null)) { |
358 | | // false or any = any, return rhs |
359 | 6.22k | return_result_column_id(rhs_column); |
360 | 6.22k | } else if ((rhs_all_true && !rhs_is_nullable) || |
361 | 252 | (rhs_all_true && rhs_all_is_not_null)) { |
362 | | // any or true = true, return rhs |
363 | 19 | return_result_column_id(rhs_column); |
364 | 233 | } else if ((rhs_all_false && !rhs_is_nullable) || |
365 | 233 | (rhs_all_false && rhs_all_is_not_null)) { |
366 | | // any or false = any, return lhs |
367 | 39 | return_result_column_id(lhs_column); |
368 | 194 | } else { |
369 | 194 | if (!result_is_nullable) { |
370 | 3 | vector_vector.template operator()<false>(); |
371 | 191 | } else { |
372 | 191 | vector_vector_null.template operator()<false>(); |
373 | 191 | } |
374 | 194 | } |
375 | 6.47k | } |
376 | 6.75k | } else { |
377 | 1 | return Status::InternalError("Compound operator must be AND or OR."); |
378 | 1 | } |
379 | | |
380 | 7.02k | DCHECK_EQ(result_column->size(), count); |
381 | 7.02k | return Status::OK(); |
382 | 7.02k | } |
383 | | |
384 | 89 | double execute_cost() const override { |
385 | 89 | double cost = 0.3; |
386 | 171 | for (const auto& child : _children) { |
387 | 171 | cost += child->execute_cost(); |
388 | 171 | } |
389 | 89 | return cost; |
390 | 89 | } |
391 | | |
392 | | private: |
393 | 73.9k | static inline constexpr uint8_t apply_and_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) { |
394 | | // (<> && false) is false, (true && NULL) is NULL |
395 | 73.9k | return (l_null & r_null) | (r_null & (l_null ^ a)) | (l_null & (r_null ^ b)); |
396 | 73.9k | } |
397 | 238k | static inline constexpr uint8_t apply_or_null(UInt8 a, UInt8 l_null, UInt8 b, UInt8 r_null) { |
398 | | // (<> || true) is true, (false || NULL) is NULL |
399 | 238k | return (l_null & r_null) | (r_null & (r_null ^ a)) | (l_null & (l_null ^ b)); |
400 | 238k | } |
401 | | |
402 | | template <bool is_and> |
403 | | void static do_not_null_pred(uint8_t* __restrict lhs, const uint8_t* __restrict rhs, |
404 | 12 | size_t size) { |
405 | | #ifdef NDEBUG |
406 | | #if defined(__clang__) |
407 | | #pragma clang loop vectorize(enable) |
408 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) |
409 | | #pragma GCC ivdep |
410 | | #endif |
411 | | #endif |
412 | 28.1k | for (size_t i = 0; i < size; ++i) { |
413 | 28.1k | if constexpr (is_and) { |
414 | 28.0k | lhs[i] &= rhs[i]; |
415 | 28.0k | } else { |
416 | 39 | lhs[i] |= rhs[i]; |
417 | 39 | } |
418 | 28.1k | } |
419 | 12 | } _ZN5doris13VCompoundPred16do_not_null_predILb1EEEvPhPKhm Line | Count | Source | 404 | 9 | size_t size) { | 405 | | #ifdef NDEBUG | 406 | | #if defined(__clang__) | 407 | | #pragma clang loop vectorize(enable) | 408 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) | 409 | | #pragma GCC ivdep | 410 | | #endif | 411 | | #endif | 412 | 28.0k | for (size_t i = 0; i < size; ++i) { | 413 | 28.0k | if constexpr (is_and) { | 414 | 28.0k | lhs[i] &= rhs[i]; | 415 | | } else { | 416 | | lhs[i] |= rhs[i]; | 417 | | } | 418 | 28.0k | } | 419 | 9 | } |
_ZN5doris13VCompoundPred16do_not_null_predILb0EEEvPhPKhm Line | Count | Source | 404 | 3 | size_t size) { | 405 | | #ifdef NDEBUG | 406 | | #if defined(__clang__) | 407 | | #pragma clang loop vectorize(enable) | 408 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) | 409 | | #pragma GCC ivdep | 410 | | #endif | 411 | | #endif | 412 | 42 | for (size_t i = 0; i < size; ++i) { | 413 | | if constexpr (is_and) { | 414 | | lhs[i] &= rhs[i]; | 415 | 39 | } else { | 416 | 39 | lhs[i] |= rhs[i]; | 417 | 39 | } | 418 | 39 | } | 419 | 3 | } |
|
420 | | |
421 | | template <bool is_and> |
422 | | void static do_null_pred(const uint8_t* __restrict lhs_data, const uint8_t* __restrict lhs_null, |
423 | | const uint8_t* __restrict rhs_data, const uint8_t* __restrict rhs_null, |
424 | | uint8_t* __restrict res_data, uint8_t* __restrict res_null, |
425 | 236 | size_t size) { |
426 | | #ifdef NDEBUG |
427 | | #if defined(__clang__) |
428 | | #pragma clang loop vectorize(enable) |
429 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) |
430 | | #pragma GCC ivdep |
431 | | #endif |
432 | | #endif |
433 | 312k | for (size_t i = 0; i < size; ++i) { |
434 | 312k | if constexpr (is_and) { |
435 | 73.9k | res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); |
436 | 73.9k | res_data[i] = lhs_data[i] & rhs_data[i]; |
437 | 238k | } else { |
438 | 238k | res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); |
439 | 238k | res_data[i] = lhs_data[i] | rhs_data[i]; |
440 | 238k | } |
441 | 312k | } |
442 | 236 | } _ZN5doris13VCompoundPred12do_null_predILb1EEEvPKhS3_S3_S3_PhS4_m Line | Count | Source | 425 | 44 | size_t size) { | 426 | | #ifdef NDEBUG | 427 | | #if defined(__clang__) | 428 | | #pragma clang loop vectorize(enable) | 429 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) | 430 | | #pragma GCC ivdep | 431 | | #endif | 432 | | #endif | 433 | 74.0k | for (size_t i = 0; i < size; ++i) { | 434 | 73.9k | if constexpr (is_and) { | 435 | 73.9k | res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); | 436 | 73.9k | res_data[i] = lhs_data[i] & rhs_data[i]; | 437 | | } else { | 438 | | res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); | 439 | | res_data[i] = lhs_data[i] | rhs_data[i]; | 440 | | } | 441 | 73.9k | } | 442 | 44 | } |
_ZN5doris13VCompoundPred12do_null_predILb0EEEvPKhS3_S3_S3_PhS4_m Line | Count | Source | 425 | 192 | size_t size) { | 426 | | #ifdef NDEBUG | 427 | | #if defined(__clang__) | 428 | | #pragma clang loop vectorize(enable) | 429 | | #elif defined(__GNUC__) && (__GNUC__ >= 5) | 430 | | #pragma GCC ivdep | 431 | | #endif | 432 | | #endif | 433 | 238k | for (size_t i = 0; i < size; ++i) { | 434 | | if constexpr (is_and) { | 435 | | res_null[i] = apply_and_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); | 436 | | res_data[i] = lhs_data[i] & rhs_data[i]; | 437 | 238k | } else { | 438 | 238k | res_null[i] = apply_or_null(lhs_data[i], lhs_null[i], rhs_data[i], rhs_null[i]); | 439 | 238k | res_data[i] = lhs_data[i] | rhs_data[i]; | 440 | 238k | } | 441 | 238k | } | 442 | 192 | } |
|
443 | | |
444 | 7.02k | bool _has_const_child() const { |
445 | 7.02k | return std::ranges::any_of(_children, |
446 | 14.0k | [](const VExprSPtr& arg) -> bool { return arg->is_constant(); }); |
447 | 7.02k | } |
448 | | |
449 | | std::pair<const uint8_t*, const uint8_t*> _get_raw_data_and_null_map( |
450 | 13.5k | const ColumnPtr& column, bool has_nullable_column) const { |
451 | 13.5k | if (has_nullable_column) { |
452 | 11.5k | const auto* nullable_column = assert_cast<const ColumnNullable*>(column.get()); |
453 | 11.5k | auto* data_column = |
454 | 11.5k | assert_cast<const ColumnUInt8*>(nullable_column->get_nested_column_ptr().get()) |
455 | 11.5k | ->get_data() |
456 | 11.5k | .data(); |
457 | 11.5k | auto* null_map = nullable_column->get_null_map_column_ptr()->get_data().data(); |
458 | 11.5k | return std::make_pair(data_column, null_map); |
459 | 11.5k | } else { |
460 | 1.98k | auto* data_column = assert_cast<const ColumnUInt8*>(column.get())->get_data().data(); |
461 | 1.98k | return std::make_pair(data_column, nullptr); |
462 | 1.98k | } |
463 | 13.5k | } |
464 | | |
465 | | TExprOpcode::type _op; |
466 | | }; |
467 | | |
468 | | } // namespace doris |