在数据库中实现分层数据结构 [英] Implementing a hierarchical data structure in a database

查看:37
本文介绍了在数据库中实现分层数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有两种方法:邻接表和嵌套树.据说由于大量查询,邻接列表在遍历时会变得很慢.但我不知道这方面的任何现实数字.我正在制作的网站将有 200 页的区域.生成(例如)站点地图的遍历时间是否会超过大约 0.3 秒?

I know there are two approaches: adjacency list and nested tree. It's said that adjacency list can become slow to use on traversal because of numerous queries. But I don't know any realistic figures for this. The site I'm making will have in the region of 200 pages. Is traversal to generate (for example) a sitemap going to take longer than about 0.3 seconds?

使用 LAMP 堆栈在 MySQL (innoDB) 上运行.

Running on MySQL (innoDB) with LAMP stack.

如果可能,我更喜欢实现邻接,因为设计更简单.

I'd prefer to implement adjacency if possible because of the more simplistic design.

谢谢.

推荐答案

除了您提到的两个之外,还有更多选项.有:

There are more options than just the two you mention. There are:

  • 邻接列表(几乎每个人都使用的parent_id")
  • 嵌套集
  • 路径枚举
  • 闭表(又名邻接关系)

查看我对将平面表解析为树的最有效/最优雅的方法是什么?"

或者几本书:

  • "Trees and Hierarchies in SQL for Smarties" by Joe Celko.
  • "SQL Design Patterns" by Vadim Tropashko.

这篇关于在数据库中实现分层数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆