I am aware of several models for describing hierarchical data in relational databases:
- self-reference parent (each record has has a foreign key pointing to the primary key of the same table, not sure what this is called)
- adjacency lists
- nested sets
It occurred to me that there is another way to describe a hierarchy which has a different set of drawbacks to these models (a high degree of redundancy for one thing) - that is to maintain a shadow table where all the ancestors for each node in a tree and the number of generations apart the node is from its ancestor, e.g.
node ancestor generations
---- -------- -----------
leaf parent 1
leaf grandparent 2
leaf great-grandparent 3
leaf root 4
parent grandparent 1
parent great-grandparent 2
parent root 3
grandparent great-grandparent 1
grandparent root 2
great-grandparent root 1
Describes the hierarchy....
root
|
+- great-grandparent
|
+- grandparent
|
+- parent
|
+- leaf
I sincerely doubt that I have invented something new - but I'm struggling to find a description of this on the web due to the noise returned by search engines.
Does this have a name already?