Mysql 5有管理分层数据的程序吗?
我使用嵌套集模型将 分层数据 保存到数据库表中,我感兴趣的是 MySQL 是否内置支持添加/删除节点,或者我必须从头开始编写存储过程。 谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,MySQL 没有内置函数来执行此操作。 您可能必须实施自己的解决方案。
我已经用存储过程实现了嵌套集,并且效果很好。 我相信在嵌套集原则上已经有了进一步的工作 嵌套间隔来解决与插入或删除节点所需的大量更新有关的问题 - 但这也有其自身的一系列问题。
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.
正如 @teabot 所说,MySQL 没有附带任何内置功能来执行此操作。 然而,存在许多资源,它们将为您所需的查询提供一半以上的不错的起点,因此您必须完全自己推出。
有关示例,请参阅在 MySQL 中使用图形,MySQL 文档,甚至可能 Joe Celko 的书。 根据您的具体用例,您可能还会发现有人已经为您完成了该操作(请参阅 django -mptt 实现)。
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).