我试图根据apoc.create.relationship
函数的现有关系属性添加新的关系:
:auto CALL apoc.periodic.iterate(
"MATCH (source:Entity)-[r:TEMP_RELATION]->(target:Entity) RETURN source, r, target",
"CALL apoc.create.relationship(source, r.`Interaction-type`, r, target) YIELD rel RETURN rel",
{batchSize:5}
);
当我运行这个查询时,我会得到Java堆错误(最大堆是8g)。看起来iterate
实际上并不是在迭代,而是将过多的内容加载到内存中。我在Mac (M1)上使用Neo4j 4.4.8。
知道这里为什么会有内存泄漏吗?
发布于 2022-07-13 17:15:22
由于neo4j 4的行为发生了变化,当您将一个节点或关系传递给一个单独的事务/语句时,它会将它自己的事务传递到它起源的地方。
因此,所有更新都是在原始事务上积累的。为了避免这种情况,您必须通过返回id(n) as id
或id(r) as relId
来“重新绑定”节点和rels。
然后,您可以在update语句:WHERE id(n) = id
中重新匹配节点和re,并在那里使用它。在你的例子中:
:auto CALL apoc.periodic.iterate(
"MATCH (source:Entity)-[r:TEMP_RELATION]->(target:Entity) RETURN id(source) as sId, properties(r) as props, r.`Interaction-type` as type, id(target) as tId",
"MATCH (source), (target) where id(source) = sId AND id(target) = tId
CALL apoc.create.relationship(source, type, props, target) YIELD rel RETURN count(*)",
{batchSize:10000}
);
https://stackoverflow.com/questions/72969640
复制相似问题