尽量使用参数
这是因为cypher的缓存机制,相同的query执行第二遍会快很多避免笛卡尔积
笛卡尔积会让执行时间爆炸式的增长
match (a),(b)
return *
在写上上述笛卡尔积式时,请一定确保用where过滤过了
下面也是一种情况
match (u:user)-[:purchase]->(i:item)
where ...
with u, i
match (foo)-[:relate]->(bar)
return *
- 避免在where语句中做匹配
match (u:user)-[:viewed]->(i:item),(u)-[:purchase]->(other:item)
where u.id=123123
and (i)-[:related_to]->(other)
return i
可以换成这样来写
match (u:user)-[:viewed]->(i:item),(u)-[:purchase]->(other:item)
where u.id=123123
with i,other
match (i)-[related_to]->(other)
return i
- 拆分较长的match语句
- stackoverflow…