How to implement high performance tree view in SQL Server 2005

后端 未结 5 1207
遥遥无期
遥遥无期 2021-02-01 00:04

What is the best way to build the table that will represent the tree? I want to implement a select ,insert ,update and delete that will work well with big data. The select for e

5条回答
  •  广开言路
    2021-02-01 00:13

    You have to ask yourself these questions first : 1) What is ratio of modifications vs reads ? (= mostly static tree or changing constantly?) 2) How deep and how large do you expect the tree to grow ?

    Nested sets are great for mostly-static trees where you need operations on whole branches. It handles deep trees without problems.

    Materialized path works well for dynamic (changing) trees with constrained/predictable depth.

    Recursive CTEs are ideal for very small trees, but the branch operations ("get all children in this branch..") get very costly with deep / large tree.

提交回复
热议问题