Nested Sets
Let's see how Nested Sets can solve the Naive Trees antipattern.
The Nested Sets solution stores information with each node that pertains to the set of its descendants rather than the node’s immediate parent. This information can be represented by encoding each node in the tree with two numbers, which we can call nsleft
and nsright
.
Creating Comments
table with nsleft
and nsright
Let’s create the Comments
table, with nsright
and nsleft
as its columns.
Get hands-on with 1300+ tech skills courses.