NEW
Also known as: Tree-Structured Data
Data organized in parent-child relationships forming a tree-like structure for hierarchical querying and traversal.
DESCRIPTION
Hierarchical data represents entities with parent-child links, naturally forming trees. Common patterns include adjacency lists, nested sets, and materialized paths. JSON and XML often encode hierarchical structures, while relational systems model them via joins or specialized features. Databases provide hierarchical queries, recursive CTEs, or extensions like PostgreSQL ltree for indexing paths. Hierarchical models suit organizational charts, file systems, and product categories. Choosing the right modeling pattern affects query performance, maintainability, and data integrity. Graph databases offer alternative representations when relationships exceed tree constraints.
ALTERNATIVE DEFINITIONS
MongoDB
Hierarchical data is a common model for data that expresses parent-child relationships.
Emphasizes parent-child structure and modeling options.
Oracle
Hierarchical queries are used to select rows that have a hierarchical relationship.
Focuses on SQL support for hierarchical relationships.
PostgreSQL
The ltree module provides a data type for representing labels of data stored in a hierarchical tree-like structure.
Defines a native data type for storing hierarchical paths.
RELATED TERMS
Hierarchy Parent-Child Relationship Adjacency List Nested Set Model Materialized Path XML JSON
COMPETING TERMS
Relational Data Graph Data
RELATIONS
- Broader: Data
KNOWLEDGE AREAS
Data Modeling Data Architecture Data Storage & Operations Data Integration & Interoperability
TARGET AUDIENCE
Data Engineer Data Architect Data Modeler Software Developer BI Specialist
EXTERNAL SOURCES
- Wikipedia - Hierarchical database model
- MongoDB - Modeling tree structures in documents
- PostgreSQL - Hierarchical path data type
- Microsoft Learn - Recursive CTEs for hierarchies
- Neo4j - Tree modeling in graph databases
TOP QUESTIONS
What is Hierarchical Data and where is it used?
Hierarchical Data arranges records in parent-child trees. It’s used in org charts, file systems, categories, and menus.
Category: Overview
How do relational databases store Hierarchical Data?
Using adjacency lists, nested sets, or materialized paths, often with recursive CTEs to query ancestors and descendants.
Category: Implementation
What are trade-offs between adjacency lists and nested sets?
Adjacency lists are simple but slow for deep traversals; nested sets speed ancestor queries but complicate updates.
Category: Opinion
When should a graph database be chosen for Hierarchical Data?
Use graph databases when relationships include cross-links, multiple parents, or complex traversals beyond strict trees.
Category: UseCases
What are common mistakes modeling Hierarchical Data?
Choosing nested sets without tooling, ignoring referential integrity, and failing to index path columns are common pitfalls.
Category: Mistakes
How can Hierarchical Data be optimized for queries?
Use path indexing (e.g., ltree), cache ancestor paths, and maintain computed depth/leaf flags.
Category: Performance
What risks exist when updating deep hierarchies?
Reparenting can break invariants and cascade changes; ensure transactional updates and consistency checks.
Category: Risk
How are hierarchies represented in JSON?
Nested objects and arrays represent parent-child structures; careful schema design prevents ambiguity and deeply nested traversal costs.
Category: Implementation
Which SQL features help query Hierarchical Data?
Recursive CTEs, CONNECT BY, and window functions facilitate ancestor/descendant queries efficiently.
Category: Practices