
本文介绍了建议在非关系数据库中使用分层数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个使用非关系数据库作为后端的Web应用程序(django-nonrel + AppEngine)。
我需要存储一些分层数据(项目/子项目_1 /子项目_N /任务),我想知道应该使用哪种模式。现在我想到了:
取决于你如何查询它们。例如,如果您只需要查找父项的直接子项,则邻接列表模型可能是最简单的。如果你想枚举整个子树,祖先列表或嵌套集合运行良好 - 尽管我会避免在App Engine上嵌套集合。
如果您需要事务完整性树中的对象 - 并且不会每秒更新一次,而是每秒更新一次 - 您应该查看App Engine对实体组和祖先的支持。
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?
解决方案
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.
这篇关于建议在非关系数据库中使用分层数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!