Описание тега nested-sets
The nested set model is a particular technique for representing nested sets (also known as trees or hierarchies) in relational databases.
From Wikipedia:
The nested set model is a particular technique for representing nested sets (also known as trees or hierarchies) in relational databases.
In the nested set model, nodes are numbered according to a tree traversal which visits each node twice, assigning numbers in the order of visiting, and at both visits. This leaves two numbers for each node, which are stored as two attributes. Querying becomes inexpensive: hierarchy membership can be tested by comparing these numbers. Updating requires renumbering and is therefore expensive. Refinements that use rational numbers instead of integers can avoid renumbering, and so are faster to update, although much more complicated.