Deepak K Uday
Deepak K Uday

Reputation: 11

Finding largest path in huge cyclic neo4j directed graph with infinite depth using cypher query

I have a neo4j graph in which different nodes are connected through directed relationship.This graph contains cycles. I want to find all entities in largest path with this relationship for a set of given entities to a set of target entities. The query I am using is provided below : NOTE: Number of nodes in sample graph = 1000 and Relationships = 2500 and Depth = Infinite. Also our final graph may contain nodes upto 25000.

match (n:dataEntity) where id(n) in 
[28, 4, 27, 151, 34, 36, 57, 59, 71, 73, 75, 119, 121, 140, 142, 144] 
match (d:dataEntity) where   NOT (d)-[:dependsOn]->(:dataEntity)
with distinct d ,n
match res =(n)-[:dependsOn*]->(d) 
with   d,n,nodes(res) as   x 
return x

The problem with this query is that it works fine upto depth 5 but as we are going for uncertain depth it is taking too much time i.e. more than 20 minutes. Thanks in advance and plz revert if u need any further information !!!

Upvotes: 1

Views: 216

Answers (1)

cybersam
cybersam

Reputation: 66989

The basic problem is that you are trying to perform an unreasonably expensive query.

Based on your data characteristics:

  • a dataEntity node has an average of about 2.5 outgoing relationships
  • the path from any node n to any node d can have a length of up to 2500

Let's say, for example, that a particular path (out of probably a very large number of possible paths) from one specific n to one specific d is of length 500. To find that single path, the number of operations would be (2.5^500), or about 10^199.

You need to reconsider what you are trying to do, and see if there is a more clever way to do what you want. Perhaps changing the data model will help, but it all depends on your use cases.

Upvotes: 2

Related Questions