Database.What is “denormalization”? What is it used for?

Denormalization is the process of intentionally introducing redundancy into a database by combining normalized tables — often for performance or simplicity reasons.

It’s the reverse of normalization, done not because of bad design, but to optimize read-heavy operations.

🎯 Why Use Denormalization?

  1. Improve Read Performance
    • Reduces the number of joins needed in complex queries.
    • Speeds up data retrieval in analytics and reporting.
  2. Simplify Queries
    • Fewer tables to query means easier SQL for developers.
  3. Caching or Materialized Views
    • Pre-aggregated or summary data can be denormalized to improve performance.

❌ Downsides of Denormalization

  • Data redundancy → more storage
  • Update anomalies → harder to keep redundant data consistent
  • Complex inserts/updates → more logic needed to maintain correctness

✅ Example: From Normalized to Denormalized

🔹 Normalized Structure

Customers

CustomerIDName
1Alice
2Bob

Orders

OrderIDCustomerIDProduct
1011Laptop
1022Phone

To get a customer’s name and product, you’d need a JOIN:

SELECT Orders.OrderID, Customers.Name, Orders.Product
FROM Orders
JOIN Customers ON Orders.CustomerID = Customers.CustomerID;

🔸 Denormalized Structure

Orders

OrderIDCustomerNameProduct
101AliceLaptop
102BobPhone

Now:

  • ✅ No join needed
  • ❌ But CustomerName is duplicated, and must be kept consistent across records

🧠 When to Use Denormalization?

Use it carefully when:

  • Your database is read-heavy
  • Joins are slowing down performance
  • Data doesn’t change often (e.g., reporting systems)
  • You’re working with NoSQL or data warehouses
This entry was posted in Без рубрики. Bookmark the permalink.