Merge Relationships with node ids efficiently

(Gdebenito) #1

I use this query to relate some nodes between other nodes that the user has.
The problem I have is that when a lot of relationships are created, it takes longer and longer.
I'm trying to find the bottleneck here but I'm missing why or what.
If you can help me i would appreciate.

TL;DR here is my query to be optimized

{ "sender":123, "target":124, "label":"fruit", "bidirectional":true},
{ "sender":123, "target":125, "label":"vegetable", "bidirectional":false}
] as input
MATCH (s) <-[:HAS]-(user:User {author:"me"})-[:HAS]->(t)
UNWIND input as relationship
WITH s,t,relationship
WHERE ID(s) = relationship.sender AND ID(t) =
MERGE (s)-[:HAS {label: relationship.label}]->(t)
WITH s,t,relationship
WHERE relationship.bidirectional = true
MERGE (t)-[:HAS {label: relationship.label}]->(s)

The WITH clause is replaced by parameters I send to the query, input in my original query is $input.

I found this link interesting (
Thank you


(Andrew Bowman) #2

We can help, but could you PROFILE an execution of the query and (after expanding all elements) attach the profile plan here?