cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to optimize query excluding relationship property and in-depth

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??

2 REPLIES 2

MuddyBootsCode
Graph Steward

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.

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 :