Skip to content

Commit

Permalink
fix match index selecting (#3457)
Browse files Browse the repository at this point in the history
  • Loading branch information
czpmango authored Dec 15, 2021
1 parent 60c5019 commit bb6fc4e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 20 deletions.
5 changes: 0 additions & 5 deletions src/graph/optimizer/rule/IndexScanRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ Status IndexScanRule::appendColHint(std::vector<IndexColumnHint>& hints,
fmt::format("Not supported value type {} for index.", item.value_.type()));
}
if (item.relOP_ == Expression::Kind::kRelEQ) {
// check the items, don't allow where c1 == 1 and c1 == 2 and c1 > 3....
// If EQ item appears, only one element is allowed
if (items.items.size() > 1) {
return Status::SemanticError();
}
isRangeScan = false;
begin = {item.value_, true};
break;
Expand Down
26 changes: 15 additions & 11 deletions src/graph/planner/match/PropIndexSeek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,30 @@ bool PropIndexSeek::matchNode(NodeContext* nodeCtx) {
}

auto* matchClauseCtx = nodeCtx->matchClauseCtx;
Expression* filter = nullptr;
Expression* filterInWhere = nullptr;
Expression* filterInPattern = nullptr;
if (matchClauseCtx->where != nullptr && matchClauseCtx->where->filter != nullptr) {
filter = MatchSolver::makeIndexFilter(
filterInWhere = MatchSolver::makeIndexFilter(
node.labels.back(), node.alias, matchClauseCtx->where->filter, matchClauseCtx->qctx);
}
if (filter == nullptr) {
if (node.props != nullptr && !node.props->items().empty()) {
filter = MatchSolver::makeIndexFilter(node.labels.back(), node.props, matchClauseCtx->qctx);
}
}
// TODO(yee): Refactor these index choice logic
if (filter == nullptr && !node.labelProps.empty()) {
if (!node.labelProps.empty()) {
auto props = node.labelProps.back();
if (props != nullptr) {
filter = MatchSolver::makeIndexFilter(node.labels.back(), props, matchClauseCtx->qctx);
filterInPattern =
MatchSolver::makeIndexFilter(node.labels.back(), props, matchClauseCtx->qctx);
}
}

if (filter == nullptr) {
Expression* filter = nullptr;
if (!filterInPattern && !filterInWhere) {
return false;
} else if (!filterInPattern) {
filter = filterInWhere;
} else if (!filterInWhere) {
filter = filterInPattern;
} else {
filter =
LogicalExpression::makeAnd(matchClauseCtx->qctx->objPool(), filterInPattern, filterInWhere);
}

nodeCtx->scanInfo.filter = filter;
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/bugfix/TruncatedStringIndex.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Truncated string index
create tag index p1 on person(name(3));
"""
Then the execution should be successful
And wait 4 seconds
And wait 6 seconds
When executing query:
"""
insert vertex person(name) values "1":("abc1"),"2":("abc2");
Expand Down
4 changes: 2 additions & 2 deletions tests/tck/features/delete/DeleteVertexWithoutEdge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: delete vertex without edge
CREATE TAG t(id int);
CREATE EDGE e();
"""
And wait 4 seconds
And wait 6 seconds
When executing query:
"""
INSERT VERTEX t(id) VALUES 1:(1),2:(2),3:(3);
Expand Down Expand Up @@ -73,7 +73,7 @@ Feature: delete vertex without edge
CREATE TAG t(id int);
CREATE EDGE e();
"""
And wait 4 seconds
And wait 6 seconds
When executing query:
"""
INSERT VERTEX t(id) VALUES 1:(1),2:(2),3:(2);
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/lookup/LookUp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ Feature: LookUpTest_Vid_String
CREATE TAG INDEX player_index_3 on player(name,age);
CREATE TAG INDEX team_index_1 on team(name);
"""
And wait 4 seconds
And wait 6 seconds
And having executed:
"""
INSERT EDGE
Expand Down
42 changes: 42 additions & 0 deletions tests/tck/features/match/IndexSelecting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,48 @@ Feature: Index selecting for match statement
| 2 | AppendVertices | 5 | |
| 5 | IndexScan | 0 | {"indexCtx": {"columnHints":{"scanType":"PREFIX"}}} |
| 0 | Start | | |
When profiling query:
"""
MATCH (v:player) WHERE v.name == "Tim Duncan" and v.name < "Zom" RETURN v.name AS name
"""
Then the result should be, in any order, with relax comparison:
| name |
| "Tim Duncan" |
And the execution plan should be:
| id | name | dependencies | operator info |
| 9 | Project | 7 | |
| 7 | Filter | 2 | |
| 2 | AppendVertices | 6 | |
| 6 | IndexScan | 0 | {"indexCtx": {"columnHints":{"scanType":"PREFIX"}}} |
| 0 | Start | | |
When profiling query:
"""
MATCH (v:player) WHERE v.name=="Tim Duncan" and v.age>4 and v.name>"A" RETURN v.name AS name
"""
Then the result should be, in any order, with relax comparison:
| name |
| "Tim Duncan" |
And the execution plan should be:
| id | name | dependencies | operator info |
| 9 | Project | 7 | |
| 7 | Filter | 2 | |
| 2 | AppendVertices | 6 | |
| 6 | IndexScan | 0 | {"indexCtx": {"columnHints":{"scanType":"PREFIX"}}} |
| 0 | Start | | |
When profiling query:
"""
MATCH (v:player{name:"Tim Duncan"}) WHERE v.name < "Zom" RETURN v.name AS name
"""
Then the result should be, in any order, with relax comparison:
| name |
| "Tim Duncan" |
And the execution plan should be:
| id | name | dependencies | operator info |
| 9 | Project | 7 | |
| 7 | Filter | 2 | |
| 2 | AppendVertices | 6 | |
| 6 | IndexScan | 0 | {"indexCtx": {"columnHints":{"scanType":"PREFIX"}}} |
| 0 | Start | | |
# Range Index
When profiling query:
"""
Expand Down

0 comments on commit bb6fc4e

Please sign in to comment.