Skip to content

Commit

Permalink
Fix wrong properties prune in length function. (#4884)
Browse files Browse the repository at this point in the history
Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
Shylock-Hg and Sophie-Xie committed Nov 18, 2022
1 parent ae7e2fe commit b5df04f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
4 changes: 3 additions & 1 deletion src/graph/visitor/PropertyTrackerVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,10 @@ void PropertyTrackerVisitor::visit(AttributeExpression *expr) {
}

void PropertyTrackerVisitor::visit(FunctionCallExpression *expr) {
// length function support `STRING` input too, so we can't ignore it directly
// TODO add type info to variable to help optimize it.
static const std::unordered_set<std::string> ignoreFuncs = {
"src", "dst", "type", "typeid", "id", "rank", "length"};
"src", "dst", "type", "typeid", "id", "rank" /*, "length"*/};

auto funName = expr->name();
std::transform(funName.begin(), funName.end(), funName.begin(), ::tolower);
Expand Down
18 changes: 18 additions & 0 deletions tests/tck/features/bugfix/NullInputOfLength.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2022 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
Feature: Null input of length function

Background:
Given a graph with space named "nba"

Scenario: Null input of length function
When executing query:
"""
match p = (v)-[:like]->() where id(v) == 'Tim Duncan'
return length(v.player.name) as l, length(p) as lp
"""
Then the result should be, in any order:
| l | lp |
| 10 | 1 |
| 10 | 1 |
44 changes: 22 additions & 22 deletions tests/tck/features/optimizer/PrunePropertiesRule.feature
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,14 @@ Feature: Prune Properties rule
| length(p) |
| 1 |
And the execution plan should be:
| id | name | dependencies | operator info |
| 13 | Project | 11 | |
| 11 | Limit | 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 |
| 13 | Project | 11 | |
| 11 | Limit | 5 | |
| 5 | AppendVertices | 4 | { "props": "[{\"props\":[\"_tag\", \"name\", \"speciality\"],\"tagId\":8}, {\"props\":[\"_tag\", \"name\", \"age\"],\"tagId\":9}, {\"props\":[\"_tag\", \"name\"],\"tagId\":10}]" } |
| 4 | Traverse | 2 | {"vertexProps": "[{\"props\":[\"name\", \"age\", \"_tag\"],\"tagId\":9}, {\"props\":[\"name\", \"speciality\", \"_tag\"],\"tagId\":8}, {\"props\":[\"name\", \"_tag\"],\"tagId\":10}]", "edgeProps": "[{\"type\": 3, \"props\": [\"_type\", \"_rank\", \"_dst\", \"_src\", \"likeness\"]}]" } |
| 2 | Dedup | 1 | |
| 1 | PassThrough | 3 | |
| 3 | Start | | |
When profiling query:
"""
MATCH p = (a:player)-[e:like*1..3]->(b:player{age:39})
Expand All @@ -466,20 +466,20 @@ Feature: Prune Properties rule
| "Tracy McGrady" | 1 |
| "Tracy McGrady" | 3 |
And the execution plan should be:
| id | name | dependencies | operator info |
| 14 | Project | 13 | |
| 13 | BiInnerJoin | 15,12 | |
| 15 | Project | 17 | |
| 17 | AppendVertices | 16 | { "props": "[{\"props\":[\"name\",\"age\"],\"tagId\":9}]" } |
| 16 | Traverse | 2 | {"vertexProps": "", "edgeProps": "[{\"type\": 3, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } |
| 2 | Dedup | 1 | |
| 1 | PassThrough | 3 | |
| 3 | Start | | |
| 12 | Project | 18 | |
| 18 | AppendVertices | 10 | { "props": "[{\"props\":[\"_tag\"],\"tagId\":10}]" } |
| 10 | Traverse | 8 | {"vertexProps": "[{\"props\":[\"name\",\"age\"],\"tagId\":9}]", "edgeProps": "[{\"type\": 4, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } |
| 8 | Argument | | |
| 9 | Start | | |
| id | name | dependencies | operator info |
| 14 | Project | 13 | |
| 13 | BiInnerJoin | 15,12 | |
| 15 | Project | 17 | |
| 17 | AppendVertices | 16 | { "props": "[{\"props\":[\"_tag\", \"name\", \"speciality\"],\"tagId\":8}, {\"props\":[\"_tag\", \"name\", \"age\"],\"tagId\":9}, {\"props\":[\"_tag\", \"name\"],\"tagId\":10}]" } |
| 16 | Traverse | 2 | {"vertexProps": "[{\"props\":[\"name\", \"age\", \"_tag\"],\"tagId\":9}, {\"props\":[\"name\", \"speciality\", \"_tag\"],\"tagId\":8}, {\"props\":[\"name\", \"_tag\"],\"tagId\":10}]", "edgeProps": "[{\"type\": 3, \"props\": [\"_type\", \"_rank\", \"_dst\", \"_src\", \"likeness\"]}]" } |
| 2 | Dedup | 1 | |
| 1 | PassThrough | 3 | |
| 3 | Start | | |
| 12 | Project | 18 | |
| 18 | AppendVertices | 10 | { "props": "[{\"props\":[\"_tag\"],\"tagId\":10}]" } |
| 10 | Traverse | 8 | {"vertexProps": "[{\"props\":[\"name\", \"age\", \"_tag\"],\"tagId\":9}, {\"props\":[\"name\", \"speciality\", \"_tag\"],\"tagId\":8}, {\"props\":[\"name\", \"_tag\"],\"tagId\":10}]", "edgeProps": "[{\"type\": 4, \"props\": [\"_type\", \"_rank\", \"_dst\"]}]" } |
| 8 | Argument | | |
| 9 | Start | | |

@distonly
Scenario: union match
Expand Down

0 comments on commit b5df04f

Please sign in to comment.