I asked the same question on Slack and they suggested me to move the discussion on Neo4j Community.
How to optimize below Cypher?
PROFILE
MATCH (port:PhysicalPort) WHERE NOT (1 IN port.latest) WITH port
MATCH (device:Device) WHERE NOT (1 IN device.latest) WITH port , device
MATCH (building:Location) WHERE building.archetypeId=1008 AND NOT (1 IN building.latest) WITH port , device , building
MATCH (building) - [:HAS*0..2] -> (childLoc:Location) -[:HAS] -> (rack:Rack) -[:HAS] -> (rackPos:RackPosition) -[:HAS] -> (device) WITH port , building , device
MATCH (device) - [:HAS*1..8] -> (port) WITH DISTINCT port
RETURN port.drniId
I don't have indexing on :Location(archetypeId) and 'latest' (all Nodes) .! I have attached the execution plan.
There was a suggestion as well on the Slack.
Suggestion:
If you have multiple ports and devices that match the latest condition you’ll be running the statements after multiple times so it may be quicker to match the building first
eg
PROFILE
MATCH (building:Location) - [:HAS*0..2] -> (childLoc:Location) -[:HAS] -> (rack:Rack) -[:HAS] -> (rackPos:RackPosition) -[:HAS] -> (device:Device) -[:HAS*1..8]->(port:PhysicalPort)
WHERE building.archetypeId=1008 AND NOT (1 IN device.latest) AND NOT (1 IN port.latest)
RETURN port.drniId
But this makes the scenario much worse and my Neo4j browser hangs.
Additional Details:
Neo4j Database Version : 3.4.0
Neo4j Desktop: 1.1.12
Neo4j Database Edition: Enterprise
Any help would be greatly appreciated.
