Skip to content

Commit

Permalink
Fix mistake push down limit with skip. (#5241)
Browse files Browse the repository at this point in the history
Co-authored-by: Sophie <[email protected]>
  • Loading branch information
Shylock-Hg and Sophie-Xie authored Jan 12, 2023
1 parent a025f92 commit f6a44b4
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ StatusOr<OptRule::TransformResult> 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();
}
Expand Down
3 changes: 2 additions & 1 deletion src/graph/optimizer/rule/GetEdgesTransformRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ StatusOr<OptRule::TransformResult> 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();
}
Expand Down
123 changes: 123 additions & 0 deletions tests/tck/features/match/Scan.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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_]+/ |

0 comments on commit f6a44b4

Please sign in to comment.