0
votes

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

1
it is not weird that it takes so much, since you're getting a cartesian product of 4, so O(n^4), which is a lot. You should probably filter the nodes. What exactly are you trying to get with the query?zaboco
i want to see the possible resource flows between facilities. May be the solution set will be large but, as i read in "graph databases" oreilly books, 800k rows returned in 1-2 seconds. They cited from Neo4j in Action. Are they wrong? or i missed something?kemals
If you have :IN and :OUT relationships, if cycles in that relationship pattern are possible then your query seems like it's evaluating every path between every set of nodes in your DB. You should place some constraints on what m is, and you should probably specify WHERE m<>k AND k<>o AND n<>l AND l<>o.FrobberOfBits

1 Answers

1
votes

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