From cab1b795b13f3c38a45a06e6c27792e31d3ad850 Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Thu, 24 Feb 2022 12:47:10 +0800 Subject: [PATCH] [Optimizer] enhance ColumnPruning (#3931) * enhance ColumnPruning * fix tck Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> --- .../optimizer/rule/CollapseProjectRule.cpp | 12 +++++- tests/tck/features/match/With.feature | 11 +++-- .../optimizer/CollapseProjectRule.feature | 41 +++++++++++++++++++ 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/graph/optimizer/rule/CollapseProjectRule.cpp b/src/graph/optimizer/rule/CollapseProjectRule.cpp index 209f8eb5195..39da3ef888b 100644 --- a/src/graph/optimizer/rule/CollapseProjectRule.cpp +++ b/src/graph/optimizer/rule/CollapseProjectRule.cpp @@ -64,9 +64,11 @@ StatusOr CollapseProjectRule::transform( // disable this case to avoid the expression in ProjBelow being eval multiple // times std::unordered_set uniquePropRefNames; + std::unordered_set multiRefColNames; for (auto p : allPropRefNames) { if (!uniquePropRefNames.insert(p).second) { - return TransformResult::noTransform(); + // Records PropRefNames that are referenced multiple times + multiRefColNames.insert(p); } } @@ -75,7 +77,13 @@ StatusOr 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; } } diff --git a/tests/tck/features/match/With.feature b/tests/tck/features/match/With.feature index 5d8252d8956..d4cdca681c0 100644 --- a/tests/tck/features/match/With.feature +++ b/tests/tck/features/match/With.feature @@ -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: diff --git a/tests/tck/features/optimizer/CollapseProjectRule.feature b/tests/tck/features/optimizer/CollapseProjectRule.feature index 46a572f6274..1e52fcabfa0 100644 --- a/tests/tck/features/optimizer/CollapseProjectRule.feature +++ b/tests/tck/features/optimizer/CollapseProjectRule.feature @@ -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 | | |