求优化1
--Scanning 表现在有200万数据,每次插入大概8-10万条,每天插入一次,现在速度太慢了,要8分钟
insert into Scanning select JiaohNO,HangNO,Barcodes,HostNO,BatchNO,Sku,SkuName,CkDate,CkType,ShouDFName,Ckqty,null,CkUser,null,CCUser,null,Types from TEScanning
where not exists(select 1 from Scanning where Scanning.JiaohNO=TEScanning.JiaohNO) and CkType <>'B21'
--求优化2 查询一个月的数据,150万条数据,查询2分钟,怎么做索引!
select row_number()over(order by getdate()) as id,convert(char(10),CkDate,20),CCName,round(SUM(CkVolume),2),round(SUM(CkVolume* PerPrice.jsprice),2) from Scanning,PerPrice
where Scanning.Types=PerPrice.jstype and PerPrice.jsname='仓务工' and CkDate BETWEEN '2012-09-01 9:27:10' and '2012-10-01 9:27:10' group by convert(char(10),CkDate,20),CCName order by CCName,convert(char(10),CkDate,20)
Scanning.Types=PerPrice.jstype
这两个字段聚集索引下, CkDate非聚集索引下
Scanning.JiaohNO=TEScanning.JiaohNO 这两个字段聚集索引下,cktype 非聚集索引下
2.给计划吧。
然后waitfor 个十秒 然后在继续执行下一次插入避免产生太大的事务日志 才是关键。
ORDER BY CCName , CONVERT(CHAR(10) , CkDate , 20)改成
ORDER BY CCName , CkDate 然后这两个列上索引一下看看效果。
http://img.my.csdn.net/uploads/201210/25/1351154269_9292.jpg
http://img.my.csdn.net/uploads/201210/25/1351154269_8738.jpg
2.(SCANNING关联条件索引。)