if you are reading more than you are writing, this method seems pretty cool.
Actually, most writing functions are easier too ;-) Update operations on subtrees and leaf nodes can usually be implemented in a single SQL statement.
Insertion is really the only vaguely complex/expensive operation - and that's still just three SQL statements in a basic implementation.
The only downside is that inserts can be expensive compared to just storing the parent ID. With the implementation Celko outlined in the article inserting a node is O(N).
Still the average case isn't that bad. You can also make inserts less expensive on average by using increments larger than 1 and inserting in the "gaps" until a global renumbering becomes necessary - but since this makes the selects more complex, and most systems read/update a lot more than they insert, it's rarely worthwhile.
In reply to Re^4: (OT?) Recursive sql queries?
by adrianh
in thread (OT?) Recursive sql queries?
by BUU
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |