树就是树,你还需要考虑什么吗? 罗纳德.里根
我们看个贴吧的例子,吧友们可以一起讨论一个主题,又可以互相评论,怎么存储这些评论信息呢?
第一版:
create table comment(
comment_id serial primary key,
parent_id bigint unsigned,
bug_id bigint unsigned not null,
author bigint unsigned not null,
comment text not null,
foreign key (parent_id) refenences comment(comment_id )
);
这样会有一个问题,如何遍历给定主题的所有评论?层级可以无限深的评论,1-2-3-4-5-6......,这注定是一个耗时的过程。
一、问题分析: