简体   繁体   中英

Neo4j - Does relationship direction affect cypher performance?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM