3 ms·
The discussion of the storage of the hierarchies in the database is quite interesting.
by cjg 17y ago
The discussion of the storage of the hierarchies in the database is quite interesting.
- 83457 17y agoThis is the first time I've run across trees/nodes in the organization of relational data. Makes a lot of sense and certainly sounds like someone was "thinking outside the box".
- henning 17y agoThe nested set model is a well-known workaround for storing tree-like structures in a relational database.
- extension 17y agoExcept they implemented it wrong. You are supposed to leave gaps in the numbering to add new nodes. If you use consecutive numbers then inserting a node requires renumbering all consecutive nodes. When I was faced with this problem, I used a dynamically sized bit vector field as an id and indexed it lexicographically. When a node is inserted, it's assigned the id of its parent appended with a 0 or 1, depending on its relationship to the parent. Thus, ids are unlimited and never have to be reassigned. Selecting a subtree is just a single range search. For a non-binary tree, a vector of some other type can be used. I got the idea from this: http://en.wikipedia.org/wiki/Surreal_numbers http://en.wikipedia.org/wiki/Surreal_numbers