Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing hierarchical data in MySQL with high write load

I am building web application that should have high write load and thousands, even millions of hierarchical records representing user defined/constructed trees. I am not trying to build forum with threads but huge database with thousands of small-sized hierarchies (trees with up to 10-20 descendants)...

I am aware of many models for storing hierarchies - currently I am using Nested Sets but performance with huge data and load is issue. I am also doubtful that Adjacency Lists or something similar may resolve this.

I have been experimenting with Mongo database which is superfast key/value storage but I can use only MySQL.

I would like to hear about other people experiences with similar issues.

like image 910
idenoq Avatar asked Nov 08 '11 00:11

idenoq


2 Answers

If you can install MySQL plugins, then OQGraph storage engine is what you need.

like image 81
Mchl Avatar answered Sep 21 '22 05:09

Mchl


What is the problem with nested sets?

Is recomputing the lft/rgt values when you add/remove nodes?

Pretty sure with a bit of careful planning, you can tweak it so do only have to do rare recomputations. I've not actully tried it, but did do some planning for a system once (the client didnt want the system in the end!)

One, is multiplying the values, by say 1000, when first calculating them. Then if you add a node, you can just insert numbers between the values. Its only when there is a large number of insertions, do you start running out of numbers. A low priority batch process, could recompute the tree to free up numbers for fresh insertions.

Deleting can also be archived, with manipulating numbers. In fact a node without children is easy. No recomputation nedded. Gets more complicated if children, but I think should be doable.

like image 31
barryhunter Avatar answered Sep 21 '22 05:09

barryhunter