Optimized SQL for tree structures

前端 未结 11 888
耶瑟儿~
耶瑟儿~ 2020-11-28 21:39

How would you get tree-structured data from a database with the best performance? For example, say you have a folder-hierarchy in a database. Where the folder-database-row h

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 22:30

    I am a fan of the simple method of storing an ID associated with its parentID:

    ID     ParentID
    1      null
    2      null
    3      1
    4      2
    ...    ...
    

    It is easy to maintain, and very scalable.

提交回复
热议问题