Muh*_*nan 3 neo4j nosql graph-databases
我有neo4j数据库,其中包含数百万个类型为person的节点,我想删除所有person节点的特定属性。我试图通过match查询实现它,但是它正在扫描所有节点。
这是我尝试过的查询。
MATCH (p:Person)
REMOVE p.fatherName
Run Code Online (Sandbox Code Playgroud)
除了此查询,还有其他快速替代方法吗?
无法通过Cypher来提高该查询的性能。
您可以尝试避免没有父亲名称属性的节点
MATCH (p:Person)
WHERE HAS (p.fatherName)
REMOVE p.fatherName
Run Code Online (Sandbox Code Playgroud)
同样可以帮助添加LIMIT并多次运行查询
MATCH (p:Person)
WHERE HAS (p.fatherName)
WITH p LIMIT 100000
REMOVE p.fatherName
Run Code Online (Sandbox Code Playgroud)
我建议您编写用于删除该属性的非托管扩展。
例如
Label nodeLabel = DynamicLabel.label("Person");
String propertyName = "fatherName";
try(Transaction tx = database.beginTx()) {
final ResourceIterator<Node> people = database.findNodes(nodeLabel);
for (Node person : IteratorUtil.asCollection(people)) {
if (person.hasProperty(propertyName)) {
person.removeProperty(propertyName);
}
}
tx.success();
}
Run Code Online (Sandbox Code Playgroud)