I have a system in existence which works on parent-child model.

  1. They share common attributes, as they belong to same class.
  2. A parent can enforces certain data on any user selected attribute, and the data is required to be propagated down the hierarchy for the same attribute in all children and their children.
  3. For a given attribute, if a child's parent dies (object gets destroyed) or child has not been enforced by parent, child can behave the same way, like in point #2, (on user request) for its children.

My system is pretty big (in database). For example:

  • Each object of the class has 150 atributes.
  • There are in total about 8 million attributes for objects created. Hence, the objects are close to 53,333.
  • There is a single parent for the objects. Its a big tree.

If I want to enforce data on the top most parent for a single attribute, it takes about 8 mins for it to complete.

Does anyone know a model which can perform faster than hierarchical model, but similar to behaviour?

  • 1
    $\begingroup$ If I understand you correctly, it is possible that every object will have a different value for some attribute. Then to enforce some value from the top, will definitely take 53333 assignments and they will take 8 mins. It could be that in reality this situation will very rarely occur or that you are allowed to do the assignments lazily. You should specify your needs in more detail. $\endgroup$ – Karolis Juodelė Jan 13 '13 at 13:52
  • $\begingroup$ 8 minutes seems like a lot of time for this small an update. Have you checked whether your database design and query are good? (If not, ask on Stack Overflow.) $\endgroup$ – Raphael Jan 14 '13 at 22:26

I am guessing that you used a technique known as "Adjacency list" to store your tree in the database. However, other solutions are also available, including "Path enumeration", "Nested sets" and "Closure table". The latter one, closure table, is the best one and you may want to design again your database using this technique for storing your hierarchical data.

For more information, see these slides, in particular the section on naive trees which starts at the slide #48. Or, this book from the same author. Finally, a more formal treatment of this subject is also included in this book.

  • $\begingroup$ Thank you! I will try to read and understand these when I get home. $\endgroup$ – Nayan Aug 6 '13 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.