VARCHAR would probably not be a good idea here as the data is likely to exceed 255 characters (MySQL restriction) pretty quickly.

If the post-er wants to serialize, I'd imagine that blob or text would be a more flexible solution and without the 255 character restriction.

Personally, I'd go with a single table approach (assuming that each node has only a single parent) using a parent node id field...

nodes
node_id (UNIQUE INT)
parent_node_id (INT)
data (whatever is relevant)

That's just an off-the-cuff response, but as your nodes and subnodes theoretically contain the same information I wouldn't go sticking them in different tables. This way works by simply adding a parent_node_id column that would allow you look either up or down the node tree any arbitrary amount. It's not necessarily the fastest way (because of the multiple selects to move up or down the tree, so as the nodes reach 'n' levels they take, what is it, O(n) time) but it represents a relatively consistent interface that won't throw you into problems with your database.

A question of tradeoffs I suppose.


In reply to RE: Re: Storing Complex Structures in a database by jreades
in thread Storing Complex Structures in a database by xunker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.