Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optimizer] enhance ColumnPruning #3931

Merged
merged 3 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | | |