我需要一些幫助來優化查詢。我有一個查詢需要花費很長時間才能運行12s,如果我可以在優化它的時候獲得一些幫助,我會非常喜歡,因爲我不是sql專家。在這裏它是:優化內部聯接
SELECT ID ,
user_login ,
user_nicename ,
user_registered ,
user_status ,
display_name ,
t1.meta_value AS account_type ,
1 t2.meta_value AS views ,
GROUP_CONCAT(t4.term_id) AS interests_skills,
GROUP_CONCAT(t4.taxonomy) AS taxonomyComb ,
t4.term_id ,
t4.taxonomy
FROM wp_users
INNER JOIN wp_usermeta AS t1
ON (
t1.user_id = wp_users.ID
AND
(
t1.meta_key = 'account_type'
AND t1.meta_value = 'individual'
)
)
LEFT JOIN wp_usermeta AS t2
ON (
t2.user_id = wp_users.ID
AND t2.meta_key = 'views'
)
LEFT JOIN wp_term_relationships AS t3
ON (
t3.object_id = (1000000+wp_users.ID)
)
INNER JOIN wp_term_taxonomy AS t4
ON (
(
t3.term_taxonomy_id = t4.`term_taxonomy_id`
AND t4.taxonomy = 'category'
AND t4.term_id IN (396,410,411,416,142,417)
)
OR
(
t3.term_taxonomy_id = t4.`term_taxonomy_id`
AND t4.taxonomy = 'skill'
AND t4.term_id IN (461,463,464,466,490,468,470,491,473,474,475)
)
)
WHERE t4.term_id IS NOT NULL
GROUP BY ID LIMIT 0,10
這裏是解釋
1 SIMPLE T4範圍PRIMARY,term_id_taxonomy,分類term_id_taxonomy 106 NULL 17使用其中;使用臨時;使用文件排序
1 SIMPLE T1 REF USER_ID,meta_key meta_key 768常量3773使用其中
1個SIMPLE wp_users eq_ref PRIMARY PRIMARY 8 jasper_gi.t1.user_id 1
1 SIMPLE T2 REF USER_ID,meta_key meta_key 768常量2
1 SIMPLE T3 eq_ref PRIMARY,term_taxonomy_id PRIMARY 16 FUNC,jasper_gi.t4.term_taxonomy_id 1使用其中;使用索引
我修正了查詢格式。查看編輯歷史記錄,如果您沒有,我可能會無意中刪除了一個句子!請檢查並根據需要重新添加。 – 2010-12-08 14:16:14