How to optimize query excluding relationship property and in-depth
![pedrochagasjr pedrochagasjr](https://community.neo4j.com/legacyfs/online/2X/6/6bb6e007132cb940382c7ceade41dca392bee277.png)
‎07-14-2020 03:11 PM
Hi,
My neo4j db has 3 million nodes and 32 million relationships, I'm running :
MATCH (p:Person{id:123})-[r*..2]-(m) WHERE NONE(x in r WHERE type(x) in ['Buyer','Seller','Owner']) RETURN p,r,m
when a node has many relationships it crashes (PROFILE crashes too), is there any way to improve the query??
- Labels:
-
Cypher
![MuddyBootsCode MuddyBootsCode](https://community.neo4j.com/legacyfs/online/2X/7/7b1e57bcf619a1531fb53f6cc4e0cb83c5c27f06.jpeg)
‎07-18-2020 07:42 AM
Is the depth check on relationships necessary? Meaning are you only looking for that pattern that matches 2 deep? Or are you looking for nodes that don't have the relationship at all? If it's not necessary to go deep into those relationships it would speed up your query quite a bit. You might be able to do something like:
MATCH (p:Person {id: 123})
WHERE NOT (r in (p)-[r*..2]->(m))
the rest of your logic here
You're currently traversing a lot of relationships which I'm sure is hurting your performance.
![pedrochagasjr pedrochagasjr](https://community.neo4j.com/legacyfs/online/2X/6/6bb6e007132cb940382c7ceade41dca392bee277.png)
‎07-20-2020 12:02 PM
Thanks for your reply. Yes, the depth check is necessary. I'm trying get all relationships expt Buyer,Seller,Owner up to the second depth level.
I think this part of exclusion is crashing :
![](/skins/images/35448E1D2B14DA61375C1E03B7139839/responsive_peak/images/icon_anonymous_message.png)