Skip to content

Commit

Permalink
fix PushLimitDownProjRule
Browse files Browse the repository at this point in the history
  • Loading branch information
czpmango committed Oct 21, 2021
1 parent e179fc4 commit fa5d7eb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/graph/optimizer/rule/PushLimitDownProjectRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ StatusOr<OptRule::TransformResult> PushLimitDownProjectRule::transform(
auto newLimit = static_cast<Limit *>(limit->clone());
auto newLimitGroup = OptGroup::create(octx);
auto newLimitGroupNode = newLimitGroup->makeGroupNode(newLimit);
auto projInputVar = proj->inputVar();
newLimit->setOutputVar(proj->outputVar());
newLimit->setInputVar(proj->inputVar());
// newLimit->setColNames(proj->colNames());
newLimit->setInputVar(projInputVar);
auto *varPtr = octx->qctx()->symTable()->getVar(projInputVar);
DCHECK(!!varPtr);
newLimit->setColNames(varPtr->colNames);

auto newProj = static_cast<Project *>(proj->clone());
auto newProjGroupNode = OptGroupNode::create(octx, newProj, limitGroupNode->group());
newProj->setOutputVar(limit->outputVar());
newProj->setInputVar(newLimit->outputVar());
// newProj->setColNames(limit->colNames());

newProjGroupNode->dependsOn(const_cast<OptGroup *>(newLimitGroupNode->group()));
for (auto dep : projGroupNode->dependencies()) {
Expand Down
40 changes: 40 additions & 0 deletions tests/tck/features/optimizer/PushLimitDownProjectRule.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
Feature: Push Limit down project rule

Background:
Given a graph with space named "nba"

Scenario: push limit down to Project
When profiling query:
"""
MATCH p=(v:player)-[]->(n)
WHERE id(v)=="Tim Duncan" and n.age>30
RETURN p LIMIT 100
"""
Then the result should be, in any order:
| p |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:teammate@0 {end_year: 2016, start_year: 2010}]->("Danny Green" :player{age: 31, name: "Danny Green"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:teammate@0 {end_year: 2016, start_year: 2015}]->("LaMarcus Aldridge" :player{age: 33, name: "LaMarcus Aldridge"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:teammate@0 {end_year: 2016, start_year: 2002}]->("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:teammate@0 {end_year: 2016, start_year: 2001}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"})> |
| <("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"})-[:like@0 {likeness: 95}]->("Tony Parker" :player{age: 36, name: "Tony Parker"})> |
And the execution plan should be:
| id | name | dependencies | operator info |
| 18 | DataCollect | 26 | |
| 26 | Project | 25 | |
| 25 | Limit | 20 | |
| 20 | Filter | 13 | |
| 13 | Project | 12 | |
| 12 | InnerJoin | 11 | |
| 11 | Project | 22 | |
| 22 | GetVertices | 7 | |
| 7 | Filter | 6 | |
| 6 | Project | 5 | |
| 5 | Filter | 24 | |
| 24 | GetNeighbors | 1 | |
| 1 | PassThrough | 0 | |
| 0 | Start | | |

0 comments on commit fa5d7eb

Please sign in to comment.