Graph Database Newbie Q- How to decide on the direction of a relation between 2 nodes -
how decide verb-direction of relation ?
e.g have country falling under sub region in turn under region. 1 better , there thumb rules on deciding direction.
(region)-[has]->(sub region)-[has]->(country)
or
(region)<-[belongs_to]-(sub region)<-[belongs_to]-(country)
regards san
i agree @inverfalcon directionality subjective decision. however, there may (at least) 1 situation in might want use specific direction, if make important use case faster.
this related fact if can make cypher pattern less specific (without affecting output), neo4j have less work , query faster.
for example, suppose entire data model consists of 2 node labels , 2 relationship types, below. (i use own data model, since don't know uses cases are.)
(:person)-[:acted_in]->(:movie) (:person)-[:directed]->(:movie) in order find movies actor acted in, query have following. (notice have specify acted_in type, because outgoing relationship of type directed. means neo4j has explicitly test every outgoing relationship type):
match (:person {id: 123})-[:acted_in]->(m:movie) return m; however, if data model replaced directed type directed_by type had opposite directionality, instead:
(:person)-[:acted_in]->(:movie) (:person)<-[:directed_by]-(:movie) with tweak, query simpler , faster (since neo4j not have test relationship types):
match (:person {id: 123})-->(m:movie) return m; and complete, notice in above 2 match patterns remove :movie label, since in both data models acted_in end node have movie label.
Comments
Post a Comment