是PostgreSQL的Ltree模块好适合用于螺纹意见?
-
03-07-2019 - |
题
我在考虑使用PostgreSQL的 Ltree模块 在我的申请,以帮助螺纹的意见。我一直在虎视眈眈了一段时间使用螺纹的意见。我想,它会帮助的情况下,需要更新的节点及其孩子,就像当你想要隐藏的评论和答复。
我想ltree(或类似的东西)它将是有用的,如果这是与传统的邻接表("comment_id"/"parent_comment_id").
之前投入使用ltree,我不知道一些事情:
- 是你,还有你,用ltree?这是什么一个可以称之为"生产"?
- 如果是这样,什么问题你有没有用它来解决?有没有这样做的一个良好的工作吗?
- 你认为这是一个良好的配合一
螺纹评论的系统?
- 如果你用它,你怎么使用"案文"一部分的道路?你有没有设立类似ODP例如,他们利用"上面。天文学。宇宙学"或基本上类似的主要关键"1.403.29.5"?
- 有没有更好的方式做到这一点?我有点紧张采用一种嵌套的列表方法--的一切我已经阅读表明,它并不是所有热带更新或插入(你没有重新安排整个事情?).我也不CS主要这种数据结构的东西我可能忘记的未来。是任何人使用嵌套的列表用于评论或类似的东西吗?
如果有任何帮助,这里是模式我正在考虑:
CREATE TABLE comments (
comment_id SERIAL PRIMARY KEY,
parent_comment_id int REFERENCES comments(comment_id) ON UPDATE CASCADE ON DELETE CASCADE,
thread_id int NOT NULL REFERENCES threads(thread_id) ON UPDATE CASCADE ON DELETE CASCADE,
path ltree NOT NULL,
comment_body text NOT NULL,
hide boolean not null default false
);
"路径"一栏,用于通过ltree,看起来是这样的:
<thread_id>.<parent_comment_id_#1>.<parent_comment_id_#2>.<my_comment_id>
是有什么错误使用的主键的道路?我应该包括节点自己的主键的道路?如果我做了,会是有意义的投入的一个独特的索引,以作为约束的?
解决方案
- 是的,是的,
- 层级结构的部分在一个知识基础(一个实现);
- 是的,
该定义的一个表中的问题:
Table "knowledgebase.section"
Column | Type | Modifiers
----------------------------+--------------------------+-----------------------------------------------------------------------------
section_sid | integer | not null default nextval('knowledgebase.section_section_sid_seq'::regclass)
section | character varying | not null
description | character varying |
path | ltree | not null
is_active | boolean | not null default true
role_sid | integer | not null
last_modified_by | integer | not null
creation_datetime | timestamp with time zone | not null default now()
last_modification_datetime | timestamp with time zone | not null default now()
is_expanded | boolean | not null default false
section_idx | tsvector |
Indexes:
"section_sid_pkey" PRIMARY KEY, btree (section_sid)
"section_section_key" UNIQUE, btree (section)
"idxsection_idx" gist (section_idx)
"path_gist_idx" gist (path)
Foreign-key constraints:
"last_modified_by_fkey" FOREIGN KEY (last_modified_by) REFERENCES "user"."role"(role_sid) ON UPDATE CASCADE ON DELETE RESTRICT
"role_sid_fkey" FOREIGN KEY (role_sid) REFERENCES "user"."role"(role_sid) ON UPDATE CASCADE ON DELETE RESTRICT
Triggers:
section_idx_update BEFORE INSERT OR UPDATE ON knowledgebase.section FOR EACH ROW EXECUTE PROCEDURE tsearch2('section_idx', 'section')
"路径"栏中使用的主要关键作为一个标签。
一个样品目前的内容表(关于主键和"路径"栏):
section_sid | path
-------------+-------
53 | 34.53
56 | 56
55 | 29.55
35 | 35
54 | 34.54
37 | 30.37
... | ...
其他提示
8.4版的PostgreSQL将带来共同的表格式功能纳入核心与 WITH
和 WITH... RECURSIVE
表达方式。如果你是修改旧的代码,你可能想等到8.4被释放,然后你会不会担心任何不兼容性之间的Ltree和新的核心语法。如果你的工作与老刑法,或者不想等待8.4,你可能会想要确定你写的代码是容易翻译的新的语法,尤其是如果你改变旧的模式或设计一个新的一个。
参见:
不隶属于 StackOverflow