Hi! I'm currently developing functionality to delete all customer data from my database once a customer leaves, but even with a very small example (about 1300 nodes and 4500 edges, when a potential large customer could have a thousands times that or more) the database query seems to struggle.
My instance is in aura and configured to the minimum CPU/Memory configuration as the project is still in development
The database is organized in a way that all customer data is reachable by paths from a node of label Installation, identified by an id, so i attempted 2 approaches to delete the data.
MATCH to_delete=(:Installation {id: "104069967"})-[*]->() DETACH DELETE to_delete
That one hits a memory limit in the database (calling it by http indicates the following:
The allocation of an extra 2.0 MiB would use more than the limit 278.0 MiB. Currently using 278.0 MiB. dbms.memory.transaction.total.max threshold reached
If i prepend the query with EXPLAIN it shows that it expects 220,744,638,748,247 results, i assume from relations forming loops, although at least in the web console changing DETACH DELETE for RETURN makes the query work (tho not deleting the nodes ofc)
My second approach seeing this was this:
MATCH (i:Installation {id: "104069967"})
MATCH (x)
WHERE EXISTS {
(i)-[*]->(x)
}
CALL(x) {
DETACH DELETE x
} IN TRANSACTIONS
WITH i
DETACH DELETE i
Which doesn't error out from memory but drives the CPU consumption in the database to 100% and takes more than an hour (i haven't actually seen it finish).
Is there a better way of achieving this? I couldn't find anything in the documentation that suggest this approach is wrong but i can't imagine such a tiny amount of nodes hitting the database limits like this is normal behavior.
External Link
Platform
You are about to visit:
https://example.comThis will open in a new tab. Make sure you trust this link.