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:
Teon Banek 2017-07-29 13:24:16 +02:00
parent 06d3629fd0
commit 160a6866dc
2 changed files with 16 additions and 1 deletions

View File

@ -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)) {

View File

@ -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