从Neo4j删除所有节点时出现ConstraintViolationTransactionFailureException [英] ConstraintViolationTransactionFailureException when deleting all nodes from Neo4j
问题描述
当尝试从Neo4j图形数据库中删除所有节点时(过去我已经在较小的数据集上成功完成了多次操作),运行此查询后,我始终遇到Error: undefined - undefined
MATCH (n) DETACH
DELETE n
我发现我试图一次删除的节点数可能太大(> 100000),所以我尝试了该查询
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
WITH n,r LIMIT 10000
DELETE n,r
及其许多变体,主要表现在我在这篇文章中看到的内容:解决方案
查询的编写方式中的一个问题是,每个DELETE
都一次仅尝试删除一个节点/关系对.如果任何节点具有多个关系,您将收到该约束违反错误,因为要删除一个节点,您必须删除其所有关系(事先或同时删除).
要删除10000个节点(及其所有关系),请使用以下查询:
MATCH (n)
WITH n LIMIT 10000
DETACH DELETE n;
When attempting to delete all nodes from my Neo4j graph database, which I have successfully done many times in the past on smaller datasets, I consistently ran across Error: undefined - undefined
after running this query
MATCH (n) DETACH
DELETE n
I figured the number of nodes I was attempting to delete at once may be too large (>100000), so I then tried this query
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
WITH n,r LIMIT 10000
DELETE n,r
and many variations of it, acting on mostly what I read in this post: Best way to delete all nodes and relationships in Cypher. All returned this error
org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException: Cannot delete node<32769>, because it still has relationships. To delete this node, you must first delete its relationships.
and each time, the node Neo4j could not delete differs. Is there any way of resolving this issue?
Perhaps also noteworthy, while desperately running variations of the previous query, when I ran this query
MATCH ()-[r]-()
OPTIONAL MATCH (n)-[r]-()
WITH r,n LIMIT 10000
DELETE r,n
I got this rather unique error
Java heap space
in the console, which showed up as Neo.DatabaseError.General.UnknownError
in the banner.
One of the problems with the way your queries are written is that each DELETE
is only attempting to delete a single node/relationship pair at a time. If any nodes have more than one relationship, you will get that constraint violation error, since in order to delete a node you have to delete all of its relationships (either beforehand or at the same time).
To delete 10000 nodes (and all their relationships), use this query:
MATCH (n)
WITH n LIMIT 10000
DETACH DELETE n;
这篇关于从Neo4j删除所有节点时出现ConstraintViolationTransactionFailureException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!