January 28, 2020 at 2:40 pm
Heh... it's funny. I was going to suggest the same things about the method I use. I maintain the adjacency list (with a detector to prevent loops) and regen the nested sets hierarchy when there are changes (which is now incredibly fast using the construction method I identify in the both articles).
Don't even think about trying to add, move, or delete in nested sets. Maintain the adjacency list and regen the nested sets after changes. Best of both worlds.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 30, 2020 at 9:32 pm
To add to what Jeff said, it's really not that hard to write a bunch of stored procedures for the nested set model. I published a few of these in various places, but you need a routine to renumber the left and right structure numbers, remove an entire subtree, insert an entire subtree, remove a single node and then promote the deleted node's subordinates, do some counts and whatever else you happen to need. The integer math is very simple, consisting of multiplying or dividing by two and incrementing or decrementing.
Please post DDL and follow ANSI/ISO standards when asking for help.
January 31, 2020 at 4:00 am
To add to what Jeff said, it's really not that hard to write a bunch of stored procedures for the nested set model. I published a few of these in various places, but you need a routine to renumber the left and right structure numbers, remove an entire subtree, insert an entire subtree, remove a single node and then promote the deleted node's subordinates, do some counts and whatever else you happen to need. The integer math is very simple, consisting of multiplying or dividing by two and incrementing or decrementing.
It's much easier to maintain the hierarchy using an Adjacency List and just rebuild the Nested Sets from that. I recently tested the methods in the "Hierarchies on Steroids" articles on my newer laptop... it'll rebuild the Nested Sets for a million node Hierarchy in 19 seconds instead of the previous 54 seconds (which smoked all other methods even then).
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 16 through 17 (of 17 total)
You must be logged in to reply to this topic. Login to reply