这是一次冒险。我从上一个问题中的循环重复查询开始,但是每个循环将遍历所有 1700万条记录 , 这意味着将花费数周的时间 (*select count * from MyTable*使用MSSQL 2005,运行服务器需要4:30分钟)。我从这个站点和这个帖子中闪现了信息。
*select count * from MyTable*
并已经到达下面的查询。问题是,对于任何类型的性能,这是否是对1700万条记录运行的正确查询类型?如果不是,那是什么?
SQL查询:
DELETE tl_acxiomimport.dbo.tblacxiomlistings WHERE RecordID in (SELECT RecordID FROM tl_acxiomimport.dbo.tblacxiomlistings EXCEPT SELECT RecordID FROM ( SELECT RecordID, Rank() over (Partition BY BusinessName, latitude, longitude, Phone ORDER BY webaddress DESC, caption1 DESC, caption2 DESC ) AS Rank FROM tl_acxiomimport.dbo.tblacxiomlistings ) al WHERE Rank = 1)
看到QueryPlan会有所帮助。
这可行吗?
SELECT m.* into #temp FROM tl_acxiomimport.dbo.tblacxiomlistings m inner join (SELECT RecordID, Rank() over (Partition BY BusinessName, latitude, longitude, Phone ORDER BY webaddress DESC, caption1 DESC, caption2 DESC ) AS Rank FROM tl_acxiomimport.dbo.tblacxiomlistings ) al on (al.RecordID = m.RecordID and al.Rank = 1) truncate table tl_acxiomimport.dbo.tblacxiomlistings insert into tl_acxiomimport.dbo.tblacxiomlistings select * from #temp