How to represent a data tree in SQL?

后端 未结 8 853
星月不相逢
星月不相逢 2020-12-02 06:20

I\'m writing a data tree structure that is combined from a Tree and a TreeNode. Tree will contain the root and the top level actions on the data. I\'m using a UI library to

8条回答
  •  长情又很酷
    2020-12-02 06:52

    I've bookmarked this slidshare about SQL-Antipatterns, which discusses several alternatives: http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back?src=embed

    The recommendation from there is to use a Closure Table (it's explained in the slides).

    Here is the summary (slide 77):

                      | Query Child | Query Subtree | Modify Tree | Ref. Integrity
    Adjacency List    |    Easy     |     Hard      |    Easy     |      Yes
    Path Enumeration  |    Easy     |     Easy      |    Hard     |      No
    Nested Sets       |    Hard     |     Easy      |    Hard     |      No
    Closure Table     |    Easy     |     Easy      |    Easy     |      Yes
    

提交回复
热议问题