Ole*_*nge 26 sql sql-server indexing bulkinsert
我尝试将数百万条记录插入到包含20个以上索引的表中.
在上一次运行中,每100,000行需要超过4小时,查询在3½天后被取消...
你对如何提高速度有什么建议吗?
(我怀疑很多索引都是原因.如果您也这么认为,如何在操作之前自动删除索引,然后再次创建相同的索引?)
额外信息:
状态更新:
接受的答案帮助我加快了速度.
Luc*_*ero 43
您可以禁用和启用索引.请注意,禁用它们可能会产生不必要的副作用(例如,具有重复的主键或唯一索引等),只有在重新启用索引时才会发现这些副作用.
--Disable Index
ALTER INDEX [IXYourIndex] ON YourTable DISABLE
GO
--Enable Index
ALTER INDEX [IXYourIndex] ON YourTable REBUILD
GO
Run Code Online (Sandbox Code Playgroud)
这听起来像数据仓库操作.在插入之前删除索引并在之后重建它们是正常的.
重建索引时,首先构建聚簇索引,然后相反地将其删除.他们应该都有100%的填充因子.
代码应该是这样的
if object_id('Index') is not null drop table IndexList
select name into Index from dbo.sysindexes where id = object_id('Fact')
if exists (select name from Index where name = 'id1') drop index Fact.id1
if exists (select name from Index where name = 'id2') drop index Fact.id2
if exists (select name from Index where name = 'id3') drop index Fact.id3
.
.
BIG INSERT
RECREATE THE INDEXES
Run Code Online (Sandbox Code Playgroud)