简体   繁体   English

使用密码查询在无限深度的巨大循环neo4j有向图中找到最大路径

[英]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. 我有一个neo4j图,其中不同的节点通过有向关系进行连接。此图包含周期。 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. 下面提供了我正在使用的查询:注意:示例图中的节点数= 1000,关系= 2500,深度=无限。 Also our final graph may contain nodes upto 25000. 同样,我们的最终图形可能包含最多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. 该查询的问题是它可以很好地工作到深度5,但是由于不确定的深度,它花费了太多时间,即超过20分钟。 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 一个dataEntity节点平均具有约2.5个传出关系
  • the path from any node n to any node d can have a length of up to 2500 从任何节点n到任何节点d的路径的最大长度为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 . 例如,假设从一个特定的n到一个特定的d的特定路径(可能有大量可能的路径)的长度为500。要找到该路径,操作数应为(2.5 ^ 500),或大约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. 也许更改数据模型会有所帮助,但这全部取决于您的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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