Reputation: 922
Let's assume the following situation. We have database with Person
nodes and Knows
relations. Finding people that know each other is trivial, but how to write the query that returns all people that particular person does not know? The only way I could think of it was:
match (n), (m) where not (n)-->(m) and n.id = 1 return n,m;
The obvious downside of this query is cartesian product, so with large amount of data this query would be terribly slow. But is there any other solution possible? I tried with OPTIONAL MATCH
, but it did not work out as there is no m
node when r is null
.
Upvotes: 3
Views: 83
Reputation: 10856
It's technically a cartesian product, but since once side in anchored to an individual node really the search space is just on the m
. Have you tried benchmarking the query?
Also, I wonder about trying this:
MATCH (m) WHERE NOT (n {id: 1})-->(m)
RETURN n,m;
Upvotes: 1