I created a query in which I insert to a empty table the result of a select from other table.
我创建了一个查询,在其中我向其他表中插入select的结果。
This select itself takes ~20 minutes (30 M Rows, 120 Columns and "Where" conditions, and it's fine), but the insert into takes ~1 hour.
这个选择本身需要大约20分钟(30 M行,120列和“Where”条件,并且它很好),但插入需要约1小时。
Do you have any suggestions of how to improve it?
您对如何改进有任何建议吗?
What I've done is as in the below example.
我所做的就像下面的例子。
Insert Into tableA
Select *
From TableB
Appreciate your help!
感谢你的帮助!
2 个解决方案
#1
2
Drop all the indexes on TableA
, then insert again :
删除TableA上的所有索引,然后再次插入:
INSERT INTO tableA
SELECT * FROM TableB
Indexes are known to slow down insert statements .
已知索引会降低插入语句的速度。
#2
0
Beneath the already mentioned indexes you could check if TableA has constraints defined (primary key, foreign key, etc.) since constraints are often implemented by indexes.
在已经提到的索引下面,您可以检查TableA是否定义了约束(主键,外键等),因为约束通常由索引实现。
Furthermore you could check if there are triggers on TableA. Another test would be to export/unload TableB to a file e.g. TableB.txt and then import/load the file TableB.txt into TableA. (Sorry I don't know the syntax for SQL Server).
此外,您可以检查TableA上是否有触发器。另一个测试是将TableB导出/卸载到文件,例如TableB.txt然后将文件TableB.txt导入/加载到TableA中。 (抱歉,我不知道SQL Server的语法)。
Another item to check may be the transaction log. Probably it is possible to change logging to BULK_LOGGED see: Disable Transaction Log
另一个要检查的项目可能是事务日志。可能可以将日志记录更改为BULK_LOGGED,请参阅:禁用事务日志
#1
2
Drop all the indexes on TableA
, then insert again :
删除TableA上的所有索引,然后再次插入:
INSERT INTO tableA
SELECT * FROM TableB
Indexes are known to slow down insert statements .
已知索引会降低插入语句的速度。
#2
0
Beneath the already mentioned indexes you could check if TableA has constraints defined (primary key, foreign key, etc.) since constraints are often implemented by indexes.
在已经提到的索引下面,您可以检查TableA是否定义了约束(主键,外键等),因为约束通常由索引实现。
Furthermore you could check if there are triggers on TableA. Another test would be to export/unload TableB to a file e.g. TableB.txt and then import/load the file TableB.txt into TableA. (Sorry I don't know the syntax for SQL Server).
此外,您可以检查TableA上是否有触发器。另一个测试是将TableB导出/卸载到文件,例如TableB.txt然后将文件TableB.txt导入/加载到TableA中。 (抱歉,我不知道SQL Server的语法)。
Another item to check may be the transaction log. Probably it is possible to change logging to BULK_LOGGED see: Disable Transaction Log
另一个要检查的项目可能是事务日志。可能可以将日志记录更改为BULK_LOGGED,请参阅:禁用事务日志