SQL Practice Logo

SQLPractice Online

Denormalization Strategies: Performance

Module: Schema Design & Advanced DDL

## Read Performance Improvements

Denormalization can dramatically improve read performance:

**Eliminating Joins:**

- Normalized query with 2 joins: 500ms

- Denormalized query with no joins: 50ms

- Improvement: 10x faster

**Reducing I/O:**

- Normalized: Read 3 tables (orders, customers, products)

- Denormalized: Read 1 table (orders with redundant columns)

- I/O reduction: 66%

**Simplifying Execution Plans:**

- Normalized: Hash join → Sort → Merge join

- Denormalized: Sequential scan or index scan

- CPU reduction: 70%

## Write Performance Impact

Denormalization makes writes slower:

**Single Table Update:**

- Normalized: UPDATE customers SET email = 'new@email.com' WHERE id = 123; (5ms)

- Denormalized: UPDATE customers + UPDATE orders (100 rows) (50ms)

- Impact: 10x slower writes

**Trigger Overhead:**

- Each trigger adds 1-5ms per operation

- Multiple triggers compound

- Bulk operations especially affected

**Transaction Size:**

- Normalized: 1 row update

- Denormalized: 1 + N row updates (N = number of related rows)

- Lock contention increases

## Storage Costs

Denormalization increases storage:

**Example: E-commerce Orders**

- Normalized orders: 50 bytes per row

- Denormalized orders (with customer_name, product_name): 150 bytes per row

- 10 million orders: 1GB vs 3GB

- Cost: 2GB extra storage

**Is it worth it?**

- Storage is cheap: $0.023/GB/month (AWS RDS)

- 2GB extra = $0.05/month

- Query performance improvement: Priceless

## Caching vs Denormalization