[英]Optimize slow update query
I have two tables: 我有两个表:
1) Testone - has 100k rows and 1 Index and 6 NON-Clustered index 1) Testone-具有10万行,1个索引和6个非聚集索引
2) Testtwo - has 316 Million rows, 1 Index and 4 NON-Clustered index 2) Testtwo-具有3.16亿行,1个索引和4个非聚集索引
I have update statement need to optimize the following one due to taking more time when executing this query, could you please help me the best approach.. 由于执行此查询需要更多时间,我有更新语句需要优化以下语句,请您帮我最好的方法。
update mp
set mp.ModelInfoID = mi.ModelInfoID
from Testone mp
inner join Testtwo mi on mp.ModelNumberStr = replace(replace(mi.Model, '/', ''), '-', '')
where MemberID is not null and mp.ModelInfoID is null
start with just optimizing this 从优化这个开始
look at the query plan 看一下查询计划
index on MemberID, mp.ModelInfoID, and mi.ModelInfoID will help 关于MemberID,mp.ModelInfoID和mi.ModelInfoID的索引将有帮助
select mp.ModelInfoID, mi.ModelInfoID
from Testone mp
join Testtwo mi
on mp.ModelNumberStr = replace(replace(mi.Model, '/', ''), '-', '')
and MemberID is not null
and mp.ModelInfoID is null
and mi.ModelInfoID is not null -- no need to update if they are the same
Cleary the replace(replace(mi.Model, '/', ''), '-', '') is going to be the bottle neck. 显然,replace(replace(mi.Model,'/',''),'-','')将成为瓶颈。 A computed column with an index may do the trick. 具有索引的计算列可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.