如何让Neo4j Cypher查询更快?

时间:2014-06-13 14:08:44

标签: neo4j cypher

我在我的应用中有这个查询:

MATCH (ctx:Context{uid:"c1af16f0-f2fa-11e3-a477-6749dbdfc34e"}), 
c-[at:AT]->ctx, 
s-[in:IN]->ctx, 
ctx-[by:BY]->u 
WITH c,at,s,in,ctx,by,u 
MATCH con-[byc:BY]->u 
WHERE byc.statement = s.uid 
DELETE at,in,s,byc

这需要很长时间才能执行。我以为是因为WHERE子句,但是没有,即使我摆脱了WITH并直接转到DELETE,例如

MATCH (ctx:Context{uid:"c1af16f0-f2fa-11e3-a477-6749dbdfc34e"}), 
c-[at:AT]->ctx, 
s-[in:IN]->ctx, 
ctx-[by:BY]->u 
DELETE at,in,s

它还需要太长时间。

要删除的节点很多(数百个),但是,我可能只是对查询做错了吗?

请告诉我......

基本思想是找到一个节点,然后查找连接到它的所有其他节点,删除这些关系,只删除一种类型的连接节点。

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试类似这样的产品扩展会减少:

MATCH (ctx:Context{uid:"c1af16f0-f2fa-11e3-a477-6749dbdfc34e"})<-[in:IN]-(s)
WITH ctx, collect(s.uid) as uids
MATCH (ctx)<-[in:IN]-(s)
DELETE s, in
WITH DISTINCT ctx, uids
MATCH (ctx)<-[at:AT]->()
DELETE at
WITH DISTINCT ctx, uids
MATCH (con)-[byc:BY]->()
WHERE byc.statement in uids 
DELETE byc
相关问题