Hierarchical Data in MySQL

后端 未结 8 1631
南笙
南笙 2020-12-04 22:57

I\'ve got a sort of tree like thing going on in my MySQL database.

I have a database that has categories, and each category has a subcat. I\'m keeping all the catego

8条回答
  •  囚心锁ツ
    2020-12-04 23:58

    I would like to share my idea with you.

    Limitation of Adjacency Model: Follow the Managing Hierarchical Data in MySQL As you already described adjacency model has limitation that you have to know the level before you retrieve path.

    Use Nested model: But if you convert the data structure your data structure to Nested set model then you can still use the self join to get the tree.

    Converting Hierarchical model to Nested model: Now we need a tree travel algorithm to index the nested model. This can be implemented in mysql function (Sorry the conversion needs some algorithm implementation : A tree traversal algorithm. Not sure which one is best fitted).

    Thanks :)

提交回复
热议问题