user2234995
user2234995

Reputation: 285

cypher query for shortest path is too slow

I use Neo4j1.9m05. I want to calculate the shortest path between every pair of nodes. Right now I use this Cypher query:

START a=node(1), b=node(1-1000) MATCH p=shortestPath(a-[:cooperate*..50]-b) RETURN length(p)

1-1000 just means there are 1000 nodes. This simple query costs more than 2 minutes, which is too slow. I just want to query for 1000 pairs of shortest path length. Can anyone help?

Upvotes: 2

Views: 952

Answers (1)

Jürgen Bernau
Jürgen Bernau

Reputation: 21

Things to try

Did you run the query on a cold cache? Try running it twice to verify.

Check if there is sufficient memory. Shortest path queries take a massive hit if the relevant portion of the graph does not fit into the cache.

I noticed that you are searching for an undirected path. You could help the algorithm by specifying the direction if possible.

Upvotes: 1

Related Questions