Take a look at https://maxdemarzi.com/2017/02/06/neo4j-is-faster-than-mysql-in-performing-recursive-query/ or try the query on Neo4j 3.2 (Alpha release) as it does a better job handling these types of queries.
On Tuesday, February 14, 2017 at 7:01:39 PM UTC-6, Steve wrote: > > I am getting started with Neo4j and wondering about finding the nodes > connected to another node from at most k edges (friend of a friend of a > friend ... up to k times). I will illustrate with the example from the > tutorial in Neo4j itself (I put graph creation commands are at the bottom). > > match (e {name:"Emil"})-[*1..2]-(p) > return DISTINCT e, p; > > This query would return nodes connected to Emil and nodes connected to > those nodes. My issue is that it seems this enumerates EVERY path of length > 1-2 from Emil, though I don't care about enumerating all paths. This is an > issue in large, dense graphs as the complexity becomes overwhelming. Based > on my testing, it seems DISTINCT is a post-processing step that does not > affect the runtime of the query, though it will eliminate the redundant > output. Is that correct? > > My main question, is there a way to form a Cypher query for this problem > so that I am not traversing all the unique paths and the complexity can be > reduced? Please let me know if I have a misunderstanding somewhere as well. > > > Best, > Steve > > > ---- Commands to create the graph ----- > CREATE (ee:Person { name: "Emil", from: "Sweden", klout: 99 }) > MATCH (ee:Person) WHERE ee.name = "Emil" > CREATE (js:Person { name: "Johan", from: "Sweden", learn: "surfing" }), > (ir:Person { name: "Ian", from: "England", title: "author" }), > (rvb:Person { name: "Rik", from: "Belgium", pet: "Orval" }), > (ally:Person { name: "Allison", from: "California", hobby: "surfing" }), > (ee)-[:KNOWS {since: 2001}]->(js),(ee)-[:KNOWS {rating: 5}]->(ir), > (js)-[:KNOWS]->(ir),(js)-[:KNOWS]->(rvb), > (ir)-[:KNOWS]->(js),(ir)-[:KNOWS]->(ally), > (rvb)-[:KNOWS]->(ally) > > -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.