From f6a44b41a8b0f14dba9d0870959b6e22db2db4bd Mon Sep 17 00:00:00 2001 From: shylock <33566796+Shylock-Hg@users.noreply.github.com> Date: Thu, 12 Jan 2023 16:04:49 +0800 Subject: [PATCH] Fix mistake push down limit with skip. (#5241) Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> --- ...tEdgesTransformAppendVerticesLimitRule.cpp | 3 +- .../optimizer/rule/GetEdgesTransformRule.cpp | 3 +- tests/tck/features/match/Scan.feature | 123 ++++++++++++++++++ 3 files changed, 127 insertions(+), 2 deletions(-) diff --git a/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.cpp b/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.cpp index ae2421c811e..c6971129237 100644 --- a/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.cpp +++ b/src/graph/optimizer/rule/GetEdgesTransformAppendVerticesLimitRule.cpp @@ -121,7 +121,8 @@ StatusOr GetEdgesTransformAppendVerticesLimitRule::tra newLimitGroupNode->dependsOn(newAppendVerticesGroup); - auto *newScanEdges = GetEdgesTransformUtils::traverseToScanEdges(traverse, limit->count(qctx)); + auto *newScanEdges = + GetEdgesTransformUtils::traverseToScanEdges(traverse, limit->offset() + limit->count(qctx)); if (newScanEdges == nullptr) { return TransformResult::noTransform(); } diff --git a/src/graph/optimizer/rule/GetEdgesTransformRule.cpp b/src/graph/optimizer/rule/GetEdgesTransformRule.cpp index 695ab2c4dfe..e72e4c213eb 100644 --- a/src/graph/optimizer/rule/GetEdgesTransformRule.cpp +++ b/src/graph/optimizer/rule/GetEdgesTransformRule.cpp @@ -100,7 +100,8 @@ StatusOr GetEdgesTransformRule::transform( newProjectGroupNode->dependsOn(newLimitGroup); newProject->setInputVar(newLimit->outputVar()); - auto *newScanEdges = GetEdgesTransformUtils::traverseToScanEdges(traverse, limit->count(qctx)); + auto *newScanEdges = + GetEdgesTransformUtils::traverseToScanEdges(traverse, limit->offset() + limit->count(qctx)); if (newScanEdges == nullptr) { return TransformResult::noTransform(); } diff --git a/tests/tck/features/match/Scan.feature b/tests/tck/features/match/Scan.feature index fc84d2f70f5..b2acd24964d 100644 --- a/tests/tck/features/match/Scan.feature +++ b/tests/tck/features/match/Scan.feature @@ -78,6 +78,67 @@ Feature: Match seek by scan | Name | | "Mary" | + Scenario: query vertices by scan with skip limit + When executing query: + """ + MATCH (v) + RETURN v.person.name AS name + SKIP 10 LIMIT 4 + """ + Then the result should be, in any order: + | name | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + When executing query: + """ + MATCH (v) + RETURN v.person.name AS name + SKIP 10 LIMIT 5 + """ + Then the result should be, in any order: + | name | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + When executing query: + """ + MATCH (v) + RETURN v.person.name AS name + SKIP 10 LIMIT 7 + """ + Then the result should be, in any order: + | name | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + When executing query: + """ + MATCH (v) + RETURN v.person.name AS name + SKIP 10 LIMIT 11 + """ + Then the result should be, in any order: + | name | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + Scenario: query vertices by scan failed When executing query: """ @@ -168,3 +229,65 @@ Feature: Match seek by scan LIMIT 3 """ Then a ExecutionError should be raised at runtime: Scan vertices or edges need to specify a limit number, or limit number can not push down. + + # #5223 + Scenario: query edge by scan with skip limit + When executing query: + """ + MATCH ()-[e]->() + RETURN type(e) AS Type + SKIP 10 LIMIT 4 + """ + Then the result should be, in any order: + | Type | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + When executing query: + """ + MATCH ()-[e]->() + RETURN type(e) AS Type + SKIP 10 LIMIT 5 + """ + Then the result should be, in any order: + | Type | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + When executing query: + """ + MATCH ()-[e]->() + RETURN type(e) AS Type + SKIP 10 LIMIT 7 + """ + Then the result should be, in any order: + | Type | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + When executing query: + """ + MATCH ()-[e]->() + RETURN type(e) AS Type + SKIP 10 LIMIT 11 + """ + Then the result should be, in any order: + | Type | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ | + | /[\w_]+/ |