From 93b4ca0f2bd5d0f3721e5211d23918646360a8d3 Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Thu, 22 Dec 2022 13:35:57 +0800 Subject: [PATCH] fix bug of reduce unary not for logic xor --- .../rule/UnionAllIndexScanBaseRule.cpp | 11 ++++---- src/graph/util/ExpressionUtils.cpp | 3 ++- .../expression/LogicalExpression.feature | 27 +++++++++++++++++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/graph/optimizer/rule/UnionAllIndexScanBaseRule.cpp b/src/graph/optimizer/rule/UnionAllIndexScanBaseRule.cpp index 645bb6794c8..1cd1e216a83 100644 --- a/src/graph/optimizer/rule/UnionAllIndexScanBaseRule.cpp +++ b/src/graph/optimizer/rule/UnionAllIndexScanBaseRule.cpp @@ -48,11 +48,12 @@ bool UnionAllIndexScanBaseRule::match(OptContext* ctx, const MatchedResult& matc auto conditionType = condition->kind(); if (condition->isLogicalExpr()) { - // Case1: OR Expr - if (conditionType == ExprKind::kLogicalOr) { - return true; - } - // Case2: AND Expr + // Don't support XOR yet + if (conditionType == ExprKind::kLogicalXor) return false; + if (graph::ExpressionUtils::findAny(static_cast(condition), + {ExprKind::kLogicalXor})) + return false; + if (conditionType == ExprKind::kLogicalOr) return true; if (conditionType == ExprKind::kLogicalAnd && graph::ExpressionUtils::findAny(static_cast(condition), {ExprKind::kRelIn})) { diff --git a/src/graph/util/ExpressionUtils.cpp b/src/graph/util/ExpressionUtils.cpp index 423a8d39e5b..cf8990ededd 100644 --- a/src/graph/util/ExpressionUtils.cpp +++ b/src/graph/util/ExpressionUtils.cpp @@ -544,7 +544,8 @@ Expression *ExpressionUtils::reduceUnaryNotExpr(const Expression *expr) { auto operandMatcher = [](const Expression *operandExpr) -> bool { return (operandExpr->kind() == Expression::Kind::kUnaryNot || (operandExpr->isRelExpr() && operandExpr->kind() != Expression::Kind::kRelREG) || - operandExpr->isLogicalExpr()); + operandExpr->kind() == Expression::Kind::kLogicalAnd || + operandExpr->kind() == Expression::Kind::kLogicalOr); }; // Match the root expression diff --git a/tests/tck/features/expression/LogicalExpression.feature b/tests/tck/features/expression/LogicalExpression.feature index f299cb4fe74..51c5e1144f3 100644 --- a/tests/tck/features/expression/LogicalExpression.feature +++ b/tests/tck/features/expression/LogicalExpression.feature @@ -3,8 +3,10 @@ # This source code is licensed under Apache 2.0 License. Feature: Logical Expression - Scenario: xor crash bug fix 1 + Background: Given a graph with space named "nba" + + Scenario: xor When executing query: """ match (v0:player)-[e:serve]->(v1) where not ((e.start_year == 1997 xor e.end_year != 2016) or (e.start_year > 1000 and e.end_year < 3000)) return count(*) @@ -18,4 +20,25 @@ Feature: Logical Expression """ Then the result should be, in any order: | count(*) | - | 140 | + | 12 | + When executing query: + """ + match (v0:player)-[e:serve]->(v1) with not ((e.start_year == 1997 xor e.end_year != 2016) and (e.start_year > 1000 and e.end_year < 3000)) AS a where a return count(*) + """ + Then the result should be, in any order: + | count(*) | + | 12 | + When executing query: + """ + WITH 1 AS a WHERE NOT((NOT TRUE) XOR TRUE) RETURN COUNT(*) + """ + Then the result should be, in any order: + | COUNT(*) | + | 0 | + When executing query: + """ + WITH 1 AS a RETURN NOT((NOT TRUE) XOR TRUE) AS b + """ + Then the result should be, in any order: + | b | + | false |