Denormalization
Intentionally introduce redundancy to improve read performance. Common techniques: caching computed values in columns, storing aggregates, or pre-joining tables.
Intentionally introduce redundancy to improve read performance. Common techniques: caching computed values in columns, storing aggregates, or pre-joining tables.
-- 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 = ?;
Denormalize for read performance only after normalization proves too slow.