此查詢需要很長時間才能在具有70GB數據的MS Sql 2008 DB上運行。 如果我單獨運行2 where子句,則需要很多時間。有沒有辦法讓這個查詢更高效的性能?
編輯 - 之後我需要將'select *'更改爲'delete',請在回答時記住它。謝謝:)
select *
From computers
Where Name in
(
select T2.Name
from
(
select Name
from computers
group by Name
having COUNT(*) > 1
) T3
join computers T2 on T3.Name = T2.Name
left join policyassociations PA on T2.PK = PA.EntityId
where (T2.EncryptionStatus = 0 or T2.EncryptionStatus is NULL) and
(PA.EntityType <> 1 or PA.EntityType is NULL)
)
OR
ClientId in
(
select substring(ClientID,11,100)
from computers
)
用存在(子查詢)替換IN(子查詢)(t2和t3從未被外部查詢引用,並且t2和t3具有相同的用途,它們的產品是笛卡爾積。) – wildplasser