309254 {
309255 if (!IsGreaterThan(comparison.GetExpressionType()) && !IsLessThan(comparison.GetExpressionType())) {
309256 return FilterResult::UNSUPPORTED;
309257 }
309258
309259 auto &left_node = GetNode(*comparison.left);
309260 reference<Expression> right_node = GetNode(*comparison.right);
309261
309262 do {
309263 if (right_node.get().GetExpressionType() != ExpressionType::OPERATOR_CAST) {
309264 break;
309265 }
309266 auto &bound_cast_expr = right_node.get().Cast<BoundCastExpression>();
309267 if (bound_cast_expr.child->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) {
309268 break;
309269 }
309270 auto &col_ref = bound_cast_expr.child->Cast<BoundColumnRefExpression>();
309271 for (auto &stored_exp : stored_expressions) {
309272 reference<Expression> expr = stored_exp.first;
309273 if (expr.get().GetExpressionType() == ExpressionType::OPERATOR_CAST) {
309274 expr = *(right_node.get().Cast<BoundCastExpression>().child);
309275 }
309276 if (expr.get().GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) {
309277 continue;
309278 }
309279 auto &st_col_ref = expr.get().Cast<BoundColumnRefExpression>();
309280 if (st_col_ref.binding != col_ref.binding) {
309281 continue;
309282 }
309283 if (bound_cast_expr.return_type != stored_exp.second->return_type) {
309284 continue;
309285 }
309286 bound_cast_expr.child = stored_exp.second->Copy();
309287 right_node = GetNode(*bound_cast_expr.child);
309288 break;
309289 }
309290 } while (false);
309291
309292 if (left_node.Equals(right_node)) {
309293 return FilterResult::UNSUPPORTED;
309294 }
309295
309296 idx_t left_equivalence_set = GetEquivalenceSet(left_node);
309297 idx_t right_equivalence_set = GetEquivalenceSet(right_node);
309298 if (left_equivalence_set == right_equivalence_set) {
309299 if (comparison.GetExpressionType() == ExpressionType::COMPARE_GREATERTHAN ||
309300 comparison.GetExpressionType() == ExpressionType::COMPARE_LESSTHAN) {
309301
309302
309303 return FilterResult::UNSATISFIABLE;
309304 }
309305
309306 return FilterResult::SUCCESS;
309307 }
309308
309309 vector<ExpressionValueInformation> &left_constants = constant_values.find(left_equivalence_set)->second;
309310 vector<ExpressionValueInformation> &right_constants = constant_values.find(right_equivalence_set)->second;
309311 bool is_successful = false;
309312 bool is_inserted = false;
309313
309314
309315
309316 for (const auto &right_constant : right_constants) {
309318 info.constant = right_constant.constant;
309319
309320 if (right_constant.comparison_type == ExpressionType::COMPARE_EQUAL) {
309321
309322
309323
309324
309325 info.comparison_type = comparison.GetExpressionType();
309326 } else if ((comparison.GetExpressionType() == ExpressionType::COMPARE_GREATERTHANOREQUALTO &&
309327 IsGreaterThan(right_constant.comparison_type)) ||
309328 (comparison.GetExpressionType() == ExpressionType::COMPARE_LESSTHANOREQUALTO &&
309329 IsLessThan(right_constant.comparison_type))) {
309330
309331
309332 info.comparison_type = right_constant.comparison_type;
309333 if (!is_inserted) {
309334
309335 auto filter = make_uniq<BoundComparisonExpression>(comparison.GetExpressionType(),
309336 comparison.left->Copy(), comparison.right->Copy());
309337 remaining_filters.push_back(std::move(filter));
309338 is_inserted = true;
309339 }
309340 } else if ((comparison.GetExpressionType() == ExpressionType::COMPARE_GREATERTHAN &&
309341 IsGreaterThan(right_constant.comparison_type)) ||
309342 (comparison.GetExpressionType() == ExpressionType::COMPARE_LESSTHAN &&
309343 IsLessThan(right_constant.comparison_type))) {
309344
309345
309346
309347 info.comparison_type = comparison.GetExpressionType();
309348 if (!is_inserted) {
309349
309350 auto filter = make_uniq<BoundComparisonExpression>(comparison.GetExpressionType(),
309351 comparison.left->Copy(), comparison.right->Copy());
309352 remaining_filters.push_back(std::move(filter));
309353 is_inserted = true;
309354 }
309355 } else {
309356
309357 continue;
309358 }
309359
309360 if (AddConstantComparison(left_constants, info) == FilterResult::UNSATISFIABLE) {
309361 return FilterResult::UNSATISFIABLE;
309362 }
309363 is_successful = true;
309364 }
309365 if (is_successful) {
309366 if (is_root) {
309367
309368 auto transitive_filter = FindTransitiveFilter(*comparison.left);
309369 if (transitive_filter != nullptr) {
309370
309371 auto &transitive_cast = transitive_filter->Cast<BoundComparisonExpression>();
309372 auto transitive_result = AddTransitiveFilters(transitive_cast, false);
309373 if (transitive_result == FilterResult::UNSUPPORTED) {
309374
309375 remaining_filters.push_back(std::move(transitive_filter));
309376 }
309377 if (transitive_result == FilterResult::UNSATISFIABLE) {
309378
309379 return FilterResult::UNSATISFIABLE;
309380 }
309381 }
309382 }
309383 return FilterResult::SUCCESS;
309384 }
309385
309386 return FilterResult::UNSUPPORTED;
309387}
void filter(InputArray image, InputArray kernel, OutputArray output)