All good points - thanks for the clarification!<br><br><div><span class="gmail_quote">On 2/9/07, <b class="gmail_sendername">Krishna Dole</b> &lt;<a href="mailto:dontfall@gmail.com">dontfall@gmail.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Jeff,<br><br>Thanks for writing us about this, and welcome to the list.<br><br>&gt; First, I think the parent_id field is completely unnecessary.&nbsp;&nbsp;The point of
<br>&gt; the nested set model seems to be that you eliminate the need for the join,<br>&gt; thereby creating a table with a single fact, in a single place.&nbsp;&nbsp;If you<br>&gt; don&#39;t have a parent_id, you identify a root as anything with lft=1.&nbsp;&nbsp;You can
<br>&gt; achieve multiple roots by using composite keys (by adding a set_id column,<br>&gt; for example).<br><br>You&#39;re right-- strictly speaking the parent_id field is unnecessary,<br>and thus non-normalized. However, we have chosen to keep it thus far
<br>for several reasons:<br><br>1) It provides a good backup to the lft/rgt indexes. Nested sets are<br>inherently both volatile and brittle. I feel good about our code&#39;s<br>ability to maintain the left/right values, but if they somehow became
<br>corrupted, repairing them without having parent_id would be a devilish<br>manual process at best and impossible at worst. We provide handy<br>methods for both checking and re-indexing using the parent_id.<br><br>2) It provides significant performance advantages in a number of
<br>situations: the common task of fetching a node&#39;s parent is _much_<br>faster using parent_id. Fetching immediate children would require a<br>&#39;level&#39; column if the parent_id was not present, and maintaining a
<br>level column would be a bit of work.&nbsp;&nbsp;(But nice to have-- it&#39;s on the<br>to-do list)<br><br>3) It makes reversion to an adjacency-list model trivial (just nuke<br>the lft and rgt cols) if you decide nested sets aren&#39;t for you. One of
<br>my goals with the code is to make it easy for people using<br>acts_as_tree to try a nested set model.<br><br>4) The parent_id is required (and used to good effect) in the ez-set branch.<br><br>5) It doesn&#39;t really cause any problems, performance or otherwise.
<br><br>&gt;<br>&gt; Second, the numbering scheme need not be contiguous.&nbsp;&nbsp;If you use the full<br>&gt; range of floats given in a database you can insert thousands of children<br>&gt; without ever having to recalculate other rows in the database.&nbsp;&nbsp;This will
<br>&gt; drastically increase performance on inserts/updates, and unless you are<br>&gt; working with huge sets, you may never need to recalculate parent boundaries.<br><br>I looked into using floats, but I was turned off by the fact that
<br>trees less than 60 levels deep (if I recall correctly) could overrun<br>the index. That said, if you would like to try implementing something<br>like this, please do-- I&#39;m happy to provide what advice I can.<br><br>
Keeping the index sequential has a few benefits: you can find out how<br>many descendants a node has without hitting the database, and it makes<br>finding &#39;leaf&#39; nodes easy.<br><br>&gt;<br>&gt; For more information (if you haven&#39;t already seen it), check out:
<br>&gt;<br>&gt; <a href="http://searchoracle.techtarget.com/tip/1,289483,sid13_gci537290,00.html">http://searchoracle.techtarget.com/tip/1,289483,sid13_gci537290,00.html</a><br><br>Thanks for linking to that. I&#39;d seen most of it before (Joe has
<br>recycled that material a lot of times), but some of the information at<br>the bottom was interesting.<br><br>Cheers,<br>Krishna<br>_______________________________________________<br>Betternestedset-talk mailing list<br>
<a href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk
</a><br></blockquote></div><br>