我正在尝试在 wordpress 中优化以下查询,因为返回结果需要将近一分半钟。表关系如下图所示:
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