我想在wordpress中優化以下查詢,因爲它需要將近一分半鐘才能返回結果。表關係表示如下圖:優化mysql查詢 - 許多內部聯接
SELECT SQL_CALC_FOUND_ROWS wp_posts . *
FROM wp_posts
INNER JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_term_relationships AS tt1
ON (wp_posts.ID = tt1.object_id)
INNER JOIN wp_term_relationships AS tt2
ON (wp_posts.ID = tt2.object_id)
INNER JOIN wp_term_relationships AS tt3
ON (wp_posts.ID = tt3.object_id)
INNER JOIN wp_term_relationships AS tt4
ON (wp_posts.ID = tt4.object_id)
WHERE 1 = 1
AND (
wp_term_relationships.term_taxonomy_id IN (25)
OR tt1.term_taxonomy_id IN (26)
OR tt2.term_taxonomy_id IN (16)
OR tt3.term_taxonomy_id IN (17)
OR tt4.term_taxonomy_id IN (18)
)
AND wp_posts.post_type IN ('product')
AND (wp_posts.post_status = 'publish')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_title ASC
LIMIT 0 , 15
我有困難,理解你正試圖在這裏實現什麼:
這裏將是修改後的查詢。也許你可以給我們提供一個最重要的實體的明確解釋和你試圖得到的結果? – Lukx