Hi habr. Recently, I was faced with a task that required the use of a structure such as trees. But not one global tree is built from the entire table, but several small trees. Moreover, when generating the page, it was necessary to obtain a tree corresponding to a specific element.
Now let's get straight to the point.
If every time you make a recursive query to build a tree, it will be very resource intensive.
I did this: when I create elements, I add them to the tree implemented in php, and then I simply serialize an instance of the tree class to another table, and
In the table with the elements, I add a column with the number of the desired tree. And when necessary, I just load the tree from that table. When I add a new item, I deserialize the tree, change it and serialize it back.
I am interested in - what disadvantages do you see in this approach?