Fix three match cartesian sequential scanning (#1555)

This commit is contained in:
Josipmrden 2023-12-04 00:01:29 +01:00 committed by GitHub
parent 46bfeb0023
commit 0fb3ae2d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 95 additions and 4 deletions

View File

@ -511,10 +511,6 @@ class RuleBasedPlanner {
std::set<ExpansionGroupId> visited_expansion_groups;
last_op =
GenerateExpansionOnAlreadySeenSymbols(std::move(last_op), matching, visited_expansion_groups, symbol_table,
storage, bound_symbols, new_symbols, named_paths, filters, view);
// We want to create separate branches of scan operators for each expansion group group of patterns
// Whenever there are 2 scan branches, they will be joined with a Cartesian operator
@ -528,6 +524,14 @@ class RuleBasedPlanner {
continue;
}
last_op =
GenerateExpansionOnAlreadySeenSymbols(std::move(last_op), matching, visited_expansion_groups, symbol_table,
storage, bound_symbols, new_symbols, named_paths, filters, view);
if (visited_expansion_groups.contains(expansion.expansion_group_id)) {
continue;
}
std::unique_ptr<LogicalOperator> starting_expansion_operator = nullptr;
if (!initial_expansion_done) {
starting_expansion_operator = std::move(last_op);

View File

@ -73,6 +73,7 @@ add_subdirectory(inspect_query)
add_subdirectory(filter_info)
add_subdirectory(queries)
add_subdirectory(garbage_collection)
add_subdirectory(query_planning)
copy_e2e_python_files(pytest_runner pytest_runner.sh "")
copy_e2e_python_files(x x.sh "")

View File

@ -0,0 +1,6 @@
function(copy_query_planning_e2e_python_files FILE_NAME)
copy_e2e_python_files(query_planning ${FILE_NAME})
endfunction()
copy_query_planning_e2e_python_files(common.py)
copy_query_planning_e2e_python_files(query_planning_cartesian.py)

View File

@ -0,0 +1,24 @@
# Copyright 2023 Memgraph Ltd.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
# License, and you may not use this file except in compliance with the Business Source License.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.
import pytest
from gqlalchemy import Memgraph
@pytest.fixture
def memgraph(**kwargs) -> Memgraph:
memgraph = Memgraph()
yield memgraph
memgraph.drop_indexes()
memgraph.ensure_constraints([])
memgraph.drop_database()

View File

@ -0,0 +1,42 @@
# Copyright 2023 Memgraph Ltd.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
# License, and you may not use this file except in compliance with the Business Source License.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.
import sys
import pytest
from common import memgraph
QUERY_PLAN = "QUERY PLAN"
def test_indexed_join_with_indices(memgraph):
memgraph.execute("CREATE INDEX ON :Node(id);")
expected_explain = [
f" * Produce {{a, b, r}}",
f" * Filter (a :Node), {{a.id}}",
f" * Expand (b)-[r:EDGE]-(a)",
f" * ScanAllByLabelPropertyValue (b :Node {{id}})",
f" * Once",
]
results = list(
memgraph.execute_and_fetch(
"EXPLAIN MATCH (a:Node {id: 1}) MATCH (b:Node {id: 2}) MATCH (a)-[r:EDGE]-(b) return a,b,r;"
)
)
actual_explain = [x[QUERY_PLAN] for x in results]
assert expected_explain == actual_explain
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-rA"]))

View File

@ -0,0 +1,14 @@
queries_cluster: &queries_cluster
cluster:
main:
args: ["--bolt-port", "7687", "--log-level=TRACE"]
log_file: "query_planning.log"
setup_queries: []
validation_queries: []
workloads:
- name: "Query planning cartesian"
binary: "tests/e2e/pytest_runner.sh"
args: ["query_planning/query_planning_cartesian.py"]
<<: *queries_cluster