简体   繁体   English

Neo4j遍历表现

[英]Neo4j traversal performance

I want to perform an undirected traversal to extract all ids connected through a certain type of relationship 我想执行无向遍历以提取通过某种关系连接的所有ID

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. 我怀疑通过使用*它搜索从s到x的每条路径,但由于我只想要id,所以这些路径可以被丢弃。 What I really want is an BFS or DFS search to find the connect nodes from s. 我真正想要的是BFS或DFS搜索从s中查找连接节点。

Both query returns the exact same result since there are no elements with shortest path higher than 5 (only in the test example !). 两个查询都返回完全相同的结果,因为没有最短路径高于5的元素(仅在测试示例中!)。

Did you add an index for create index on :Node(entry) ? 您是否在create index on :Node(entry)添加了索引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. 此外,根据路径中每个节点的rel的数量,您可以获得可能返回的图表中的rel 10 ^(或一般rels ^步骤)路径。

Can you try first with a smaller upper limit like 3 and work from there? 你能先尝试一个较小的上限,比如3,并从那里开始工作吗?

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)

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

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