diff --git a/src/query/plan/distributed.cpp b/src/query/plan/distributed.cpp index db36d0f5c..aeaca0e9a 100644 --- a/src/query/plan/distributed.cpp +++ b/src/query/plan/distributed.cpp @@ -771,9 +771,9 @@ DistributedPlan MakeDistributedPlan(const LogicalOperator &original_plan, worker_plan, pull_id, worker_plan->OutputSymbols(distributed_plan.symbol_table)); } - } else if (distributed_plan.worker_plans.empty() && - planner.NeedsSynchronize()) { - // If the plan performs writes, we still need to Synchronize. + } else if (planner.NeedsSynchronize()) { + // If the plan performs writes on master, we still need to Synchronize, even + // though we don't split the plan. distributed_plan.master_plan = std::make_unique( std::move(distributed_plan.master_plan), nullptr, false); } diff --git a/tests/unit/query_planner.cpp b/tests/unit/query_planner.cpp index ed75fabfe..62eba6d69 100644 --- a/tests/unit/query_planner.cpp +++ b/tests/unit/query_planner.cpp @@ -2204,4 +2204,32 @@ TYPED_TEST(TestPlanner, DistributedMatchCreateReturn) { MakeCheckers(ExpectScanAll(), ExpectCreateNode())); CheckDistributedPlan(planner.plan(), symbol_table, expected); } + +TYPED_TEST(TestPlanner, DistributedCartesianCreate) { + // Test MATCH (a), (b) CREATE (a)-[e:r]->(b) + AstTreeStorage storage; + database::Master db; + database::GraphDbAccessor dba(db); + auto relationship = dba.EdgeType("r"); + auto *node_a = NODE("a"); + auto *node_b = NODE("b"); + QUERY(SINGLE_QUERY( + MATCH(PATTERN(node_a), PATTERN(node_b)), + CREATE(PATTERN(NODE("a"), EDGE("e", Direction::OUT, {relationship}), + NODE("b"))))); + auto symbol_table = MakeSymbolTable(*storage.query()); + auto left_cart = + MakeCheckers(ExpectScanAll(), + ExpectPullRemote({symbol_table.at(*node_a->identifier_)})); + auto right_cart = + MakeCheckers(ExpectScanAll(), + ExpectPullRemote({symbol_table.at(*node_b->identifier_)})); + auto expected = ExpectDistributed( + MakeCheckers(ExpectCartesian(std::move(left_cart), std::move(right_cart)), + ExpectCreateExpand(), ExpectSynchronize(false)), + MakeCheckers(ExpectScanAll()), MakeCheckers(ExpectScanAll())); + auto planner = MakePlanner(db, storage, symbol_table); + CheckDistributedPlan(planner.plan(), symbol_table, expected); +} + } // namespace