memgraphdb

The Memgraph instance restarts when running DFS algorithm


I have some issues running DFS algorithm. The Memgraph instance restarts after a while and no result is returned. My query looks like:

MATCH path=(n:LABEL {name: "node_name", source_id: "12345"})-[*]->(m) RETURN path

My database contains 600K nodes and 650K relationships with 16GB of available memory. The weirdest part is that BFS algorithm runs smoothly and really fast, returning 7500 paths.

MATCH path=(n:LABEL {name: "node_name", source_id: "12345"})-[*BFS]->(m) RETURN path

Any idea what can I do to improve the performance for the DFS algorithm or why is it crashing??


Solution

  • The best way to reduce this would definitely be the constraining of path length, this way the algorithm doesn't explore node as far as possible and won't do unnecessary scanning. But, as you said, if you need all possible paths and cannot constrain the path length, we can try other ways to try and optimize.

    First, make sure you have created all necessary indexes, that would be the crucial step if you already haven't. Next, you could try to limit the search by a certain label or a property. That way the database will use the

    ScanAllByLabel
    

    operator instead of the

    ScanAll
    

    operator, which will search nodes based on labels and reduce the actual search. You could also consider creating an index on the properties you're filtering to speed up the query execution.