1
votes

I have a graph with many hundread thousand nodes. In that, there is one particular node of interest. I want to get all nodes connected to that node with any relationship and any relationship depth (that is it might be connected to the original node through several other nodes). I queries node with its id property and expanded all its neighboring nodes. The graph looks like this with the node of interest highlighted/clicked:

enter image description here

I tried following query to get all those nodes:

MATCH (a {id :"8e5b90c5242f4382bd8e71ae901b0433"})
CALL apoc.path.expandConfig(a, 
{
  uniqueness: 'NODE_PATH'
}) yield path
return path

But this makes the neo4j take gigs of RAM and I have only 4GBs. The query hangs pc and never completes. Whats wrong with cypher?

1
It's important to understand what this particular expansion actually does. Because you're using NODE_PATH uniqueness, the only restriction here is that the same node cannot occur more than once in a given path. But this expansion will still be trying to expand to all possible unique paths in your graph. Not all possible relationships, all possible paths, of any length. In even a simple graph like this this is a staggering number of paths, which you don't even need since you just want the nodes. Those paths will be walking the same nodes and relationships over and over for a very long time.InverseFalcon
Does the path (a)-[]->(b) is considered different from (a)-[]->(b)-[]->(a)? If yes, does that imply any graph with a cycle will lead to infinite number of paths?Mahesha999
Yes, those are two different paths. Default uniqueness in Cypher expansions will find all possible paths exhausting all relationships (as limited by the types and directions of the relationships in the pattern). Since by default each relationship is only traversed once, you won't get an infinite loop or infinite number of paths when a loop is present. NODE_PATH uniqueness will be a bit better, as nodes can't be reused in each individual path, so the second path would not be considered.InverseFalcon

1 Answers

3
votes

You might want to use apoc.path.subgraphNodes() instead, which "expands to nodes of a subgraph" which es exactly what you want.

See the APOC User Guide, this function was added in March.