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

    1. <legend id='p949r'><style id='p949r'><dir id='p949r'><q id='p949r'></q></dir></style></legend>
    2. <small id='p949r'></small><noframes id='p949r'>

      • <bdo id='p949r'></bdo><ul id='p949r'></ul>

    3. 在 SQL Server 中使用外键是否会严重影响性能?

      Is there a severe performance hit for using Foreign Keys in SQL Server?(在 SQL Server 中使用外键是否会严重影响性能?)
      <tfoot id='QpPtY'></tfoot>
      <legend id='QpPtY'><style id='QpPtY'><dir id='QpPtY'><q id='QpPtY'></q></dir></style></legend>
        <bdo id='QpPtY'></bdo><ul id='QpPtY'></ul>

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

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

              <tbody id='QpPtY'></tbody>
              • 本文介绍了在 SQL Server 中使用外键是否会严重影响性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尽最大努力说服我的老板让我们在我们的数据库中使用外键 - 到目前为止还没有运气.

                I'm trying my best to persuade my boss into letting us use foreign keys in our databases - so far without luck.

                他声称这会消耗大量的性能,并说我们只是偶尔有工作来清理无效的引用.

                He claims it costs a significant amount of performance, and says we'll just have jobs to cleanup the invalid references now and then.

                显然这在实践中是行不通的,数据库中充斥着无效的引用.

                Obviously this doesn't work in practice, and the database is flooded with invalid references.

                有谁知道比较、基准测试或类似的证明使用外键没有显着的性能影响?(我希望能说服他)

                Does anyone know of a comparison, benchmark or similar which proves there's no significant performance hit to using foreign keys? (Which I hope will convince him)

                推荐答案

                由于必须检查 FK,因此插入、更新和删除的性能会受到很小的影响.对于单个记录,除非您开始将大量 FK 关联到该表(显然,检查 100 个其他表需要比 2 个表更长的时间),否则这通常会很小以至于不会引起注意.这是好事不是坏事,因为没有完整性的数据库是不可信的,因此毫无用处.您不应以诚信换取速度.这种性能下降通常会被更好的执行计划优化能力所抵消.

                There is a tiny performance hit on inserts, updates and deletes because the FK has to be checked. For an individual record this would normally be so slight as to be unnoticeable unless you start having a ridiculous number of FKs associated to the table (Clearly it takes longer to check 100 other tables than 2). This is a good thing not a bad thing as databases without integrity are untrustworthy and thus useless. You should not trade integrity for speed. That performance hit is usually offset by the better ability to optimize execution plans.

                我们有一个中等大小的数据库,大约有 900 万条记录和 FK,它们应该出现在任何地方,很少注意到性能下降(除了一个设计糟糕的表,它有超过 100 个外键,从其中删除记录有点慢这一切都必须检查).我认识的几乎所有处理 TB 级大型数据库的 dba 以及对大型数据集高性能的真正需求都坚持外键约束,因为完整性是任何数据库的关键.如果拥有 TB 级数据库的人可以承受非常小的性能损失,那么您也可以.

                We have a medium sized database with around 9 million records and FKs everywhere they should be and rarely notice a performance hit (except on one badly designed table that has well over 100 foreign keys, it is a bit slow to delete records from this as all must be checked). Almost every dba I know of who deals with large, terabyte sized databases and a true need for high performance on large data sets insists on foreign key constraints because integrity is key to any database. If the people with terabyte-sized databases can afford the very small performance hit, then so can you.

                FK 不会自动编入索引,如果没有编入索引,可能会导致性能问题.

                FKs are not automatically indexed and if they are not indexed this can cause performance problems.

                老实说,我会复制你的数据库,添加正确索引的 FK,并显示插入、删除、更新和从这些表中选择的时间差,与没有 FK 的数据库相比.表明您不会造成性能下降.然后显示查询的结果,显示孤立记录不再有意义,因为它们相关的 PK 不再存在.对于包含财务信息的表(我们有 2700 个无法与客户关联的订单"将使管理层坐下来注意),显示这一点特别有效.

                Honestly, I'd take a copy of your database, add properly indexed FKs and show the time difference to insert, delete, update and select from those tables in comparision with the same from your database without the FKs. Show that you won't be causing a performance hit. Then show the results of queries that show orphaned records that no longer have meaning because the PK they are related to no longer exists. It is especially effective to show this for tables which contain financial information ("We have 2700 orders that we can't associate with a customer" will make management sit up and take notice).

                这篇关于在 SQL Server 中使用外键是否会严重影响性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How do I split flat file data and load into parent-child tables in database?(如何拆分平面文件数据并加载到数据库中的父子表中?)
                How to import CSV into sqlite using RSqlite?(如何使用 RSqlite 将 CSV 导入 sqlite?)
                Import CSV to Update rows in table(导入 CSV 以更新表中的行)
                Importing MaxMind#39;s GeoLite2 to MySQL(将 MaxMind 的 GeoLite2 导入 MySQL)
                Import / Export database with SQL Server Server Management Studio(使用 SQL Server Server Management Studio 导入/导出数据库)
                How do you import a large MS SQL .sql file?(如何导入大型 MS SQL .sql 文件?)
                    <bdo id='zluHA'></bdo><ul id='zluHA'></ul>
                      <tbody id='zluHA'></tbody>

                      <legend id='zluHA'><style id='zluHA'><dir id='zluHA'><q id='zluHA'></q></dir></style></legend>
                    1. <small id='zluHA'></small><noframes id='zluHA'>

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