Can I optimize this Neo4j request?

I have a fairly large data set (20 million nodes, 200 million edges), the simplest shortestPath requests complete in milliseconds, everything is fine.

But ... I need to allow shortestPath to have a ZERO or ONE relation of type 999 and it can only be the first one from the beginning of the node.

So my query became something like this:

MATCH (one:Obj{oid:'startID'})-[r1*0..1]-(b:Obj) 
WHERE all(rel in r1 where rel.val = 999) 
WITH one, b 
MATCH (two:Obj{oid:'endID'}), path=shortestPath((one) -[0..21]-(two)) 
WHERE ALL (x IN RELATIONSHIPS(path) 
WHERE (x.val > -1 and x.val<101) or (x.val=999 or x.val=998)) return path

it starts in milliseconds when there is a short path (up to 2-4), but it can take 5 or 20 seconds for paths like 5 ++. Maybe I wrote an inefficient request?

This question will be asked if available.

+4
source share
1 answer

, .

node.

ZERO ONE 999. ONE , .

, :

 MATCH (start:Obj {oid:'startID'}),
       (end:Obj {oid:'endID'}),
       path=shortestPath((start)-[1..21]->(end))
  WITH path, relationships(path) AS rels
 WHERE all(r IN relationships WHERE r.val != 999)
    OR (relationships[0].val = 999
        AND all(r IN relationships[1..] WHERE r.val != 999))
RETURN path

, , , , , .

: , WHERE :

 WHERE all(r IN relationships[1..] WHERE r.val != 999)

, .

+1

Source: https://habr.com/ru/post/1685438/


All Articles