Hazel Tree is the tree structure system used by Blackcube to organize content hierarchically: menus, breadcrumbs, section navigation, etc. It relies on a mathematical approach that prioritizes read performance over write performance.
Concretely, Blackcube uses a structure based on rational fractions rather than the classic parent-child reference approach.
Attribution
Hazel Tree is an implementation of Dan Hazel's research work published in 2008: "Using rational numbers to key nested sets". This innovative approach solves the limitations of traditional Nested Sets by using rational fractions rather than integers, making insertion operations much more efficient. [Read the original paper on arXiv](https://arxiv.org/abs/0806.3115)
The Problem with Classic Trees
Traditional Trees (Adjacency List)
Classic trees simply store a reference to each element's parent. This approach has advantages and disadvantages:
- Simple and fast insertion
- Reading requires multiple recursive queries
- Cache mandatory to obtain acceptable performance
Hazel Tree
The Hazel Tree approach inverts this logic by optimizing reading at the expense of writing:
- Slightly more complex insertion, but these operations are rare
- Ultra-fast reading with a single SQL query
- No cache necessary for read operations
Performance
Display a 3-Level Menu
With a classic approach, about 50 SQL queries are needed to load all elements and their relationships. With Hazel Tree, a single query is sufficient.
Generate a 5-Level Breadcrumb
The classic approach requires 5 consecutive SQL queries to traverse the hierarchy upward. Hazel Tree retrieves everything in a single query.
Retrieve All Descendants
With classic trees, recursive queries are needed whose number depends on the tree's depth. Hazel Tree retrieves the entire branch in a single query, regardless of depth.
In Practice
You automatically benefit from Hazel Tree when using the following features:
- Displaying a navigation menu
- Generating a breadcrumb
- List of a section's children
- Retrieving a complete tree branch
No specific action is required from you. Blackcube automatically manages the Hazel Tree structure in the background when creating, modifying or deleting nodes.
Key Points to Remember
- Optimized for reading: Hazel Tree is designed for sites where displaying hierarchical content is frequent. Every visitor navigating your site benefits from optimal performance.
- Automatic management: You have nothing to configure or manage. Blackcube automatically takes care of maintaining the Hazel Tree structure consistently.
Warning
Adding, moving or deleting nodes is slightly more resource-intensive than with a classic approach. However, these administration operations are rare compared to the millions of displays generated by your visitors.