这是一次冒险。我从位于 my previous question 的循环重复查询开始,但每个循环都会遍历所有 1700 万条记录,这意味着需要数周时间(仅运行 *select count * from MyTable*
需要我服务器 4:30 分钟,使用 MSSQL 2005)。我从这个网站和这个 post 上看到了信息.
并且已经到达下面的查询。问题是,对于任何类型的性能,这是在 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
关于SQL 对数百万行的性能重复删除查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/162325/