REVERSE
→ Lesson 3: Replicas in NoSQL
When to Duplicate Correctly
Not denormalization
Calculated field
A counter instead of COUNT
price_paid in purchases
duration_sec in matches
matches_played for the player
How much was paid back then and how much the item costs now are two different facts. The 3NF is not violated; there is no duplication here at all.
Time difference: GENERATED ... STORED. Calculated on write and stored on disk. Current row only, IMMUTABLE; validity depends on the types.
When COUNT(*) is called on a million rows every time a profile is opened, the cost is the need to keep the counter up to date.
Six Questions That Must Be Answered Before Denormalization Can Be Accepted
1. Which query is getting cheaper?
2. Where is the "source of truth"?
3. Who updates the copy?
4. Is a delay acceptable?
5. How do you find a discrepancy?
6. How can I fix it?
“Fewer JOINs” is not a valid justification. First, we normalize the data to 3NF; we make exceptions only where we’ve identified a problem and documented the cause.