Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j - Does relationship direction affect cypher performance?

Tags:

neo4j

cypher

Something I've always been curious about.

(Assuming you could magically flip the directions of relationships in neo4j)

Which would be faster?

START a=node(345)
MATCH (a)<-[:foo]-(b)<-[:bar]-(c)
RETURN c

or

START a=node(345)
MATCH (a)-[:foo]->(b)-[:bar]->(c)
RETURN c

Or does it not matter, as under the hood, you can traverse in either direction?

like image 993
Mark Mandel Avatar asked Aug 21 '13 04:08

Mark Mandel


1 Answers

Found the answer in the javadocs (http://api.neo4j.org/current/org/neo4j/graphdb/Relationship.html)

Even though all relationships have a direction they are equally well traversed in both directions so there's no need to create duplicate relationships in the opposite direction (with regard to traversal or performance).

That answers that.

like image 137
Mark Mandel Avatar answered Sep 18 '22 12:09

Mark Mandel