简体   繁体   中英

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 ie more than 20 minutes. Thanks in advance and plz revert if u need any further information !!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM