Neo4j 如何避免超级节点 [英] Neo4j how to avoid supernodes

查看:32
本文介绍了Neo4j 如何避免超级节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Neo4j 项目中,我有代表用户角色和权限的 RolePermission 实体.系统中的每个 User 都与适当的角色和权限集相关.

In my Neo4j project I have Role and Permission entities which represent user roles and permissions. Each User in the system has relationships to appropriate sets of roles and permissions.

我认为 RolePermission 是某种类型的超级节点,从未来的性能角度来看,它们可能会成为一个主要的问题.

I think Role and Permission are some kind of supernodes that can become a major headache from a performance point of view in future.

这种情况下的最佳实践是什么?如何重新实现RolePermission以避免超级节点可能出现的问题?

What is the best practice for this case ? How to reimplement Role and Permission in order to avoid possible issues with supernodes ?

推荐答案

您是否计划基于角色进行一些聚合/批量查询(即计算某个角色的人数,列出他们)?

Do you plan to make some aggregate/mass queries based on Roles (i.e. count number of people of certain role, list them)?

如果不是,而你只是想检查一个特定的用户是否有特定的角色,比起我的拙见,它应该不会造成难以维护的、重要的性能问题(因为你会遍历图的某些关系,忽略绝大多数您的超级节点"的多重关系).我会保持简单的设计(过早的优化是万恶之源";)),一旦发现问题(在内部,关系存储在类似链表的结构中,因此在超级节点上找到合适的可能需要时间,即使您将搜索限制为某种关系类型),使用元节点方法拆分角色节点也应该可以完成这项工作(在 中进行了描述)学习 Neo4j)

If not, and you just want to check if a specific user has certain Role, than in my humble opinion it should not cause difficult to maintain, important performance issues ( as you will traverse certain relationships of the graph, ignoring vast majority of multiple relations of your "supernodes" ). I would keep with simple design ( "premature optimization is the root of all evil" ;) ), and once problems are noticed (internally, relationships are stored in a linkedlist-like structure, so finding a proper one may take time on supernode, even if you restrict searching to a certain relation type), splitting Role nodes using meta-node approach should do the job (it's described in Learning Neo4j)

如果是,那么您有问题.这可能是 RDBMS 更好的领域......使用元节点可能无济于事,因为您仍然需要处理所有这些以列出/计算所有用户......因此将数据缓存在单独的存储中可能是简直是最好的主意......

If yes, you have a problem. That's probably a field in which RDBMS are better... Using meta nodes probably won't help, as you will still to have process all of them to list/count all users... So caching that data in a separate store may be simply the best idea ...

这篇关于Neo4j 如何避免超级节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆