SyntaxStudy
Sign Up
MySQL Denormalization for Performance
MySQL Intermediate 4 min read

Denormalization for Performance

Denormalization

Intentionally introduce redundancy to improve read performance. Common techniques: caching computed values in columns, storing aggregates, or pre-joining tables.

Example
-- Normalized: count comments by querying comments table (slow)
SELECT COUNT(*) FROM comments WHERE post_id = 1;

-- Denormalized: store comment_count on posts table
ALTER TABLE posts ADD COLUMN comment_count INT DEFAULT 0;

-- Update on insert
UPDATE posts SET comment_count = comment_count + 1 WHERE id = ?;
Pro Tip

Denormalize for read performance only after normalization proves too slow.