From 580151f4111318396bfde0c549634a3bb0ad1198 Mon Sep 17 00:00:00 2001 From: xtcyclist <7731943+xtcyclist@users.noreply.github.com> Date: Fri, 2 Dec 2022 18:41:04 +0800 Subject: [PATCH 1/3] Remove the pruning of kVarProperty and kInputProperty on count. --- src/graph/visitor/PropertyTrackerVisitor.cpp | 3 +-- .../tck/features/optimizer/PrunePropertiesRule.feature | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/graph/visitor/PropertyTrackerVisitor.cpp b/src/graph/visitor/PropertyTrackerVisitor.cpp index 293fa77ebe8..2829094f22a 100644 --- a/src/graph/visitor/PropertyTrackerVisitor.cpp +++ b/src/graph/visitor/PropertyTrackerVisitor.cpp @@ -317,8 +317,7 @@ void PropertyTrackerVisitor::visit(AggregateExpression *expr) { std::transform(funName.begin(), funName.end(), funName.begin(), ::tolower); if (funName == "count") { auto kind = expr->arg()->kind(); - if (kind == Expression::Kind::kConstant || kind == Expression::Kind::kInputProperty || - kind == Expression::Kind::kVarProperty) { + if (kind == Expression::Kind::kConstant) { return; } } diff --git a/tests/tck/features/optimizer/PrunePropertiesRule.feature b/tests/tck/features/optimizer/PrunePropertiesRule.feature index 85b906f7bb3..d17d6df6a40 100644 --- a/tests/tck/features/optimizer/PrunePropertiesRule.feature +++ b/tests/tck/features/optimizer/PrunePropertiesRule.feature @@ -878,3 +878,13 @@ Feature: Prune Properties rule | v.player.name | t.errortag.name | properties(v) | t | | "Tim Duncan" | __NULL__ | {age: 42, name: "Tim Duncan", speciality: "psychology"} | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | | "Tim Duncan" | __NULL__ | {age: 42, name: "Tim Duncan", speciality: "psychology"} | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + + Scenario: no pruning on agg after unwind + Given a graph with space named "nba" + When executing query: + """ + match (v0:player)-[e0]->(v1) where id(v0) == "Tim Duncan" unwind e0.start_year as a return count(a) + """ + Then the result should be, in any order: + | count(a) | + | 5 | From 6765be3f18619854c0bd95ddeaa9dc63e794536e Mon Sep 17 00:00:00 2001 From: xtcyclist <7731943+xtcyclist@users.noreply.github.com> Date: Tue, 6 Dec 2022 11:27:04 +0800 Subject: [PATCH 2/3] update tck. --- .../optimizer/PrunePropertiesRule.feature | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/tck/features/optimizer/PrunePropertiesRule.feature b/tests/tck/features/optimizer/PrunePropertiesRule.feature index d17d6df6a40..ee74b4abb00 100644 --- a/tests/tck/features/optimizer/PrunePropertiesRule.feature +++ b/tests/tck/features/optimizer/PrunePropertiesRule.feature @@ -888,3 +888,59 @@ Feature: Prune Properties rule Then the result should be, in any order: | count(a) | | 5 | + When executing query: + """ + match (v0:player)-[e0]->(v1) where id(v0) == "Tim Duncan" unwind e0.start_year as a return sum(a) + """ + Then the result should be, in any order: + | sum(a) | + | 10025 | + When executing query: + """ + match (v0:player)-[e0]->(v1) where id(v0) == "Tim Duncan" unwind e0.start_year as a return max(a) + """ + Then the result should be, in any order: + | max(a) | + | 2015 | + When executing query: + """ + match (v0:player)-[e0]->(v1) where id(v0) == "Tim Duncan" unwind e0.start_year as a return min(a) + """ + Then the result should be, in any order: + | min(a) | + | 1997 | + When executing query: + """ + match (v0:player)-[e0]->(v1) where id(v0) == "Tim Duncan" unwind e0.start_year as a return avg(a) + """ + Then the result should be, in any order: + | avg(a) | + | 2005.0 | + When executing query: + """ + match (v0:player)-[e0]->(v1) where id(v0) == "Tim Duncan" unwind e0.start_year as a return std(a) + """ + Then the result should be, in any order: + | std(a) | + | 6.542170893518461 | + When executing query: + """ + match (v0:player)-[e0]->(v1) where id(v0) == "Tim Duncan" unwind e0.start_year as a return std(a) + """ + Then the result should be, in any order: + | std(a) | + | 6.542170893518461 | + When executing query: + """ + match (v0:player)-[e0]->(v1) where id(v0) == "Tim Duncan" unwind e0.start_year as a return bit_or(a) + """ + Then the result should be, in any order: + | bit_or(a) | + | 2015 | + When executing query: + """ + match (v0:player)-[e0]->(v1) where id(v0) == "Tim Duncan" unwind e0.start_year as a return bit_and(a) + """ + Then the result should be, in any order: + | bit_and(a) | + | 1984 | From 135d3268f9954f0663daa9facb0dcbbffc8b2c54 Mon Sep 17 00:00:00 2001 From: xtcyclist <7731943+xtcyclist@users.noreply.github.com> Date: Tue, 6 Dec 2022 13:12:39 +0800 Subject: [PATCH 3/3] update tck. --- .../optimizer/PrunePropertiesRule.feature | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/tck/features/optimizer/PrunePropertiesRule.feature b/tests/tck/features/optimizer/PrunePropertiesRule.feature index ee74b4abb00..32a3af6a01f 100644 --- a/tests/tck/features/optimizer/PrunePropertiesRule.feature +++ b/tests/tck/features/optimizer/PrunePropertiesRule.feature @@ -422,14 +422,14 @@ Feature: Prune Properties rule | count(v2) | | 24 | And the execution plan should be: - | id | name | dependencies | operator info | - | 7 | Aggregate | 6 | | - | 6 | Project | 5 | | - | 5 | AppendVertices | 4 | { "props": "[{\"props\":[\"_tag\"],\"tagId\":8}, {\"props\":[\"_tag\"],\"tagId\":9}, {\"props\":[\"_tag\"],\"tagId\":10}]" } | - | 4 | Traverse | 2 | {"vertexProps": "", "edgeProps": "[{\"type\": 3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | - | 2 | Dedup | 1 | | - | 1 | PassThrough | 3 | | - | 3 | Start | | | + | id | name | dependencies | operator info | + | 7 | Aggregate | 6 | | + | 6 | Project | 5 | | + | 5 | AppendVertices | 4 | { "props": "[{\"tagId\":8,\"props\":[\"name\",\"speciality\",\"_tag\"]},{\"props\":[\"_tag\",\"name\",\"age\"],\"tagId\":9},{\"tagId\":10,\"props\":[\"name\",\"_tag\"]}]" } | + | 4 | Traverse | 2 | {"vertexProps": "", "edgeProps": "[{\"type\": 3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | + | 2 | Dedup | 1 | | + | 1 | PassThrough | 3 | | + | 3 | Start | | | When profiling query: """ MATCH p = (v1)-[e:like*1..5]->(v2) @@ -533,27 +533,27 @@ Feature: Prune Properties rule | "Spurs" | 11 | | "Hornets" | 3 | And the execution plan should be: - | id | name | dependencies | operator info | - | 21 | Aggregate | 20 | | - | 20 | Aggregate | 19 | | - | 19 | HashLeftJoin | 10, 25 | | - | 10 | Aggregate | 23 | | - | 23 | Project | 22 | | - | 22 | Filter | 29 | | - | 29 | AppendVertices | 28 | { "props": "[{\"props\":[\"name\", \"_tag\"],\"tagId\":10}]" } | - | 28 | Traverse | 27 | {"vertexProps": "[{\"props\":[\"age\"],\"tagId\":9}]", "edgeProps": "[{\"type\": 4, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | - | 27 | Traverse | 26 | {"vertexProps": "", "edgeProps": "[{\"type\": -5, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | - | 26 | Traverse | 2 | {"vertexProps": "", "edgeProps": "[{\"type\": -3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}, {\"type\": 3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | - | 2 | Dedup | 1 | | - | 1 | PassThrough | 3 | | - | 3 | Start | | | - | 25 | Project | 24 | | - | 24 | Filter | 16 | | - | 16 | AppendVertices | 15 | { "props": "[{\"props\":[\"name\", \"_tag\"],\"tagId\":10}]" } | - | 15 | Traverse | 14 | {"vertexProps": "[{\"props\":[\"age\"],\"tagId\":9}]", "edgeProps": "[{\"type\": 4, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | - | 14 | Traverse | 13 | {"vertexProps": "", "edgeProps": "[{\"type\": -3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | - | 13 | Traverse | 11 | {"vertexProps": "", "edgeProps": "[{\"type\": -3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}, {\"type\": 3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | - | 11 | Argument | | | + | id | name | dependencies | operator info | + | 21 | Aggregate | 20 | | + | 20 | Aggregate | 19 | | + | 19 | HashLeftJoin | 10, 25 | | + | 10 | Aggregate | 23 | | + | 23 | Project | 22 | | + | 22 | Filter | 29 | | + | 29 | AppendVertices | 28 | { "props": "[{\"props\":[\"name\", \"_tag\"],\"tagId\":10}]" } | + | 28 | Traverse | 27 | {"vertexProps": "[{\"tagId\":8,\"props\":[\"name\",\"speciality\",\"_tag\"]},{\"tagId\":9,\"props\":[\"name\",\"age\",\"_tag\"]},{\"props\":[\"name\",\"_tag\"],\"tagId\":10}]", "edgeProps": "[{\"type\":4,\"props\":[\"_dst\",\"_type\",\"_rank\"]}]"} | + | 27 | Traverse | 26 | {"vertexProps": "", "edgeProps": "[{\"type\": -5, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | + | 26 | Traverse | 2 | {"vertexProps": "", "edgeProps": "[{\"type\": -3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}, {\"type\": 3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | + | 2 | Dedup | 1 | | + | 1 | PassThrough | 3 | | + | 3 | Start | | | + | 25 | Project | 24 | | + | 24 | Filter | 16 | | + | 16 | AppendVertices | 15 | { "props": "[{\"props\":[\"name\", \"_tag\"],\"tagId\":10}]" } | + | 15 | Traverse | 14 | {"vertexProps": "[{\"tagId\":8,\"props\":[\"name\",\"speciality\",\"_tag\"]},{\"tagId\":9,\"props\":[\"name\",\"age\",\"_tag\"]},{\"props\":[\"name\",\"_tag\"],\"tagId\":10}]", "edgeProps": "[{\"type\":4,\"props\":[\"_dst\",\"_type\",\"_rank\"]}]"} | + | 14 | Traverse | 13 | {"vertexProps": "", "edgeProps": "[{\"type\": -3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | + | 13 | Traverse | 11 | {"vertexProps": "", "edgeProps": "[{\"type\": -3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}, {\"type\": 3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } | + | 11 | Argument | | | @distonly Scenario: test properties: