Laurynas Stašys
Laurynas Stašys

Reputation: 338

Find all subgraphs in neo4j

I am struggling with a Neo4j query to find all subgraphs in my graph. Basically, I need to find all pairs of type_a and type_b nodes who share same properties (currently, name and location).

a glorious subgraph

I have ~15mln location (gray) nodes, ~60mln name (red) nodes, ~320mln type_a (violet) nodes and ~250mln type_b (yellow) nodes.

My query looks like this:

CYPHER runtime=compiledExperimentalFeatureNotSupportedForProductionUse
EXPLAIN
MATCH (fname:name) WITH fname
MATCH fname_path=(user_a:user_a)-[:HAS_FNAME]->(fname)<-[:HAS_FNAME]-(user_b:user_b)
WITH user_a, fname, user_b
MATCH lname_path=(user_a)-[:HAS_LNAME]->(lname)<-[:HAS_LNAME]-(user_b)
WITH user_a, user_b, lname, fname
MATCH (user_a)-[:HAS_LOCATION]->(loc)<-[:HAS_LOCATION]-(user_b)
RETURN user_a.id,user_b.id,fname.name,lname.name,loc.name;

My current problem is that query has been running for almost two days without any result so I believe that there must be something wrong with it

Upvotes: 1

Views: 454

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41676

Try first with a limited dataset.

CYPHER runtime=compiledExperimentalFeatureNotSupportedForProductionUse
MATCH (fname:name) WITH fname
WITH fname LIMIT 100000
MATCH fname_path=(user_a:user_a)-[:HAS_FNAME]->(fname)<-[:HAS_FNAME]-(user_b:user_b)
WITH user_a, fname, user_b
MATCH lname_path=(user_a)-[:HAS_LNAME]->(lname)<-[:HAS_LNAME]-(user_b)
WITH user_a, user_b, lname, fname
MATCH (user_a)-[:HAS_LOCATION]->(loc)<-[:HAS_LOCATION]-(user_b)
RETURN user_a.id,user_b.id,fname.name,lname.name,loc.name;

And don't use neo4j-shell or cypher-shell but a program with the bolt driver that streams the result records directly to buffered file.

Upvotes: 1

Related Questions