Neo4J查询性能

时间:2013-06-10 14:41:13

标签: neo4j cypher

我有一个相对较小的图形(2.5M节点,5M rel,7.7M属性),我正在执行(在我看来)一个简单的查询,但它需要63秒才能在基于SSD的快速笔记本电脑上执行。这真的是我应该从Neo4j中得到的表现,还是查询有什么问题?

start ph=node(2)
match ph-[:NEXT_LEVEL]->c
where c.tag = "class 1"
with c
match c-[:NEXT_LEVEL]->p<-[:SOLD]-l<-[:LINE]-h-[:SOLD_IN]->s
return s.tag as store, sum(l.item_quantity) as quantity order by s.tag;

console output

更新:只是想发布更新的查询:

start ph=node(2)
match ph-[:NEXT_LEVEL]->c-[:NEXT_LEVEL]->p<-[:SOLD]-l<-[:LINE]-h-[:SOLD_IN]->s
where c.tag = "class 1"
with s.tag as store, sum(l.item_quantity) as quantity
return store, quantity order by store;

console with updated query

1 个答案:

答案 0 :(得分:0)

除非您有特定用例,否则通常应尝试删除WITH子句以提高性能。

start ph=node(2)
match ph-[:NEXT_LEVEL]->c-[:NEXT_LEVEL]->p<-[:SOLD]-l<-[:LINE]-h-[:SOLD_IN]->s
where c.tag = "class 1"
return s.tag as store, sum(l.item_quantity) as quantity order by s.tag;

编辑:正如评论中所讨论的那样,我们可以通过强制ORDER BY在聚合之后而不是之前发生来获得更好的性能。我们可以使用WITH来实现这一点(所以我们刚才讨论的是具体的用例)。这里的不同之处在于我们将WITH子句尽可能地移动到最后,允许所有先前的处理组合在一起而不是分开。

start ph=node(2)
match ph-[:NEXT_LEVEL]->c-[:NEXT_LEVEL]->p<-[:SOLD]-l<-[:LINE]-h-[:SOLD_IN]->s
where c.tag = "class 1"
with s.tag as store, sum(l.item_quantity) as quantity
return store, quantity order by store;