diff --git a/src/graph/optimizer/rule/IndexScanRule.cpp b/src/graph/optimizer/rule/IndexScanRule.cpp index a19f0554e22..2099e1e16f3 100644 --- a/src/graph/optimizer/rule/IndexScanRule.cpp +++ b/src/graph/optimizer/rule/IndexScanRule.cpp @@ -233,11 +233,6 @@ Status IndexScanRule::appendColHint(std::vector& 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; diff --git a/src/graph/planner/match/PropIndexSeek.cpp b/src/graph/planner/match/PropIndexSeek.cpp index dfbd33f39c5..ac418dca4d0 100644 --- a/src/graph/planner/match/PropIndexSeek.cpp +++ b/src/graph/planner/match/PropIndexSeek.cpp @@ -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; diff --git a/tests/tck/features/bugfix/TruncatedStringIndex.feature b/tests/tck/features/bugfix/TruncatedStringIndex.feature index 149d775e4ff..00b4af86988 100644 --- a/tests/tck/features/bugfix/TruncatedStringIndex.feature +++ b/tests/tck/features/bugfix/TruncatedStringIndex.feature @@ -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"); diff --git a/tests/tck/features/delete/DeleteVertexWithoutEdge.feature b/tests/tck/features/delete/DeleteVertexWithoutEdge.feature index 8fce80e1ede..cdc7bb3d6ab 100644 --- a/tests/tck/features/delete/DeleteVertexWithoutEdge.feature +++ b/tests/tck/features/delete/DeleteVertexWithoutEdge.feature @@ -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); @@ -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); diff --git a/tests/tck/features/lookup/LookUp.feature b/tests/tck/features/lookup/LookUp.feature index 9c60ab73a9e..bac70bd930f 100644 --- a/tests/tck/features/lookup/LookUp.feature +++ b/tests/tck/features/lookup/LookUp.feature @@ -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 diff --git a/tests/tck/features/match/IndexSelecting.feature b/tests/tck/features/match/IndexSelecting.feature index 4744fd7ec6c..462d42e60d6 100644 --- a/tests/tck/features/match/IndexSelecting.feature +++ b/tests/tck/features/match/IndexSelecting.feature @@ -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: """