0
votes

I'm working with Neo4j 2.1.7. I'm trying to count the paths starting from a node and terminating to the same node (i.e. loops), with maximum given path length.

My (very simple) query is

match p=(n:MyLabel) -[r*..maxLength]- (n)
return n.myid, count(p)

The entire graph has 200k nodes, while MyLabel nodes are only 50k, but I'm having very poor performance even with low values of maxLength (5 or 6).

How can I improve?

Thanks in advance

1

1 Answers

0
votes

This is a global graph query, which will create exponential results.

E.g. if you have 100 rels per node, then 6 steps out will be 100^6 = 1.000.000.000.000 paths that it will find per node and then you also go over all nodes.

I recommend that you instead look at shortestPath, but even so, doing that 50k times is still a lot, try to use PROFILE to output the query plan so you see the amount of data you touch.

match (n:MyLabel)
match shortestPath((n)-[*..maxLength]- (n))
return n.myid, count(*)

It might be that Neo4j 2.2 with the new query planner is better at that.