In this lesson, you will learn how to evaluate the performance costs of joining multiple tables against the storage overhead of duplicating data.
Up until now, we have focused on keeping data "normalized"—splitting information into separate tables (like Users, Orders, and Products) to avoid repetition and ensure data consistency. While this is great for accuracy, it forces the database to perform complex joins every time you need a full picture of a record.
The Join Cost
Every time you perform an INNER JOIN or LEFT JOIN, the database engine must work to locate matching rows across different physical storage blocks. If you are joining several large tables, the engine must manage memory for intermediate result sets and calculate matches for every row. As we learned in our previous lessons on Join Path Analysis and Cardinality, joins become computationally expensive as the number of tables grows.
The Denormalization Alternative
Denormalization is the intentional act of adding redundant data back into a table to eliminate the need for those costly joins. Imagine a Sales table that requires a product name. Instead of joining the Products table every time you query sales, you could store the product_name directly in the Sales table:
-- Normalized: Requires joining to get the name
SELECT s.id, p.name
FROM Sales s
JOIN Products p ON s.product_id = p.id;
-- Denormalized: No join needed, but 'name' is duplicated for every sale
SELECT id, product_name
FROM Sales;
The Trade-off
Choosing to denormalize is a balancing act:
- Read Performance: Denormalization is often faster because you avoid expensive
JOINoperations. Reading a single, wide table is usually cheaper than stitching together multiple small ones. - Write/Storage Overhead: You pay the price in memory (storing the same string multiple times) and complexity during updates. If a product name changes, you now have to update it in every single
Salesrow instead of just once in theProductstable.
Key Takeaway: Denormalization trades off data consistency and storage efficiency for faster read performance by reducing the need for expensive join operations.