I have the following graph topology:
There are OSMNode nodes with lat, lon, location properties. The OSMNodes are chained through NEXT relationships. Certain OSMNodes have a FIRST_NODE relationship pointed towards them:
(:OSMWay)-[:FIRST_NODE]->(:OSMNode)
I would like to link the OSMWay nodes with a [:NEXT_WAY] relationship and add a length property to it. The length of the NEXT_WAY relationship should be the sum of all [:NEXT {distance: distance}] properties of OSMNodes linking the two OSMWay nodes.
I created a query and it works fine, but it is rather slow: it creates 10K NEXT_WAY relationships every 45 seconds on average.
This is my query:
CALL apoc.periodic.iterate(
'MATCH (fw:OSMWay)-[:FIRST_NODE]->(fn:OSMNode)
WHERE NOT (fw)-[:NEXT_WAY]->()
RETURN fw, fn',
'CALL {
WITH fn
MATCH (fn)-[rls:NEXT*]->(ln:OSMNode)<-[:FIRST_NODE]-(nw:OSMWay)
WITH nw, rls LIMIT 1
RETURN nw, REDUCE(s=0, r in rls | s+r.distance) AS length
}
CREATE (fw)-[:NEXT_WAY {length: length}]->(nw)',
{batchSize:10000, parallel:false});
(How) could we change this query to improve execution speed?
Thank you.