Search⌘ K
AI Features

Antipattern: Always Depend on One’s Parent

Understand the common SQL antipattern of relying solely on the parent_id column in hierarchical data structures. Learn how the Adjacency List model handles immediate parent-child relationships but struggles with querying all descendants beyond two levels. This lesson helps you recognize why this approach is limited and prepares you to explore better methods for managing and querying hierarchical data.

Let’s imagine a query in which there is a need to retrieve the parents or children of a node. What should be our solution to such a query?

The answer is Adjacency List.

Any solution that we would find for this problem would include modifying the code that manages the tree data structures. Let’s discuss it in detail.

Adjacency list

The solution we might first think of, and that is ...