I have 2 queries in neo4j
MERGE (f:Foo {id:1})
MERGE (b:Bar {id:1})
with f,b
FOREACH (i IN range(0,999) | create (f)-[:Qux]->(b));
Added 2 labels, created 2 nodes, set 2 properties, created 1000 relationships, statement executed in 39 ms.
and
MERGE (f:Foo {id:1})
MERGE (b:Bar {id:1})
with f,b
CREATE (f) - [:Qux] -> (b)
CREATE (f) - [:Qux] -> (b)
... (1000 times)
CREATE (f) - [:Qux] -> (b)
Added 2 labels, created 2 nodes, set 2 properties, created 1000 relationships, statement executed in 8301 ms.
How come it is so much slower to create relationships with statements than with a loop?
I want to be able to create many relationships at once but a loop isn't appropriate as I want to include data on each individual relationship. How could I do this fast without using a loop. I assume something about my syntax is making a wrong assumption.
NOTE: i cleared the graph before running each of these