Skip to content

Commit

Permalink
[Optimizer] enhance ColumnPruning (#3931)
Browse files Browse the repository at this point in the history
* enhance ColumnPruning

* fix tck

Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
czpmango and Sophie-Xie authored Feb 24, 2022
1 parent 15f8874 commit cab1b79
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/graph/optimizer/rule/CollapseProjectRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ StatusOr<OptRule::TransformResult> CollapseProjectRule::transform(
// disable this case to avoid the expression in ProjBelow being eval multiple
// times
std::unordered_set<std::string> uniquePropRefNames;
std::unordered_set<std::string> multiRefColNames;
for (auto p : allPropRefNames) {
if (!uniquePropRefNames.insert(p).second) {
return TransformResult::noTransform();
// Records PropRefNames that are referenced multiple times
multiRefColNames.insert(p);
}
}

Expand All @@ -75,7 +77,13 @@ StatusOr<OptRule::TransformResult> CollapseProjectRule::transform(
auto colNames = projBelow->colNames();
for (size_t i = 0; i < colNames.size(); ++i) {
if (uniquePropRefNames.count(colNames[i])) {
rewriteMap[colNames[i]] = colsBelow[i]->expr();
auto colExpr = colsBelow[i]->expr();
// disable this case to avoid the expression in ProjBelow being eval multiple
// times
if (!graph::ExpressionUtils::isPropertyExpr(colExpr) && multiRefColNames.count(colNames[i])) {
return TransformResult::noTransform();
}
rewriteMap[colNames[i]] = colExpr;
}
}

Expand Down
11 changes: 5 additions & 6 deletions tests/tck/features/match/With.feature
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,11 @@ Feature: With clause
| ("LeBron James" :player{age: 34, name: "LeBron James"}) | 34 |
And the execution plan should be:
| id | name | dependencies | operator info |
| 8 | Project | 7 | |
| 7 | Filter | 11 | |
| 11 | TopN | 4 | |
| 4 | Project | 3 | |
| 3 | Project | 2 | |
| 2 | AppendVertices | 1 | |
| 9 | Project | 8 | |
| 8 | Filter | 12 | |
| 12 | TopN | 11 | |
| 11 | Project | 3 | |
| 3 | AppendVertices | 1 | |
| 1 | IndexScan | 0 | |
| 0 | Start | | |
When executing query:
Expand Down
41 changes: 41 additions & 0 deletions tests/tck/features/optimizer/CollapseProjectRule.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,44 @@ Feature: Collapse Project Rule
| 3 | Traverse | 8 | |
| 8 | IndexScan | 2 | {"indexCtx": {"columnHints":{"scanType":"PREFIX","column":"name","beginValue":"\"Tim Duncan\"","endValue":"__EMPTY__","includeBegin":"true","includeEnd":"false"}}} |
| 2 | Start | | |
When profiling query:
"""
MATCH (v1:player)-[:like*1..2]-(v2:player)-[:serve]->(v3:team)
WHERE id(v1)=="Tim Duncan" and v3.team.name < "z"
RETURN DISTINCT v2.player.age AS vage ,v2.player.name AS vname
"""
Then the result should be, in any order, with relax comparison:
| vage | vname |
| 31 | "JaVale McGee" |
| 47 | "Shaquille O'Neal" |
| 31 | "Danny Green" |
| 32 | "Rudy Gay" |
| 25 | "Kyle Anderson" |
| 34 | "LeBron James" |
| 33 | "Chris Paul" |
| 28 | "Damian Lillard" |
| 33 | "LaMarcus Aldridge" |
| 32 | "Marco Belinelli" |
| 29 | "James Harden" |
| 30 | "Kevin Durant" |
| 30 | "Russell Westbrook" |
| 36 | "Boris Diaw" |
| 36 | "Tony Parker" |
| 32 | "Aron Baynes" |
| 38 | "Yao Ming" |
| 34 | "Tiago Splitter" |
| 41 | "Manu Ginobili" |
| 42 | "Tim Duncan" |
| 29 | "Dejounte Murray" |
And the execution plan should be:
| id | name | dependencies | operator info |
| 11 | DataCollect | 10 | |
| 10 | Dedup | 14 | |
| 14 | Project | 12 | |
| 12 | Filter | 6 | |
| 6 | AppendVertices | 5 | |
| 5 | Traverse | 4 | |
| 4 | Traverse | 2 | |
| 2 | Dedup | 1 | |
| 1 | PassThrough | 3 | |
| 3 | Start | | |

0 comments on commit cab1b79

Please sign in to comment.