I'm in the process of building web based a commenting system, for which the comments are rendered in a reddit / disqus style tree structure.
The MySQL schema uses a string of ancestor id's, and the immediate ancestor to enable me to rebuild the tree structure in memory before rendering the nested comments in HTML.
My current system for 'paging' the data, requires that I build the entire tree structure in memory, and then use the position that a comment appears in the resulting tree structure to set the position from which HTML should start and stop rendering. My concern is that this seems somewhat inefficient in that it requires that I pull all data from the database, in order to potentially just render a subset of those comments to an HTML page.
While search engine queries have returned some useful results for how to persist data in tree structures, I'm unable to find much on retrieving data from such schemas.
Is there a better / known way to retrieve this data that would satisfy the above concerns?