Fast Relational method of storing tree data (for instance threaded comments on articles)

后端 未结 6 1130
你的背包
你的背包 2020-12-13 10:59

I have a cms which stores comments against articles. These comments can be both threaded and non threaded. Although technically they are the same just with the reply column

6条回答
  •  臣服心动
    2020-12-13 11:34

    Actually, it has to be a balance between read and write.

    If you are OK with updating a bunch of rows on every insert, then nested set (or an equivalent) will give you easy, fast reads.

    Other than that, a simple FK on the parent will give you ultra-simple insert, but might well be a nightmare for retrieval.

    I think I'd go with the nested sets, but be careful about the expected data volume and usage patterns (updating several, maybe a lot of, rows on two indexed columns (for left and right info) for every insert might be a problem at some point).

提交回复
热议问题