1
進行解釋其對一個查詢之後:在聯合查詢的MySQL解釋
explain
select name from t1 where name like '%smthing%'
UNION ALL
select name from t2 where name like '%smthing%'
UNION ALL
select name from t3 where name like '%smthing%'
UNION ALL
select name from t4 where name like '%smthing%'
通過的4代表的UNION由我得到這樣的:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index (NULL) name 152 (NULL) 337 Using where; Using index
2 UNION t2 index (NULL) name 152 (NULL) 3842 Using where; Using index
3 UNION t3 index (NULL) name 452 (NULL) 204 Using where; Using index
4 UNION t4 index (NULL) name 452 (NULL) 8269 Using where; Using index
(NULL) UNION RESULT <union1,2,3,4> ALL (NULL) (NULL) (NULL) (NULL) (NULL)
當聯合的各成分進行說明,類型是「INDEX」,但是聯合結果的類型是「ALL」。 這是什麼原因導致這種行爲? 謝謝
也許你可以粘貼你的查詢,並在問題中解釋計劃的結果? – Avi 2009-04-27 12:36:35