##关系型数据库设计 ###parent_id |id |name | parent_id| |---|-------|-----------| |1 |A |NULL | |2 |B |1 | |3 |C |1 | |4 |D |2 | 优缺点: Pros: Easy to understand, fast to insert and move Cons: Requires multiple queries to get whole subtrees 针对查询问题,可以应用缓存来解决 ###left&right id name parent_id left right 1 A NULL 1 8 2 B 1 2 5 3 C 1 6 7 4 D 2 3 4 Pros: Lookup up entire subtrees with a single query (fast), intrinsic ordering of children Cons: Slow to insert and move, due to many modifications of existing records 针对修改问题,由于菜单读多写少,可以接受 ###记录path id name parent_id path 1 A NULL 1- 2 B 1 1-2- 3 C 1 1-2- 4 D 2 1-2-4-