diff --git a/src/parser/transform/expression/transform_bool_expr.cpp b/src/parser/transform/expression/transform_bool_expr.cpp index 9fa37086f43..386f7c52f5e 100644 --- a/src/parser/transform/expression/transform_bool_expr.cpp +++ b/src/parser/transform/expression/transform_bool_expr.cpp @@ -32,6 +32,12 @@ unique_ptr Transformer::TransformBoolExpr(PGBoolExpr *root) { // convert COMPARE_IN to COMPARE_NOT_IN next->type = ExpressionType::COMPARE_NOT_IN; result = move(next); + } else if (next->type >= ExpressionType::COMPARE_EQUAL && + next->type <= ExpressionType::COMPARE_GREATERTHANOREQUALTO) { + // NOT on a comparison: we can negate the comparison + // e.g. NOT(x > y) is equivalent to x <= y + next->type = NegateComparisionExpression(next->type); + result = move(next); } else { result = make_unique(ExpressionType::OPERATOR_NOT, move(next)); } diff --git a/src/planner/binder/tableref/plan_joinref.cpp b/src/planner/binder/tableref/plan_joinref.cpp index 757266b601a..2efd47145c7 100644 --- a/src/planner/binder/tableref/plan_joinref.cpp +++ b/src/planner/binder/tableref/plan_joinref.cpp @@ -74,28 +74,6 @@ unique_ptr LogicalComparisonJoin::CreateJoin(JoinType type, uni // successfully created the join condition continue; } - } else if (expr->type == ExpressionType::OPERATOR_NOT) { - auto ¬_expr = (BoundOperatorExpression &)*expr; - assert(not_expr.children.size() == 1); - ExpressionType child_type = not_expr.children[0]->GetExpressionType(); - // the condition is ON NOT (EXPRESSION) - // we can transform this to remove the NOT if the child is a Comparison - // e.g.: - // ON NOT (X = 3) can be turned into ON (X <> 3) - // ON NOT (X > 3) can be turned into ON (X <= 3) - // for non-comparison operators here we just push the filter - if (child_type >= ExpressionType::COMPARE_EQUAL && - child_type <= ExpressionType::COMPARE_GREATERTHANOREQUALTO) { - // switcheroo the child condition - // our join needs to compare explicit left and right sides. So we - // invert the condition to express NOT, this way we can still use - // equi-joins - not_expr.children[0]->type = NegateComparisionExpression(child_type); - if (CreateJoinCondition(*not_expr.children[0], left_bindings, right_bindings, conditions)) { - // successfully created the join condition - continue; - } - } } arbitrary_expressions.push_back(move(expr)); }