Does Mysql 5 have procedures for managing hierarch

2020-05-06 17:35发布

问题:

I use nested set model for saving hierarchical data into database table and I'm interested in if MySQL has built-in support for adding/deleting nodes or I have to write stored procedures from scratch. Thanks.

回答1:

To my knowledge MySQL does not have an inbuilt function to do this. You may have to implement your own solution.

I have implemented nested sets with stored procedures and it worked well. I believe there has been further work on the Nested Set principle with Nested intervals to address the issues regarding the high number of updates required on the insertion or deletion of a node - but this too has its own set of problems.



回答2:

as @teabot says, MySQL doesn't ship with any inbuilt functionality to do this. However, a number of sources exist which will give you more than a half decent starting point for the queries you require, so you want have to entirely roll your own.

For examples, see Working with Graphs in MySQL , the MySQL docs and maybe even Joe Celko's book. Depending on your exact use case, you might also find that someone has done it for you (see django-mptt implementation).