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

查看:126
本文介绍了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)?

如果没有,并且您只想检查特定用户是否具有特定角色,那么以我的拙见,它应该不会造成难以维护的重要性能问题(因为您将遍历图形的某些关系,而忽略绝大多数您的超节点"的多个关系).我将保持简单的设计(过早的优化是万恶之源";)),一旦发现问题(内部将关系存储在类似链表的结构中,因此在超级节点上找到合适的结构可能会花费一些时间,即使您将搜索限制为某种关系类型,也可以使用元节点方法拆分Role节点(学习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天全站免登陆