非关系数据库上的分层数据的建议?
我正在开发一个使用非关系数据库作为后端的 Web 应用程序(django-nonrel + AppEngine)。 我需要存储一些分层数据(projects/subproject_1/subproject_N/tasks),我想知道应该使用哪种模式。现在我想到的是:
- 邻接列表(存储项目的父 ID)
- 嵌套集(存储项目的左右值)
在我的例子中,普通用户的嵌套深度不会超过 4-5 层。 另外,在用户界面上,我希望对第一级的项目进行分页,以避免在第一页加载时加载太多项目。
据我所知,到目前为止,当层次结构更多地用于显示时,嵌套集非常有用。当经常在树上进行编辑时,邻接列表非常有用。就我而言,我想我需要的显示多于编辑(当使用嵌套集时,即使显示效果很好,上面的分页可能会使编辑的事情变得复杂)。
根据您使用非关系数据库的经验,您有什么想法和建议吗?
I'm developing an web application that uses a non-relational database as a backend (django-nonrel + AppEngine).
I need to store some hierarchical data (projects/subproject_1/subproject_N/tasks), and I'm wondering which pattern should I use. For now I thought of:
- Adjacency List (store the item's parent id)
- Nested sets (store left and right values for the item)
In my case, the depth of nesting for a normal user will not exceed 4-5 levels.
Also, on the UI, I would like to have a pagination for the items on the first level, to avoid to load too many items at the first page load.
From what I understand so far, nested sets are great when the hierarchy is used more for displaying. Adjacency lists are great when editing on the tree is done often. In my case I guess I need the displaying more than the editing (when using nested sets, even if the display would work great, the above pagination could complicate things on editing).
Do you have any thoughts and advice, based on your experience with the non-relational databases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如何存储它们取决于您需要如何查询它们。例如,如果您只需要查找父级的直接子级,则邻接列表模型可能是最简单的。如果您想枚举整个子树,祖先列表或嵌套集效果很好 - 尽管我会避免在 App Engine 上使用嵌套集。
如果您需要树中所有对象的事务完整性 - 并且不会比每秒几次更频繁地更新整个树 - 您应该研究 App Engine 对实体组和祖先的支持。
How you store them depends on how you need to query them. For example, if you only need to find the direct children of a parent, an adjacency list model is probably simplest. If you want to enumerate entire subtrees, an ancestor list or nested sets work well - though I would avoid nested sets on App Engine.
If you need transactional integrity over all the objects in a tree - and won't be updating the tree as a whole more often than a few times a second - you should look into App Engine's support for entity groups and ancestors.
我使用 SQL Server 来存储非关系数据。 SQL Server有一些叫做hierarchyID的东西..这使得大部分都是透明的。
您遇到的具体问题是什么?
I've used SQL Server to house non-relational data. SQL Server has these things called hierarchyID.. which make most of this transparent.
What's the exact problem you're having?