Neo4j内存不足错误

时间:2015-03-07 18:56:56

标签: neo4j query-optimization cypher graph-databases

我已在[{3}}

Nicole White根据此答案对我的neo4j数据库进行了建模

我也成功测试了密码查询

MATCH (a:Stop {name:'A'}), (d:Stop {name:'D'})
MATCH route = allShortestPaths((a)-[:STOPS_AT*]-(d)),
stops = (a)-[:NEXT*]->(d)
RETURN EXTRACT(x IN NODES(route) | CASE WHEN x:Stop THEN 'Stop ' + x.name
                                    WHEN x:Bus THEN 'Bus ' + x.id
                               ELSE '' END) AS itinerary,
   REDUCE(d = 0, x IN RELATIONSHIPS(stops) | d + x.distance) AS distance

针对包含10个节点的小型测试图。

但是我的原始图表包含大约2k个节点和6k个关系会导致查询出现问题。查询只是停止,我收到一个错误:

  

java.lang.OutOfMemoryError:Java堆空间

您能帮助我优化我的查询或任何其他解决方案吗?

谢谢

1 个答案:

答案 0 :(得分:1)

尝试引入WITH来限制:NEXT路径的计算,只限于那些已知为最短路径的a,d对。为可变路径长度匹配提供上限也是一种很好的做法 - 我在这里使用100作为例子:

MATCH route = allShortestPaths(
   (a:Stop {name:'A'})-[:STOPS_AT*100]-(d:Stop {name:'D'})
)
WITH route, a, d
MATCH stops = (a)-[:NEXT*100]->(d)
RETURN EXTRACT(x IN NODES(route) | CASE WHEN x:Stop THEN 'Stop ' + x.name
                                WHEN x:Bus THEN 'Bus ' + x.id
                           ELSE '' END) AS itinerary,
REDUCE(d = 0, x IN RELATIONSHIPS(stops) | d + x.distance) AS distance