![]() |
Michael Gilfix Online |
Navigation |
Storing Hierarchies in Relational DBsI recently found myself posed with a design problem that necessitated storing a hierarchical structure in a relational database (no, a directory such as LDAP wasn't an option). A desirable solution would be implemented entirely in SQL, without dipping into stored procedure specifics. A bit of research turned up three techniques:
The adjacency list is cheap for writes but expensive for queries. Nested sets and the right child index are optimized for reads at the expense of writes. The nested sets approach is particularly quick for queries, taking full advantage of database indexing capabilities -at the cost of updating the index. The right child index approach seems like it could offer a middle ground, but it's unclear how much savings since this is still an optimized for read approach. In addition to execution time, the latter two approaches also offer significant latency savings, as the adjacency list approaches requires multiple queries to follow the chain of parents up the tree. The best part about all these approaches is that they only require basic SQL. By Michael Gilfix at 2007-01-16 05:48 | Databases | Michael Gilfix's blog | login or register to post comments
|
SearchRecent blog posts
|