简体   繁体   English

Neo4j家谱关系设计

[英]Neo4j Family Tree Relationship Design

I am designing an extended family tree using Neo4j. 我正在使用Neo4j设计扩展的家谱。 During the design of the relationships I came up with two approaches: 在关系设计期间,我想出了两种方法:

  1. CREATE (p:Person)-[:PARENT_OF]->(s:Person) CREATE (p:Person)-[:STEPPARENT_OF]->(s:Person) CREATE (p:Person)-[:MARRIED_TO]->(s:Person)

With this approach I am creating different relationships for every case (keep in mind that there will be a lot of cases = a lot of relationships) 通过这种方法,我为每个案例创建了不同的关系(请注意,会有很多案例=很多关系)

  1. CREATE (p:Person)-[r:PARENT_OF {type:'natural'}]->(s:Person) CREATE (p:Person)-[r:PARENT_OF {type:'step'}]->(s:Person) CREATE (p:Person)-[r:SPOUSE_OF {type:'marriage'}]->(s:Person)

With this approach there will be less relationships but the design is a little bit messy. 使用这种方法,关系会更少,但设计会有些混乱。

I would like to know which approach will be better and why? 我想知道哪种方法会更好,为什么?

You are choosing beetwen fine-grained ( :PARENT_OF , :STEPPARENT_OF , :MARRIED_TO ) or generic relationships ( :PARENT_OF {type:'natural'} , :PARENT_OF {type:'step'} , :SPOUSE_OF {type:'marriage'} ). 您选择的是beetwen细粒度( :PARENT_OF:STEPPARENT_OF:MARRIED_TO )或通用关系( :PARENT_OF {type:'natural'} :SPOUSE_OF {type:'marriage'} :PARENT_OF {type:'step'} :SPOUSE_OF {type:'marriage'} )。

The book Graph Databases (available for download in the Neo4j site) by By Ian Robinson, Jim Webber, and Emil Eifrém says: Ian Robinson,Jim Webber和EmilEifrém撰写的《 Graph Databases》一书(可在Neo4j网站上下载 )说:

Differentiating by relationship name is the best way of eliminating large swathes of the graph from a traversal. 通过关系名称进行区分是从遍历中消除大量图形的最好方法。 Using one or more property values to decide whether or not to follow a relationship incurs extra I/O the first time those properties are accessed because the properties reside in a separate store file from the relationships (after that, however, they're cached). 首次访问这些属性时,使用一个或多个属性值来决定是否遵循某个关系会导致额外的I / O,因为这些属性与关系位于不同的存储文件中(但是此后将对其进行缓存) 。

Remember that a graph database model should be built focused on the application needs. 请记住,应根据应用程序需求构建图形数据库模型。 That is: it depends basically on what type of queries are you asking to your database. 即:它基本上取决于您要查询数据库的查询类型。

  • If you need to evaluate the type of the relationship in your graph transversal queries, probably is a good idea split it into separated relationship types. 如果您需要在图形横向查询中评估关系的type ,将其拆分为单独的关系类型可能是个好主意。
  • Otherwise, keep it as a property of a generic relationship type. 否则,请将其保留为通用关系类型的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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