Add e2e test for subqueries

This commit is contained in:
Josip Mrden
2023-06-21 17:27:38 +02:00
parent 7b7c5b3fc0
commit 79d91b68e2
2 changed files with 77 additions and 0 deletions

View File

@@ -37,4 +37,5 @@ def memgraph(**kwargs) -> Memgraph:
yield memgraph
memgraph.drop_database()
memgraph.execute("analyze graph delete statistics;")
memgraph.drop_indexes()

View File

@@ -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"]))