Fix a planning issue when CALL preceded filtering

Reviewers: mferencevic, ipaljak, llugovic

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2722
This commit is contained in:
Teon Banek 2020-03-16 10:52:13 +01:00
parent f1327c52ef
commit d63eb191f9
3 changed files with 30 additions and 2 deletions

View File

@ -524,7 +524,8 @@ std::vector<SingleQueryPart> CollectSingleQueryParts(
AddMatching({merge->pattern_}, nullptr, symbol_table, storage,
query_part->merge_matching.back());
} else if (utils::IsSubtype(*clause, With::kType) ||
utils::IsSubtype(*clause, query::Unwind::kType)) {
utils::IsSubtype(*clause, query::Unwind::kType) ||
utils::IsSubtype(*clause, query::CallProcedure::kType)) {
// This query part is done, continue with a new one.
query_parts.emplace_back(SingleQueryPart{});
query_part = &query_parts.back();

View File

@ -274,7 +274,9 @@ struct Matching {
/// Each part ends with either:
///
/// * `RETURN` clause;
/// * `WITH` clause or
/// * `WITH` clause;
/// * `UNWIND` clause;
/// * `CALL` clause or
/// * any of the write clauses.
///
/// For a query `MATCH (n) MERGE (n) -[e]- (m) SET n.x = 42 MERGE (l)` the

View File

@ -1530,6 +1530,31 @@ TYPED_TEST(TestPlanner, CallProcedureAfterScanAll) {
ExpectProduce());
}
TYPED_TEST(TestPlanner, CallProcedureBeforeScanAll) {
// Test CALL proc() YIELD field MATCH (n) WHERE n.prop = field RETURN n
AstStorage storage;
auto *ast_call = storage.Create<query::CallProcedure>();
ast_call->procedure_name_ = "proc";
ast_call->result_fields_ = {"field"};
ast_call->result_identifiers_ = {IDENT("field")};
FakeDbAccessor dba;
auto property = dba.Property("prop");
auto *query = QUERY(SINGLE_QUERY(
ast_call, MATCH(PATTERN(NODE("n"))),
WHERE(EQ(PROPERTY_LOOKUP("n", property), IDENT("field"))), RETURN("n")));
auto symbol_table = query::MakeSymbolTable(query);
std::vector<Symbol> result_syms;
result_syms.reserve(ast_call->result_identifiers_.size());
for (const auto *ident : ast_call->result_identifiers_) {
result_syms.push_back(symbol_table.at(*ident));
}
auto planner = MakePlanner<TypeParam>(&dba, storage, symbol_table, query);
CheckPlan(planner.plan(), symbol_table,
ExpectCallProcedure(ast_call->procedure_name_, ast_call->arguments_,
ast_call->result_fields_, result_syms),
ExpectScanAll(), ExpectFilter(), ExpectProduce());
}
TYPED_TEST(TestPlanner, ScanAllById) {
// Test MATCH (n) WHERE id(n) = 42 RETURN n
AstStorage storage;