Sobes.tech
Junior — Middle

What is denormalization in a database and why is it used?

sobes.tech AI

Answer from AI

Denormalization in a database is the process of intentionally introducing redundancy of data, that is, storing repeating information in multiple places. This is done to improve query performance by reducing the number of table joins.

Denormalization is applied when:

  • Complex queries with many JOINs are performed frequently, which slows down the operation.
  • There is a need to speed up data reading at the expense of redundant storage and potential complexities during updates.

For example, instead of storing the user's address only in a separate table, you can add address fields directly into the orders table to quickly retrieve all information without an additional join.

The disadvantage is that maintaining data integrity becomes more complex, as updates to information need to be made in multiple places.