http://www.perlmonks.org?node_id=354090


in reply to Recommended modules for Parent-Child trees?

If you wish the nodes to be stored in a database, then I'd suggest reading (and understanding) Nested Set Trees. In the common case of insert occasionally, query often, they are far more efficient than the usual adjacency model that people think of.

Unfortunately I don't know of a module that automates generating them in Perl, and I'm not entirely sure what such a module should look like. (Which may be why I don't know of one...) So you'd have to do some reinvention, but at least you'd reinvent a good version.

  • Comment on Re: Recommended modules for Parent-Child trees?

Replies are listed 'Best First'.
Re: Re: Recommended modules for Parent-Child trees?
by Hero Zzyzzx (Curate) on May 18, 2004 at 03:37 UTC

    Got it. Nested set trees are very, very cool. Wow! Thanks for that. The efficiency with which you could select siblings/parents/ancestors and subtrees is crazy, recursive queries always bugged me (I've implemented parent-child relationships before).

    It's a bit hard to wrap my head around how to get it into code, but I can probably come up with something given the SQL in the article.

    I need to figure out now if speed of execution outweighs speed of development, and figure out where I'm going to spend my time.

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

    My Biz

        Jeez. 1996 that thing was written. Almost makes me wish I had a computer science degree. Besides complexity (like that's something to put aside) a nested set tree model really seems the way to go in my case.

        I fear my hubris is getting the best of me, but I think I'm going to be writing a new DBI-backed module. . .

        -Any sufficiently advanced technology is
        indistinguishable from doubletalk.

        My Biz