算法 求一个可以参考的梯形回复实例

metal · January 14, 2012 · Last by Rei replied at February 04, 2012 · 3502 hits
评论1
   评论2(回复评论1)
       评论3(回复评论2)

有没有这样的例子?

codecampo.com

关系型数据库麻烦点,听说 mongodb 好搞点

#2 楼 @clc3123 是否就像实现无限极树形菜单那样,用自关联?has_one?

#3 楼 @metal 我看过一本数据库的书中介绍过 sql 的 with 关键字,好像 mysql 不支持,postgresql 可以,可以无限 join 当前表,这样一层一层树形回复揪出来。不过我没有试过,觉得这种需求比较少,因为显示效果不友好。一般都是像 discuz 那种,只显示回复的哪一条,引用那一条就行了,这样的话只要 self join 一次就好了。

使用一个 path 来标识树状结构,依赖 LIKE 查询的效率。频繁的插入、删除节点只会影响一条记录:

ancestry https://github.com/stefankroes/ancestry

The materialised path pattern requires Ancestry to use a ‘like’ condition in order to fetch descendants. This should not be particularly slow however since the the condition never starts with a wildcard which allows the DBMS to use the column index.

postgresql 有个 ltree 的模块,用的就是 path。

另外:这种结构有好几个模型的,似乎没有完美的方案在数据库层次上解决“无限节点 + 添加删除节点效率很高”的问题。楼主可以搜索一下,比如关键词 tree, hierarchy structure sql。reddit 是这种树状结构的,也可以参考其实现(包括缓存),不过是 python 写的。

Trees in MongoDB http://www.mongodb.org/display/DOCS/Trees+in+MongoDB

Materialized Paths (Full Path in Each Node) 在关系数据库也可以用

You need to Sign in before reply, if you don't have an account, please Sign up first.