Reputation: 1059
The cypher query:
MATCH (n1:ANIMAL)-[r:COHABITS]-(n2:ANIMAL)
RETURN distinct[id(n1),id(n2)] as tups, count(distinct[id(n1),id(n2)]) AS count
LIMIT 5
Never finishes, i.e. the query keeps running until neo4j encounters a javaheap memory failure. However when I execute:
MATCH (n1:ANIMAL)-[r:COHABITS]-(n2:ANIMAL)
RETURN n1,r,n2
LIMIT 5
I get a fast response.
Is there a reason/workaround for this?
Upvotes: 0
Views: 468
Reputation: 39915
For distinct
Cypher needs to build up the result set in memory to check if a new result is already present in the set. Without distinct, it just streams the results and only has very little need for heap space.
Depending on the number of :COHABITS
relationships you need to increase your heap space settings in neo4j-wrapper.conf
Upvotes: 1