6

i know this has been discussed already like anything but could not find a reliable answer i can go with.

Suppose i have a table with 10 billion records and need to delete records with identity column in where clause. which option should i go with?

option 1: disable the index which will save overhead to rearrange the index after deletion but will take longer time to search which row needs to deleted.

option 2: will not do anything with index which will locate the row very fast but rearrange the index can take some time.

i am more inclined towards the 2 option but want to see what will experts say? :)

4

3 回答 3

9

假设我有一个包含 100 亿条记录的表,并且需要在 where 子句中删除带有标识列的记录。我应该选择哪个选项?

如果要删除(或插入)超过 10% 的表(10 亿条记录),则应删除所有非聚集索引,删除记录,然后重建非聚集索引。

如果您要删除的表少于 10%,请保留索引。

您可以自由地进行性能测试,看看 10% 规则是否适用于您的 SQL Server 数据库引擎。

于 2013-06-05T14:35:47.013 回答
8

无论如何,“选项1”不是一个选项。

禁用聚集索引将使整个表无法访问,并且无论如何您都无法DELETE在表上运行 a 。它会失败

查询处理器无法生成计划,因为索引 ... 已禁用。

生成此错误的示例代码。

CREATE TABLE T(X INT CONSTRAINT PK PRIMARY KEY CLUSTERED, Y INT);

ALTER INDEX PK ON T DISABLE

DELETE FROM T
于 2013-06-05T14:32:40.053 回答
0

您通常会删除任何批量插入表的索引,这也是临时持续时间。完成批量插入后,将重新创建索引。

索引将有助于轻松定位记录以进行更新/删除操作,在这种情况下您永远不想删除它们。

HTH。

于 2013-06-05T14:30:52.593 回答