Recommendations with hierarchical data on non-relational databases?

爱⌒轻易说出口 提交于 2019-12-21 05:09:06

问题


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?


回答1:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/4634219/recommendations-with-hierarchical-data-on-non-relational-databases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!