简体   繁体   English

(neo4j)关系和节点中的属性数量的最佳实践

[英](neo4j) Best practice for the number of properties in relationships and nodes

I've just started using neo4j and, having done a few experiments, am ready to start organizing the database in itself. 我刚刚开始使用neo4j,并做了一些实验,已经准备好开始组织数据库本身。 Therefore, I've started by designing a basic diagram (on paper) and came across the following doubt: 因此,我首先设计了一个纸上的基本图表,然后遇到了以下疑问:

Most examples in the material I'm using (cypher and neo4j tutorials) present only a few properties per relationship/node. 我使用的资料中的大多数示例(cypher和neo4j教程)仅针对每个关系/节点提供了一些属性。 But I have to wonder what the cost of having a heavy string of properties is. 但是我想知道拥有大量属性的代价是多少。

Q: Is it more efficient to favor a wide variety of relationship types (GOODFRIENDS_WITH, FRIENDS_WITH, ACQUAINTANCE, RIVAL, ENEMIES, etc) or fewer types with varying properties (SEES_AS type:good friend, friend, acquaintance, rival, enemy, etc)? 问:支持多种关系类型(GOODFRIENDS_WITH,FRIENDS_WITH,ACQUAINTANCE,RIVAL,ENEMIES等)效率更高,还是较少具有不同属性的类型(SEES_AS类型:好朋友,朋友,熟人,对手,敌人等),效率更高? ?

The same holds for nodes. 节点也是如此。 The first draft of my diagram has a staggering amount of properties (title, first name, second name, first surname, second surname, suffix, nickname, and then there's physical characteristics, personality, age, jobs...) and I'm thinking it may lower the performance of the db. 我的图表的初稿具有惊人的属性(标题,名字,名字,名字,姓氏,第二个姓氏,后缀,昵称,然后是身体特征,个性,年龄,工作...),我认为这可能会降低数据库的性能。 Of course some nodes won't need all of the properties, but the basic properties will still be quite a few. 当然,某些节点并不需要所有属性,但是基本属性仍然会很多。

Q: What is the actual, and the advisable, limit for the number of properties, in both nodes and relationships? 问:在节点和关系中,属性数量的实际限制和建议限制是多少?

FYI, I am going to remake my draft in such a way as to diminish the properties by using nodes instead (create a node :family names, another for :job and so on), but I've only just started thinking it over as I'll need to carefully analyse which 'would-be properties' make sense to remain, even because the change will amplify the number of relationship types I'll be dealing with. 仅供参考,我将通过使用节点(创建节点:家族名称,为:job等创建另一个节点)以减少属性的方式来重新草稿,但我只是开始考虑如下我需要仔细分析保留哪些“可能的属性”有意义,即使更改会放大我将要处理的关系类型的数量。

Background information: 背景资料:

1) I'm using neo4j to map out all relationships between the people living in a fictional small town. 1)我正在使用neo4j绘制一个虚构小镇中人们之间的所有关系。 The queries I'll perform will mostly be as follow: 我将执行的查询主要如下:

a. 一种。 find all possible paths between 2 (or more) characters 查找2个(或更多)字符之间的所有可能路径

b. find all locations which 2 (or more) characters frequent 查找所有经常出现2个(或更多)字符的位置

c. C。 find all characters which have certain types of relationship (friends, cousins, neighbors, etc) to character X 查找与角色X有某种类型的关系(朋友,堂兄弟姐妹,邻居等)的所有角色

d. d。 find all characters with the same age (or similar age) who studied in the same school 查找在同一所学校就读过的具有相同年龄(或相似年龄)的所有角色

e. find all characters with the same age / first name / surname / hair color / height / hobby / job / temper (easy to anger) / ... 查找具有相同年龄/名字/姓氏/头发颜色/身高/爱好/工作/脾气(容易发怒)/ ...的所有字符

and variations of the above. 和以上的变化。

2) I'm not a programmer, but having self-learnt HTML and advanced excel, I feel confident I'll learn the intuitive Cypher quickly enough. 2)我不是程序员,但是拥有自学HTML和高级excel的能力,我确信我会足够快地学习直观的Cypher。

First off, for small data "sandbox" use, this is a moot point. 首先,对于小数据“沙盒”的使用,这是一个有争议的问题。 Even with the most inefficient data layout, as long as you avoid Cartesian Products and its like, the only thing you will notice is how intuitive your data is to yourself. 即使使用最无效的数据布局,只要您避免使用笛卡尔积及其类似物,您将注意到的唯一一件事就是数据对自己的直观程度。 So if this is a "toy" scale project, just focus on what makes the most organizational sense to you. 因此,如果这是一个“玩具”规模的项目,那么只需关注对您而言最有意义的组织。 If you change your mind later, reformatting via cypher won't be too hard. 如果您以后改变主意,通过密码重新格式化不会太难。


Now assuming this is a business project that needs to scale to some degree, remember that non-indexed properties are basically invisible to the Cypher planner. 现在假设这是一个需要在一定程度上进行扩展的业务项目,请记住,非索引属性基本上对Cypher计划者是不可见的。 The more meaningful and diverse your relationships, the better the Cypher planner is going to be at finding your data quickly. 您的关系越有意义和越多样化,Cypher计划者将越能迅速找到您的数据。 Favor relationships for connections you want to be able to explore, and favor properties for data you just want to see. 支持您希望能够探索的连接的关系,并支持您只想查看的数据的属性。 Index any properties or use labels that will be key for finding a particular (or set of) node(s) in your queries. 索引任何属性或使用标签,这些属性对于在查询中查找特定(或一组)节点至关重要。

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

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