canbax
canbax

Reputation: 3856

delete all edges of a certain type

I have a neo4j database that has nearly 5 million nodes and 12 million edges. I want to delete a type (UsedAt) of edge (relationship). There are nearly 3 million edges of the type "UsedAt".

I'm writing a query like

match ()-[e:UsedAt]->() delete e

This takes too much time. Never stops.

I also tried CALL apoc.periodic.iterate("match ()-[e:UsedAt]->() return e", "delete e", {batchSize:1000, parallel:true})

That also never stops. How can I delete all edges (relationships) of a certain type efficiently on a relatively large database?

Upvotes: 0

Views: 910

Answers (2)

venegr
venegr

Reputation: 168

It is not a matter of how you write the query, but a matter of neo4j's structure. Simply put, no matter how you write the query, the edges cannot be deleted as efficient as you expect. This is because: 1)It is a huge transaction in neo4j with your data size. In its essential, neo4j ensures transaction for each operation. 2) There are a lot of random read and write from disk or memory and none of them are fast. So if you stick to neo4j, you'd better avoid such operations.

Upvotes: 1

Marj
Marj

Reputation: 485

Your query should run faster if you can specify a starting node label. E.g:

match (:SomeLabel)-[e:usedAt]->() delete e

Your original query is doing a full db scan, using labels will constrain the query to look only at the selected node types, which will be faster.

Use the periodic iterate, but try it with parallel set to false. Depending on your overall graph structure you might be suffering some deadlock in the parallel processing.

Upvotes: 0

Related Questions