gpt4 book ai didi

sql-server - SQL 快速插入,无需更新

转载 作者:行者123 更新时间:2023-12-02 22:17:24 26 4
gpt4 key购买 nike

我们在 SQL Server 2008 数据库中使用单个表进行审核。

单表架构运行良好,查询简单,适应架构更改。

但它是整个数据库的主要瓶颈。所有插入和更新都必须经过审计表。

我们已经对 SELECT 语句使用 NOLOCK HINT。

由于该表没有更新,是否有任何提高 INSERT 语句吞吐量的建议?

最佳答案

确保表上有 INT(或 BIGINT)IDENTITY 主聚集索引!最好没有其他索引(如果可能的话)——这些索引会减慢插入速度。

这是一个常见的误解,因为表只需要插入而几乎不需要任何读取,因此您应该“省去”主聚集键的麻烦。

正如 SQL Server 索引女神 Kimberly Tripp 在她出色的博客文章 The Clustered Index Debate continues 中所解释的那样:

Inserts are faster in a clustered table (but only in the "right" clustered table) than compared to a heap. The primary problem here is that lookups in the IAM/PFS to determine the insert location in a heap are slower than in a clustered table (where insert location is known, defined by the clustered key). Inserts are faster when inserted into a table where order is defined (CL) and where that order is ever-increasing.

因此,正确聚集索引可以加快插入速度,这里意味着静态(永不更改)、唯一、尽可能小(INT 或 BIGINT)并且最好是不断增加(无页面) split ,因此没有性能损失)。

此外,如果您的表仅进行插入而没有更新/删除,则应确保在聚集索引上使用 100% FILLFACTOR 来完全填充这些 SQL Server 页面。

马克

关于sql-server - SQL 快速插入,无需更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1316148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com