本文介绍了删除Cypher中所有节点和关系的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Cypher从所有节点和关系中清除图形的最佳方法是什么?

What is the best way to cleanup the graph from all nodes and relationships via Cypher?

http://neo4j.com/docs/stable/query-delete.html#delete-delete-a-node-and-connected-relationships 示例

MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n,r

有注释:

那么,下面的方法更好吗?

So, is the following better?

MATCH ()-[r]-() DELETE r

MATCH (n) DELETE n

或者还有另一种对大型图形更好的方法吗?

Or is there another way that is better for large graphs?

推荐答案

正如您提到的,最简单的方法是停止Neo4j,删除data/graph.db文件夹并重新启动它.

As you've mentioned the most easy way is to stop Neo4j, drop the data/graph.db folder and restart it.

通过Cypher删除大图总是比较慢,但是如果您使用适当的事务大小来防止内存问题(记住事务在提交之前先在内存中建立),仍然可以实现.通常,50-100k原子操作是个好主意.您可以在删除语句中添加一个限制,以控制tx的大小,并报告已删除的节点数.重新运行此语句,直到返回值0:

Deleting a large graph via Cypher will be always slower but still doable if you use a proper transaction size to prevent memory issues (remember transaction are built up in memory first before they get committed). Typically 50-100k atomic operations is a good idea. You can add a limit to your deletion statement to control tx sizes and report back how many nodes have been deleted. Rerun this statement until a value of 0 is returned back:

MATCH (n)
OPTIONAL MATCH (n)-[r]-()
WITH n,r LIMIT 50000
DELETE n,r
RETURN count(n) as deletedNodesCount

这篇关于删除Cypher中所有节点和关系的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:03