• 技术文章 >数据库 >mysql教程

    Normalization VS Denormalization [转]

    2016-06-07 17:56:36原创781

    Denormalizationis the process of attempting to optimize the read performance of adatabaseby adding redundant data or by grouping data.In some cases, denormalization helps cover up the inefficiencies inherent inrelationaldatabase software.

    Denormalization is the process of attempting to optimize the read performance of a database by adding redundant data or by grouping data. In some cases, denormalization helps cover up the inefficiencies inherent in relational database software. A relational normalized database imposes a heavy access load over physical storage of data even if it is well tuned for high performance.

    A normalized design will often store different but related pieces of information in separate logical tables (called relations). If these relations are stored physically as separate disk files, completing a database query that draws information from several relations (a join operation) can be slow. If many relations are joined, it may be prohibitively slow. There are two strategies for dealing with this. The preferred method is to keep the logical design normalized, but allow the database management system (DBMS) to store additional redundant information on disk to optimize query response. In this case it is the DBMS software's responsibility to ensure that any redundant copies are kept consistent. This method is often implemented in SQL as indexed views (Microsoft SQL Server) ormaterialized views (Oracle). A view represents information in a format convenient for querying, and the index ensures that queries against the view are optimized.

    The more usual approach is to denormalize the logical data design. With care this can achieve a similar improvement in query response, but at a cost—it is now the database designer's responsibility to ensure that the denormalized database does not become inconsistent. This is done by creating rules in the database called constraints, that specify how the redundant copies of information must be kept synchronized. It is the increase in logical complexity of the database design and the added complexity of the additional constraints that make this approach hazardous. Moreover, constraints introduce a trade-off, speeding up reads (SELECT in SQL) while slowing down writes (INSERT, UPDATE, and DELETE). This means a denormalized database under heavy write load may actually offerworse performance than its functionally equivalent normalized counterpart.

    A denormalized data model is not the same as a data model that has not been normalized, and denormalization should only take place after a satisfactory level of normalization has taken place and that any required constraints and/or rules have been created to deal with the inherent anomalies in the design. For example, all the relations are in third normal form and any relations with join and multi-valued dependencies are handled appropriately.

    Examples of denormalization techniques include:

  • Materialized views, which may implement the following:
  • Storing the count of the "many" objects in a one-to-many relationship as an attribute of the "one" relation
  • Adding attributes to a relation from another relation with which it will be joined
  • Star schemas, which are also known as fact-dimension models and have been extended to snowflake schemas
  • Prebuilt summarization or OLAP cubes
  • Denormalization techniques are often used to improve the scalability of Web applications.]

    原文地址:

    Example: a shopping cart order

    Suppose that we are designing a schema for a shopping cart application. Our application

    stores orders in MongoDB, but what information should an order contain?

    Normalized schema

    A product: { : productId, : name, : price, : description } An order: { : orderId, : userInfo, : [ productId1, productId2, productId3 ] } ,美国服务器,美国空间,香港虚拟主机

    php入门到就业线上直播课:查看学习

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    前端(VUE)零基础到就业课程:点击学习

    清晰的学习路线+老师随时辅导答疑

    自己动手写 PHP MVC 框架:点击学习

    快速了解MVC架构、了解框架底层运行原理

    上一篇:Redis源码解析2 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• 实例分析MySQL中pt-query-digest工具的使用记录• 简单聊聊MySQL中join查询• 深入理解MySQL索引优化器工作原理• MySQL子查询详细教程• MySQL关于Count函数的用法区别总结
    1/1

    PHP中文网