Junior — Middle
What is the purpose of denormalization in a database and in what cases is it applied?
sobes.tech AI
Answer from AI
Denormalization in a database is used to improve read performance by reducing the number of table joins (JOIN). This is achieved by duplicating data or merging related tables.
Denormalization is applied in cases where:
- Complex queries with many JOINs are frequently executed, slowing down performance.
- There is a need to speed up data reading in systems with a high volume of queries.
- Some redundant storage volume is acceptable to increase speed.
For example, in an online store, the customer's name can be stored directly in the orders table to avoid JOINs with the customers table each time an order list is requested.