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