kemals
kemals

Reputation: 226

Cypher query takes too much time

on default setup of Neo4j, I build up database with query

CREATE  (R1:resource { name : '1' }),
        (R2:resource { name : '2' }),
        (R3:resource { name : '2' }),
        (F1:facility { name : '1' }),
        (F2:facility { name : '2' }),
        (F10)-[:OUT]->(R6),
        (R6)-[:IN]->(F3)

for simplicity, i wrote part of query. To explain, I have 8 resources and 25 facilities, facilities out or in resources with relations. I have 1000 relations randomly generated, Now I query database with

match (m:facility)-[:OUT]->(n:resource)
-[:IN]->(k:facility)-[:OUT]->(l:resource)
-[:IN]->(o:facility) return m,n,k,l,o 

but it takes more than 15 minutes. Isn't this weird Please help Thx

Upvotes: 0

Views: 149

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41676

You can also add a LIMIT 100 to your query, and try to profile it in the neo4j-shell

You also have to get the cardinality down in terms of exploding combinatorial breadth.

match (m:facility)-[:OUT]->(n:resource)-[:IN]->(k:facility)
with distinct m,collect(n) as resources_n,k
match (k)-[:OUT]->(l:resource)
with distinct with with distinct m,collect(resources_n,k) as flow, l
match (l)-[:IN]->(o:facility) 
return distinct m,flow,o
limit 100

Upvotes: 1

Related Questions