Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between apoc.periodic.iterate and apoc.periodic.commit when deleting lots of nodes?

Tags:

neo4j

What's the difference between these two lines?

call apoc.periodic.iterate("MATCH (n:Nodes) return n", "DETACH DELETE n", {batchSize:10000, iterateList:true})"

call apoc.periodic.commit("match (n:Nodes) limit {limit} detach delete n RETURN count(*)",{limit:10000})

What is the best way to delete lots of nodes?

like image 945
Mr MP Avatar asked Jul 04 '18 10:07

Mr MP


1 Answers

The procedure apoc.periodic.iterate takes two queries :

  • the first one to create a set of nodes in your example
  • the second one will be executed for each result of the first query

So in your example your match all the Node of your database, and then you delete them with a batch size of 10000.

The procedure apoc.periodic.commit takes only one query, and the procedure will execute the query again, and again and again ... tilt its result is 0.

So in your example, you take the first 10000 nodes and delete them. You repeat this behaviour till there is no more Node in your database.

To resume, both queries give the same result, but not in the same way. The apoc.periodic.iterate will take a little more RAM than the apoc.periodic.commit (the procedure needs to build the set of nodes at first), but one good thing with it is that you can use all yours CPU, via the configuration parallel:true (but be carefull to locks).

If you have a really huge number of nodes to delete, I recommand you to use the apoc.periodic.commit.

like image 114
logisima Avatar answered Nov 04 '22 00:11

logisima