缓慢的Neo4j Cypher查询

6

我想了解为什么我的Cypher查询运行速度如此之慢(仅5000个节点需要2-5秒)。该查询旨在查找一个个人网络内可到达的所有工作(他的朋友或朋友的朋友在同一家公司工作的工作)。

以下是查询:

Start current_profile= node:node_auto_index(neoid_unique_id = "Profile:1")
 Match current_profile-[r:friendships*0..2]->friends-[:roles]->company-[:positions]->jobs
 return distinct company.fmj_id

我尝试简化查询以查看我的错误,即使是这个简单的查询也需要太长时间:
START root=node(0)
Match root-[:job_subref]->j-[:jobs]->jobss
return jobss

我有问题吗?

我正在使用基于neography gem的neoid。


你可以在某个地方分享一下你的图表吗? - Luanne
请尝试使用 http://console.neo4j.org/ 和 http://console.neo4j.org/usage.html。 - Peter Neubauer
否则,将您的数据库目录压缩并上传到某个地方? - Luanne
也许这个方法可以帮助你(在我的案例中,我通过这个技巧得到了很多加速):使用 with 语句来拆分你的 match 语句,即首先匹配 current_profile-->friends,然后是 friends-->company,最后是 company-->jobs,全部在一条 Cypher 查询中完成。 - npobedina
Neo4j的速度慢是在第一次调用(启动Neo4j后)还是在后续调用时?请记住,Neo4j从预热缓存中受益匪浅。 - Stefan Armbruster
你的neo4j配置是什么?我赞同Stefan的观点,这是查询第一次运行还是后续运行?如果能分享你的graph.db目录作为一个zip文件就太好了。 - Michael Hunger
1个回答

2
试试这个查询怎么样?
Start current_profile= node:node_auto_index(neoid_unique_id = "Profile:1")
Match current_profile-[r:friendships*0..2]->friends
WITH friends
friends-[:roles]->company-[:positions]->jobs
RETURN company.fmj_id

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接