2009-09-18 36 views
0

我想優化我的Doublon檢查器,如果有人知道它可能會更快。如何優化sql doublelon檢查器

$doublonchecker="delete bad_rows.* from eMail as good_rows inner join eMail as bad_rows on bad_rows.EMAIL = good_rows.EMAIL and bad_rows.EMAIL_ID > good_rows.EMAIL_ID"; 
$resultdoublon = mysql_query($doublonchecker); 
     if (!$resultdoublon) { 
     die('Error : ' . mysql_error()); 
     } 

回答

2

我通常做下列方式:

Delete from Email where ID not in 
(
Select Min(em.ID) minID 
from eMail em group by em.Email 
) 
2

該查詢上(EMAIL)(EMAIL, EMAIL_ID)使用索引。但是,您不必多次運行該查詢,因此其性能不應該太擔心。刪除「Doublons」後,只需將(EMAIL)上的索引替換爲UNIQUE KEY,(EMAIL)即可,您永遠不會再有重複的電子郵件。