Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j traversal performance

I want to perform an undirected traversal to extract all ids connected through a certain type of relationship

When I perform the following query it returns the values fast enough

MATCH path=(s:Node {entry:"a"})-[:RelType*1..10]-(x:Node) 
RETURN collect(distinct ID(x))

However doing

MATCH path=(s:Node {entry:"a"})-[:RelType*]-(x:Node) 
RETURN collect(distinct ID(x))

takes an huge amount of time. I suspect that by using * it searches every path from s to x, but since I want only the ids these paths can be discarded. What I really want is an BFS or DFS search to find the connect nodes from s.

Both query returns the exact same result since there are no elements with shortest path higher than 5 (only in the test example !).

like image 235
fxe Avatar asked Nov 01 '22 03:11

fxe


1 Answers

Did you add an index for create index on :Node(entry) ?

Also depending on the # of rels per node in your path you get rels^10 (or general rels^steps) paths through your graph that are potentially returned.

Can you try first with a smaller upper limit like 3 and work from there?

Also leaving off the direction really hurts as you then get cycles.

What you can also try to do is:

MATCH path=(s:Node {entry:"a"})-[:RelType*]->(x:Node) 
RETURN ID(X)

and stream the results and do the uniqueness in the client

Or this if you don't want to do uniqueness in the client

MATCH path=(s:Node {entry:"a"})-[:RelType*]->(x:Node) 
RETURN distinct ID(X)
like image 199
Michael Hunger Avatar answered Dec 01 '22 06:12

Michael Hunger