I discovered https://en.wikipedia.org/wiki/Nested_set_model while investigating ways to implement nested comments efficiently on the site. It solves the problem of modeling arbitrary levels of nesting in a relational database, and being able to query for only particular subtrees. I ended up not using it, but I think it is an interesting idea nonetheless.