如果你可以幫助一個新手問題,我將不勝感激。我申請的SQL語句:簡單的MySQL選擇查詢需要4小時
INSERT INTO t03_hesid_history(uniqueID, hes_data_all_years.extract_hesid, FIELD1, FIELD2)
SELECT uniqueID, hes_data_all_years.extract_hesid, FIELD1, FIELD2
FROM hes_data_all_years
INNER JOIN T02_hesid_grouped
ON hes_data_all_years.extract_hesid = T02_hesid_grouped.extract_hesid;
的hes_data_all_years表擁有188萬條記錄和T02_hesid_grouped臺擁有8條記錄。 T02_hesid_grouped表具有一個名爲extract_hesid的單個(唯一)字段,該字段被索引。 hes_data_all_years在正在連接的extract_hesid字段上有許多字段和一個索引。
該查詢旨在提取heles_data_all_years中的所有記錄,並在T02_hesid_grouped字段中進行匹配。我期望輸出提供1-2米的記錄。
的查詢需要大約4小時...
是時間的長短因數據集大小或是否有可能進行一些優化?非常感謝!!
EXPLAIN outputon如下所示SELECT部分:
1 SIMPLE T02_hesid_grouped index I_HESID I_HESID 43 79824 Using index
1 SIMPLE hes_data_all_years ref I_HESID I_HESID 43 hes.T02_hesid_grouped.extract_hesid 1 Using where
請發佈查詢的選擇部分的'EXPLAIN'。 't03_hesid_history'是否有索引? –
謝謝 - 我已經添加了EXPLAIN輸出 – user2041216