In situations where you know you need to delete a bunch of nodes (and by rule their relationships as well), it can be tempting to simply
DETACH DELETE and be done with it. However, this can become problematic if you have dense nodes, or if you have a number of nodes
with thousands of relationships per batch. Your “batch size” can quickly become much larger than you intend.
APOC allows us to work with this. Essentially, we want to find the set of nodes that we want to delete, pass that into a call to
and then batch the deletes by the first 10K relationships, then the next 10K, and so on until it is done. The following cypher works
quite well on a large set of nodes. In this case, it is look for :TTL labelled nodes who’s
ttl property is older than the current
time. It passes those into the periodic commit statement, and deletes in batches of 10K.
Additionally please consider reviewing KB document
Large Delete Transaction Best Practices in Neo4j for other considerations