• <bdo id='5dRvM'></bdo><ul id='5dRvM'></ul>
  1. <small id='5dRvM'></small><noframes id='5dRvM'>

    <tfoot id='5dRvM'></tfoot>
    <i id='5dRvM'><tr id='5dRvM'><dt id='5dRvM'><q id='5dRvM'><span id='5dRvM'><b id='5dRvM'><form id='5dRvM'><ins id='5dRvM'></ins><ul id='5dRvM'></ul><sub id='5dRvM'></sub></form><legend id='5dRvM'></legend><bdo id='5dRvM'><pre id='5dRvM'><center id='5dRvM'></center></pre></bdo></b><th id='5dRvM'></th></span></q></dt></tr></i><div id='5dRvM'><tfoot id='5dRvM'></tfoot><dl id='5dRvM'><fieldset id='5dRvM'></fieldset></dl></div>

      <legend id='5dRvM'><style id='5dRvM'><dir id='5dRvM'><q id='5dRvM'></q></dir></style></legend>

      我应该规范化我的数据库吗?

      Should I normalize my DB or not?(我应该规范化我的数据库吗?)
    1. <legend id='iOlKK'><style id='iOlKK'><dir id='iOlKK'><q id='iOlKK'></q></dir></style></legend>

      <small id='iOlKK'></small><noframes id='iOlKK'>

        <tbody id='iOlKK'></tbody>
    2. <i id='iOlKK'><tr id='iOlKK'><dt id='iOlKK'><q id='iOlKK'><span id='iOlKK'><b id='iOlKK'><form id='iOlKK'><ins id='iOlKK'></ins><ul id='iOlKK'></ul><sub id='iOlKK'></sub></form><legend id='iOlKK'></legend><bdo id='iOlKK'><pre id='iOlKK'><center id='iOlKK'></center></pre></bdo></b><th id='iOlKK'></th></span></q></dt></tr></i><div id='iOlKK'><tfoot id='iOlKK'></tfoot><dl id='iOlKK'><fieldset id='iOlKK'></fieldset></dl></div>
      • <bdo id='iOlKK'></bdo><ul id='iOlKK'></ul>

              1. <tfoot id='iOlKK'></tfoot>
                本文介绍了我应该规范化我的数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在为数据库(例如 MySQL)设计架构时,会出现是否完全规范化表的问题.

                When designing a schema for a DB (e.g. MySQL) the question arises whether or not to completely normalize the tables.

                一方面连接(和外键约束等)非常慢,另一方面你会得到冗余数据和潜在的不一致.

                On one hand joins (and foreign key constraints, etc.) are very slow, and on the other hand you get redundant data and the potential for inconsistency.

                最后优化"是正确的方法吗?即创建一个按手册规范化的数据库,然后查看可以进行非规范化以实现最佳速度增益的内容.

                Is "optimize last" the correct approach here? i.e. create a by-the-book normalized DB and then see what can be denormalized to achieve the optimal speed gain.

                关于这种方法,我担心的是,我会选择一个可能不够快的数据库设计 - 但在那个阶段重构架构(同时支持现有数据)将非常痛苦.这就是为什么我很想暂时忘记我学到的关于正确"RDBMS 实践的所有内容,并尝试一次平面表"方法.

                My fear, regarding this approach, is that I will settle on a DB design that might not be fast enough - but at that stage refactoring the schema (while supporting existing data) would be very painful. This is why I'm tempted to just temporarily forget everything I learned about "proper" RDBMS practices, and try the "flat table" approach for once.

                这个数据库将是大量插入的事实是否会影响这个决定?

                Should the fact that this DB is going to be insert-heavy effect the decision?

                推荐答案

                一个哲学性的答案:次优(关系)数据库充斥着插入、更新和删除异常.这些都会导致数据不一致,导致数据质量不佳.如果您不能相信数据的准确性,那又有什么用呢?问问自己:你想要正确的答案更慢还是想要错误的答案更快?

                A philosophical answer: Sub-optimal (relational) databases are rife with insert, update, and delete anomalies. These all lead to inconsistent data, resulting in poor data quality. If you can't trust the accuracy of your data, what good is it? Ask yourself this: Do you want the right answers slower or do you want the wrong answers faster?

                作为一个实际问题:在快速完成之前先做好.我们人类非常不擅长预测瓶颈会在哪里出现.使数据库变得更好,在适当的时间段内测量性能,然后决定是否需要使其更快.在进行非规范化和牺牲准确性之前,请尝试其他技术:您可以获得更快的服务器、连接、数据库驱动程序等吗?存储过程可以加快速度吗?索引及其填充因子如何?如果这些和其他性能和调优技术不起作用,那么只有考虑非规范化.然后测量性能以验证您是否获得了支付"的速度提升.确保您正在执行优化,而不是悲观.

                As a practical matter: get it right before you get it fast. We humans are very bad at predicting where bottlenecks will occur. Make the database great, measure the performance over a decent period of time, then decide if you need to make it faster. Before you denormalize and sacrifice accuracy try other techniques: can you get a faster server, connection, db driver, etc? Might stored procedures speed things up? How are the indexes and their fill factors? If those and other performance and tuning techniques do not do the trick, only then consider denormalization. Then measure the performance to verify that you got the increase in speed that you "paid for". Make sure that you are performing optimization, not pessimization.

                问:所以如果我最后优化,你能推荐合理的迁移方式模式更改后的数据?如果,例如,我决定摆脱一个查找表 - 我如何迁移现有的数据库用于这种新设计?

                Q: So if I optimize last, can you recommend a reasonable way to migrate data after the schema is changed? If, for example, I decide to get rid of a lookup table - how can I migrate existing databased to this new design?

                答:当然.

                1. 进行备份.
                2. 再备份到不同的设备.
                3. 使用select into newtable from oldtable..."类型命令创建新表.您需要进行一些连接以合并以前不同的表.
                4. 删除旧表.
                5. 重命名新表.

                但是...考虑更强大的方法:

                BUT... consider a more robust approach:

                立即在完全规范化的表上创建一些视图.这些视图(虚拟表、数据上的窗口"...如果您想了解有关此主题的更多信息,请询问我)将具有与上述第三步相同的定义查询.当您编写应用程序或 DB 层逻辑时,请使用视图(至少用于读取访问;可更新的视图是……好吧,很有趣).然后,如果您稍后进行非规范化,请按上述方式创建一个新表,删除视图,无论视图是什么,重命名新基表.您的应用程序/数据库层不会知道其中的区别.

                Create some views on your fully normalized tables right now. Those views (virtual tables, "windows" on the data... ask me if you want to know more about this topic) would have the same defining query as step three above. When you write your application or DB-layer logic, use the views (at least for read access; updatable views are... well, interestsing). Then if you denormalize later, create a new table as above, drop the view, rename the new base table whatever the view was. Your application/DB-layer won't know the difference.

                在实践中实际上还有更多内容,但这应该可以帮助您入门.

                There's actually more to this in practice, but this should get you started.

                这篇关于我应该规范化我的数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Set the variable result, from query(设置变量结果,来自查询)
                What is dynamic SQL?(什么是动态 SQL?)
                Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)
                Does MySQL have time-based triggers?(MySQL 有基于时间的触发器吗?)
                is it possible to call a sql script from a stored procedure in another sql script?(是否可以从另一个 sql 脚本中的存储过程调用 sql 脚本?)
                Procedure to loop through comma separated string is not working(遍历逗号分隔字符串的过程不起作用)
                  <tbody id='wTxNP'></tbody>

                  <small id='wTxNP'></small><noframes id='wTxNP'>

                    • <legend id='wTxNP'><style id='wTxNP'><dir id='wTxNP'><q id='wTxNP'></q></dir></style></legend>

                      <tfoot id='wTxNP'></tfoot>
                        <bdo id='wTxNP'></bdo><ul id='wTxNP'></ul>

                        • <i id='wTxNP'><tr id='wTxNP'><dt id='wTxNP'><q id='wTxNP'><span id='wTxNP'><b id='wTxNP'><form id='wTxNP'><ins id='wTxNP'></ins><ul id='wTxNP'></ul><sub id='wTxNP'></sub></form><legend id='wTxNP'></legend><bdo id='wTxNP'><pre id='wTxNP'><center id='wTxNP'></center></pre></bdo></b><th id='wTxNP'></th></span></q></dt></tr></i><div id='wTxNP'><tfoot id='wTxNP'></tfoot><dl id='wTxNP'><fieldset id='wTxNP'></fieldset></dl></div>