From 79d91b68e2febce09971200fae12f52f0d841399 Mon Sep 17 00:00:00 2001 From: Josip Mrden Date: Wed, 21 Jun 2023 17:27:38 +0200 Subject: [PATCH] Add e2e test for subqueries --- tests/e2e/analyze_graph/common.py | 1 + tests/e2e/analyze_graph/optimize_indexes.py | 76 +++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/tests/e2e/analyze_graph/common.py b/tests/e2e/analyze_graph/common.py index 312bfc0e4..c43d9cd79 100644 --- a/tests/e2e/analyze_graph/common.py +++ b/tests/e2e/analyze_graph/common.py @@ -37,4 +37,5 @@ def memgraph(**kwargs) -> Memgraph: yield memgraph memgraph.drop_database() + memgraph.execute("analyze graph delete statistics;") memgraph.drop_indexes() diff --git a/tests/e2e/analyze_graph/optimize_indexes.py b/tests/e2e/analyze_graph/optimize_indexes.py index c3b6f165f..e78a57c16 100644 --- a/tests/e2e/analyze_graph/optimize_indexes.py +++ b/tests/e2e/analyze_graph/optimize_indexes.py @@ -331,5 +331,81 @@ def test_given_supernode_when_expanding_then_expand_other_way_around(memgraph): assert expected_explain_after_analysis == result_with_analysis +def test_given_supernode_when_subquery_then_carry_information_to_subquery(memgraph): + memgraph.execute("FOREACH (i in range(1, 1000) | CREATE (:Node {id: i}));") + memgraph.execute("FOREACH (i in range(1, 1000) | CREATE (:Node2 {id: i}));") + memgraph.execute("CREATE (:SuperNode {id: 1});") + memgraph.execute("CREATE INDEX ON :SuperNode(id);") + memgraph.execute("CREATE INDEX ON :SuperNode;") + memgraph.execute("CREATE INDEX ON :Node(id);") + memgraph.execute("CREATE INDEX ON :Node;") + memgraph.execute("CREATE INDEX ON :Node2(id);") + memgraph.execute("CREATE INDEX ON :Node2;") + + memgraph.execute("match (n:Node) match (s:SuperNode {id: 1}) merge (n)<-[:HAS_REL_TO]-(s);") + memgraph.execute("match (n:Node2) match (s:SuperNode {id: 1}) merge (n)<-[:HAS_REL_TO]-(s);") + + result_without_analysis = list( + memgraph.execute_and_fetch( + "explain match (n:Node) match (s:SuperNode {id: 1}) call { with n, s merge (n)<-[:HAS_REL_TO]-(s) } return 1" + ) + ) + result_without_analysis = [x["QUERY PLAN"] for x in result_without_analysis] + + expected_explain_before_analysis = [ + f" * Produce {{0}}", + f" * Accumulate", + f" * Accumulate", + f" * Apply", + f" |\\ ", + f" | * EmptyResult", + f" | * Merge", + f" | |\\ On Match", + f" | | * Expand (s)-[anon3:HAS_REL_TO]->(n)", + f" | | * Once", + f" | |\\ On Create", + f" | | * CreateExpand (n)<-[anon3:HAS_REL_TO]-(s)", + f" | | * Once", + f" | * Produce {{n, s}}", + f" | * Once", + f" * ScanAllByLabel (n :Node)", + f" * ScanAllByLabelPropertyValue (s :SuperNode {{id}})", + f" * Once", + ] + + memgraph.execute("analyze graph;") + + result_with_analysis = list( + memgraph.execute_and_fetch( + "explain match (n:Node) match (s:SuperNode {id: 1}) call { with n, s merge (n)<-[:HAS_REL_TO]-(s) } return 1" + ) + ) + result_with_analysis = [x["QUERY PLAN"] for x in result_with_analysis] + + expected_explain_after_analysis = [ + f" * Produce {{0}}", + f" * Accumulate", + f" * Accumulate", + f" * Apply", + f" |\\ ", + f" | * EmptyResult", + f" | * Merge", + f" | |\\ On Match", + f" | | * Expand (n)<-[anon3:HAS_REL_TO]-(s)", + f" | | * Once", + f" | |\\ On Create", + f" | | * CreateExpand (n)<-[anon3:HAS_REL_TO]-(s)", + f" | | * Once", + f" | * Produce {{n, s}}", + f" | * Once", + f" * ScanAllByLabel (n :Node)", + f" * ScanAllByLabelPropertyValue (s :SuperNode {{id}})", + f" * Once", + ] + + assert expected_explain_before_analysis == result_without_analysis + assert expected_explain_after_analysis == result_with_analysis + + if __name__ == "__main__": sys.exit(pytest.main([__file__, "-rA"]))