2011-05-11 131 views
1

我在表中有50964218條記錄。我將從此表中獲取數據並插入到同一個表中。這需要更多時間來操縱。如何優化此查詢。查詢優化

查詢是

INSERT INTO contacts_lists (contact_id, list_id, is_excluded, added_by_search) 
SELECT contact_id, 68114 , TRUE, added_by_search 
FROM contacts_lists cl1 
WHERE list_id = 67579 
AND is_excluded = TRUE 
AND NOT EXISTS 
    (SELECT 1 FROM contacts_lists cl2 
    WHERE cl1.contact_id = cl2.contact_id AND cl2.list_id = 68114) 

指數:LIST_ID,CONTACT_ID

+0

你能告訴我們從解釋結果?沒有解釋它幾乎不可能幫助你。 – 2011-05-11 16:49:25

回答

1

你可能會得到一個左更好的效果加入:

select t1.[field], ... 
from t1 
left join t2 
on [conditions] 
where t2.[any pkey field] is null; 
+0

謝謝,我會試試看。 – Rafiu 2011-05-13 06:00:02