I'm running neo4j 2.2.4
I have a large chain of merge that matches/creates a bunch of nodes and relationships, as well as setting properties.
All my node merges are based on one index.
With an almost empty database (thus all merges will end up creating nodes/relationships), I get the following timings:
+-------------------+
| No data returned. |
+-------------------+
Nodes created: 40
Relationships created: 87
Properties set: 62
Labels added: 40
1557 ms
Total database accesses: 688
Now 40 nodes and 87 relationships aren't that many and I'd expect the query to execute much faster than 1.5 seconds.
Below is the timings for a larger query with a similar style.
+-------------------+
| No data returned. |
+-------------------+
Nodes created: 214
Relationships created: 454
Properties set: 469
Labels added: 214
298711 ms
I'm a bit surprised at how slow this is. Is there anything I might be doing wrong here?
Edit:
The beginning of the query looks like this, and the rest are in a very similar style:
merge (e1:Label { id: "e1" })
merge (e2:Label { id: "e2" })
merge (e1)-[:R1]->(e2)
merge (e3:Label { id: "e3" })
merge (e2)-[r1:R2]->(e3)
on create set r1.p = "v"
on match set r1.p = "v"
merge (e4:Label { id: "e4" })
merge (e4)-[:R1]->(e3)
merge (e1)-[:R2]->(e4)
merge (e5:Label { id: "e5" })
merge (e2)-[r2:R3]->(e5)
on create set r2.p = "v"
on match set r2.p = "v"
merge (e6:Label { id: "e6" })
merge (e6)-[:R1]->(e5)
merge (e1)-[:R3]->(e6)
Indexes
ON :Label(id) ONLINE (for uniqueness constraint)
Constraints
ON (e:Label) ASSERT e.id IS UNIQUE
Edit 2:
The profile for the ~40 node query are captured here: https://gist.github.com/haoyangnz/c59b99a9a99a87edf00a
The profile for the ~200 node query failed due to StackOverflowError
You may try merge all the nodes and after that merge relationships. Like
Merge (a:A{id:1}), (b:B{id:2}) with a, b Merge (a)-[:RELATES_TO]->(b).
And by separating merge it maight be easier to find the problem. You might need index for id, like in my case. But i'm not sure if it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With