gpt4 book ai didi

sql - 避免基于递增键创建聚集索引

转载 作者:行者123 更新时间:2023-12-02 09:23:16 25 4
gpt4 key购买 nike

我从 mssqlcity.com 得到了这个提示。但是,我无法理解它的解释。

避免基于递增键创建聚集索引

For example, if a table has surrogate integer primary key declared as IDENTITY and the clustered index was created on this column, then every time data is inserted into this table, the rows will be added to the end of the table. When many rows will be added a "hot spot" can occur. A "hot spot" occurs when many queries try to read or write data in the same area at the same time. A "hot spot" results in I/O bottleneck. Note. By default, SQL Server creates clustered index for the primary key constraint. So, in this case, you should explicitly specify NONCLUSTERED keyword to indicate that a nonclustered index is created for the primary key constraint.

在阅读本文之前,我认为如果我选择本质上随机的列,这是不正确的,因为这会在添加新行时导致不必要的页面重定位。因此,我认为使用排序列是更好的选择。

读完这个提示后,我认为它是想说我们并不真的想使用直接排序的列作为我们的聚集索引,因为对于那些写入密集型应用程序来说将会存在 I/O 瓶颈。

我不太明白他们所说的 I/O 瓶颈的原因。他们是否说共享同一页面的太多操作会减慢磁盘操作速度?这是怎么发生的?有人可以给我解释一下吗?

最佳答案

他们所指的热点在 SQL Server 2005 及更高版本中不是问题。

发生的情况是,所有数据都被写入聚集索引的同一区域和磁盘上的同一扇区,这导致立即创建大量脏页(脏页是数据)已更改但未提交到磁盘的页面),并且当刷新或检查点运行时这可能会导致问题。

由于 IO 架构的变化(据我所知),较新的版本不会遇到此行为。

关于sql - 避免基于递增键创建聚集索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5302540/

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