3 ms·
Assuming you have lot's of little tree's in different area's one quick read optimization is have (parent node) and (root node). Writes become a pain but being
by Retric 17y ago
Assuming you have lot's of little tree's in different area's one quick read optimization is have (parent node) and (root node). Writes become a pain but being able to grab most tree's from the DB and update them in code often brings significant speedups.
- jerf 17y agoI do that one a lot, since I've yet to need to stick a multi-million node tree in a database. Careful attention to the tree re-assembly algorithm results in an O(n) re-assembly, regardless of the order of the incoming nodes. With a bit more work the same algorithm cost can give you detection of invalid trees; unless you really can't afford to load in whole trees at a time this is as fast as anything else. Ordering of the tree can be provided by either a sort at query time or an ordering parameter in the worst case. (If you use an ordered child representation and append children to their parents in the order you receive them, and you sort the tree nodes by, say, date, then the resulting tree will have all children sorted by date too, with one simple ORDER BY clause. This works great for a comment tree, for instance.) I consider this the go-to representation.