Blog
Computing path of a node in a hierarchy
2008-09-16 13:21:05 by Martynas Jusevičius
One of the outstanding issues in the updated (so far internally) version of the DIY Framework, which now keeps resources in a hierarchy, is how to effectively calculate the full URIs of resources. For this post, it would be Blog/2008/09/16/Computing+path+of+a+node+in+a+hierarchy, where the post resource is a leaf node with a depth of 5. In general terms, the question is how to calculate path of a node.
Propel's nested sets implementation for some reason calculates the path by recursively traversing from the node to its parent and so on until the root is reached, although this can be done using one SQL query. But even one query per resource is not good enough, since usually one page would use tens or even hundreds of resource objects.
In order to improve performance and not to compute the URI on every load, we left the full URI property for resources as it was, in addition to the new relative (to parent resource) URI property, and properties needed to implement the nested sets. So the question is, how to keep the full URI up-to-date all the time with resource's position in the tree? It certainly needs to change when one of the ascendant (parent, parent of the parent etc.) resources, or the resource in question itself, is moved or updated. But that might also involve a chain reaction since full URIs of descendant resources would also need to change, and they might be in numbers of hundreds or thousands. Definitely a performance problem, especially if done on the PHP level. I was thinking about implementing this with SQL triggers somehow, but it doesn't seem to be so trivial. Anyone has ideas?
Comments (5)
If know all the resource ids, surely can do the whole lot in one query with GROUP_CONCAT() to build the uri, and GROUP BY resource id.
Summary of hierarchical storage method
I personally think that the "path enumeration" model is easier to maintain than the "adjacency list" and the "nested set" ones.
I summarize all 3 models on my blog:
http://patrickallaert.blogspot.com/2008/05/hierarchical-data-in-mysql-and-other.html
review buy newbie
Hello,
I just want to say thank tou for the information. I gound in very useful and interesting. I will use your post like a guide ;)
Best regards, Bradley.
great sight
nice post you have managed because i am liking this, well its the are of technology and this make new models and invent new product and design for the ease of humanity like your product, its interesting well right now i am doing critical analysis on <a href="http://www.netplusexam.com">network+ training</a> and make my research report on it which opens the horizons of opportunities and success for the welfare of the earth and its people. May someone use my research and make a new theory and a new thing which really desired by people.
Please pray for me, May God bless you.
Thanks,
(Brain Adam)
NFSqvrrJkYCDnBpnnN
gP50U1 <a href="http://fozglwiglgyj.com/">fozglwiglgyj</a>, [url=http://xsraitojrzjz.com/]xsraitojrzjz[/url], [link=http://asvofdeakpja.com/]asvofdeakpja[/link], http://sbowkylqaqqa.com/

2008-09-16 14:24:36 by Jared