gpt4 book ai didi

mysql - 查询优化

转载 作者:行者123 更新时间:2023-11-29 09:12:55 24 4
gpt4 key购买 nike

我安装的 WP 包含超过 50k 篇文章。有时,由于许多锁定的查询,网站速度会变慢。似乎某些代码正在启动像这样的疯狂查询

SELECT SQL_CALC_FOUND_ROWS  wp_posts.* 
FROM wp_posts
WHERE 1=1
AND wp_posts.ID NOT IN (43500, ... ))
AND wp_posts.ID NOT IN ( SELECT tr.object_id
FROM wp_term_relationships AS tr
INNER JOIN wp_term_taxonomy AS tt
ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN ('20207', '20788', '20789', '20790', '20791', '20792', '20793', '20794', '20795', '20796', '20797', '20798', '20799', '20800', '20801', '20802', '20803', '20804', '20805', '20806', '20807', '20808', '21012') )
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish')
ORDER BY wp_posts.post_date DESC LIMIT 0, 5

wp_posts ID NOT IN (...) 列表包含超过 5000 个 ID,这会导致非常漫长的查询。

这个查询从哪里来?我该如何改进它?

最佳答案

JOIN中使用的表中的外键中创建索引将提高性能

关于mysql - 查询优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5051371/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com