插入块时插入开始的速度非常快(每秒1千次插入),但是随着时间的流逝,总共8百万条记录中的每3千次插入最多需要60-70秒。
有人知道我可以复查: 到目前为止,我们已经验证了自动增长 它检查磁盘级别,内存并处理任何增加的警报。 这是VM Ware虚拟服务器,Sql Server 2016 Enterprise。
能帮帮我,但我可以检查BDD,存储和服务器的所有配置。
table_data_tmp 800万个表标识(用于检索),并且包含索引 data_table_tmp1 800万 table_data_tmp1_2 300万记录 tabla_datos_fin 1900万30GB-在此处插入时插入时间很慢
附加脚本仅作为参考,因为已经确定在插入到最终表中是每次插入都要经过的地方
IF EXISTS (SELECT 1 FROM SYS.INDEXES WHERE OBJECT_ID = OBJECT_ID( 'tabla_datos_fin') AND NAME = 'IX_tabla_datos_fin_TIP_IDE_1' AND IS_DISABLED =0)
ALTER INDEX IX_tabla_datos_fin_TIP_IDE_1 ON tabla_datos_fin DISABLE;
GO
TRUNCATE TABLE tabla_datos_tmp
IF EXISTS (SELECT 1 FROM SYS.INDEXES WHERE OBJECT_ID = OBJECT_ID( 'IDX_tabla_datos_tmp') AND NAME = 'tabla_datos_tmp')
DROP INDEX tabla_datos_tmp.IDX_tabla_datos_tmp
GO
INSERT INTO tabla_datos_tmp (campos)
SELECT *
FROM [tabla_datos_tmp1]
CREATE INDEX IDX_tabla_datos_tmp ON tabla_datos_tmp (CONTROL_INT) INCLUDE (all campos)
DECLARE
@batchsize INT,
@ctr INT,
@rc INT,
@val_ini int,
@val_fin int
SELECT
@batchsize = 3000,
@ctr = 0;
WHILE 1 = 1
BEGIN
set @val_ini = @batchsize * @ctr
set @val_fin = @batchsize * (@ctr + 1)
truncate table tabla_datos_tmp1_2
INSERT INTO tabla_datos_tmp1_2
(all campos)
SELECT*
FROM tabla_datos_tmp WITH (INDEX =IDX_tabla_datos_tmp )
WHERE CONTROL_INT > @VAL_INI
AND CONTROL_INT <= @VAL_FIN
UPDATE tabla_datos_tmp1_2 SET FECHA_ULTIMA_ACTUALIZACION= GETDATE ()
/* INSERTION IS DELAYED HERE */
INSERT INTO tabla_datos_fin (al campos)
SELECT *
FROM tabla_datos_tmp1_2
/**********************/
DELETE A
FROM tabla_datos_tmp A WITH (INDEX =IDX_tabla_datos_tmp )
WHERE CONTROL_INT > @VAL_INI AND CONTROL_INT <= @VAL_FIN
IF @@ROWCOUNT = 0
BREAK;
SET @ctr = @ctr + 1;
PRINT @ctr
END
IF EXISTS (SELECT 1 FROM SYS.INDEXES WHERE OBJECT_ID = OBJECT_ID( 'tabla_datos_fin') AND NAME = 'IX_tabla_datos_fin' AND IS_DISABLED =1)
ALTER INDEX IX_tabla_datos_fin ON tabla_datos_fin REBUILD;
GO
IF EXISTS (SELECT 1 FROM SYS.INDEXES WHERE OBJECT_ID = OBJECT_ID( 'tabla_datos_fin') AND NAME = 'IX_tabla_datos_fin_TIP_IDE_1' AND IS_DISABLED =1)
ALTER INDEX IX_tabla_datos_fin_TIP_IDE_1 ON tabla_datos_fin REBUILD;
GO
答案 0 :(得分:0)
使用sql server等待统计信息来查看正在等待什么sql。找到这些之后,请深入研究其他性能计数器,直到找到问题为止。我的猜测是您的磁盘无法跟上。
https://www.sqlskills.com/blogs/paul/wait-statistics-or-please-tell-me-where-it-hurts/