Implementing a hierarchical data structure in a database(在数据库中实现分层数据结构)
问题描述
我知道有两种方法:邻接表和嵌套树.据说由于大量查询,邻接列表在遍历时会变得很慢.但我不知道这方面的任何现实数字.我正在制作的网站将有 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")
- 嵌套集
- 路径枚举
- 闭表(又名邻接关系)
查看我对将平面表解析为树的最有效/最优雅的方法是什么?"
或者几本书:
- "Smarties 的 SQL 中的树和层次结构" 作者:乔塞尔科.
- "SQL 设计模式" by Vadim Tropashko.
- "Trees and Hierarchies in SQL for Smarties" by Joe Celko.
- "SQL Design Patterns" by Vadim Tropashko.
这篇关于在数据库中实现分层数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在数据库中实现分层数据结构


基础教程推荐
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01