小编典典

SQL对数百万行重复删除查询以提高性能

sql

这是一次冒险。我从上一个问题中的循环重复查询开始,但是每个循环将遍历所有
1700万条记录这意味着将花费数周的时间*select count * from MyTable*使用MSSQL
2005,运行服务器需要4:30分钟)。我从这个站点和这个帖子中闪现了信息。

并已经到达下面的查询。问题是,对于任何类型的性能,这是否是对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)

阅读 138

收藏
2021-04-28

共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
2021-04-28