我有一个使用自我联接编写的查询。该表有约360万行,需要几个小时才能运行。
update m
SET
[ChildGlobalFamilyUnique] = [ParentGlobalFamilyUnique],
[ChildGlobalFamilyDupID] = [ParentGlobalFamilyDupId],
[ChildCustodianFamilyUnique] = [ParentCustodianFamilyUnique],
ChildCustodainFamilyDupId = ParentCustodianFamilyDupID
from(
select
child.DupGroupIdentifier
child.NuixGuid [ChildGuid],
child.toplvlguid [ChildTopLevelGuid],
parent.[IsGlobalFamilyUnique] [ParentGlobalFamilyUnique],
child.IsGlobalFamilyUnique [ChildGlobalFamilyUnique] ,
parent.GlobalFamilyDupID [ParentGlobalFamilyDupId],
child.GlobalFamilyDupID [ChildGlobalFamilyDupID],
child.CustodianFamilyDupID [ChildCustodainFamilyDupId],
child.IsCustodianFamilyUnique [ChildCustodianFamilyUnique],
parent.CustodianFamilyDupID [ParentCustodianFamilyDupID],
parent.IsCustodianFamilyUnique [ParentCustodianFamilyUnique]
from [EDDS1029171_master].dbo.tblMaster parent
inner join [EDDS1029171_master].dbo.tblMaster child
on child.DupGroupIdentifier = parent.DupeIdentifier
where child.IsCustodianFamilyUnique is null AND child.IsglobalFamilyUnique is null and child.IsChild = 1
AND parent.IsglobalFamilyUnique is not null AND parent.IsCustodianFamilyUnique is not null and parent.ischild = 0
)m
我在DupGroupIdentifier
和DupeIdentifier
上有一个非聚集索引。
如何重新编写以上代码,从而避免使用自连接并最终使查询停止运行数小时?