Break the query part on Unwind
Summary: `UNWIND` can come before `MATCH`, so it needs to break query parts. If it didn't, a query part would incorrectly grab all the matches and plan them incorrectly. A test for such a case has been added. Reviewers: florijan Reviewed By: florijan Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D598
This commit is contained in:
parent
06d3629fd0
commit
160a6866dc
@ -1106,7 +1106,9 @@ std::vector<QueryPart> CollectQueryParts(SymbolTable &symbol_table,
|
||||
query_part->merge_matching.emplace_back(Matching{});
|
||||
AddMatching({merge->pattern_}, nullptr, symbol_table, storage,
|
||||
query_part->merge_matching.back());
|
||||
} else if (dynamic_cast<With *>(clause)) {
|
||||
} else if (dynamic_cast<With *>(clause) ||
|
||||
dynamic_cast<query::Unwind *>(clause)) {
|
||||
// This query part is done, continue with a new one.
|
||||
query_parts.emplace_back(QueryPart{});
|
||||
query_part = &query_parts.back();
|
||||
} else if (dynamic_cast<Return *>(clause)) {
|
||||
|
@ -1251,4 +1251,17 @@ TEST(TestLogicalPlanner, MatchExpandVariableFiltered) {
|
||||
ExpectProduce());
|
||||
}
|
||||
|
||||
TEST(TestLogicalPlanner, UnwindMatchVariable) {
|
||||
// Test UNWIND [1,2,3] AS depth MATCH (n) -[r*d]-> (m) RETURN r
|
||||
AstTreeStorage storage;
|
||||
auto edge = EDGE("r", Direction::OUT);
|
||||
edge->has_range_ = true;
|
||||
edge->lower_bound_ = IDENT("d");
|
||||
edge->upper_bound_ = IDENT("d");
|
||||
QUERY(UNWIND(LIST(LITERAL(1), LITERAL(2), LITERAL(3)), AS("d")),
|
||||
MATCH(PATTERN(NODE("n"), edge, NODE("m"))), RETURN("r"));
|
||||
CheckPlan(storage, ExpectUnwind(), ExpectScanAll(), ExpectExpandVariable(),
|
||||
ExpectProduce());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user