I have a graph which consist of millions of disconnected subgraph. Now I am trying to find the number of nodes for all of these subgraphs. For example, lets say I have this graph which contains A-B-C, D-E, F-G-H. So the return will be 3, 2, 3.
Now I am being able to do that using the following query:
MATCH (n) CALL apoc.path.subgraphNodes(n, {}) YIELD node WITH n , count(node) as nodesnum return nodesnum
However it is incredibly slow and not at all suitable for a graph with millions of nodes therefore I would like to know if this can be done in a much faster way.