我需要优化以下查询:
SELECT /* [things omitted] */ articles.blogpost_id, articles.id AS articleid
FROM blogposts
JOIN articles ON articles.blogpost_id = blogposts.id
WHERE blogposts.deleted = 0
AND blogposts.title LIKE '%{de}%'
AND blogposts.visible = 1
AND blogposts.date_published <= NOW()
ORDER BY blogposts.date_created DESC
LIMIT 0 , 50
Run Code Online (Sandbox Code Playgroud)
EXPLAIN SELECT 给我以下结果:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE articles ALL blogpost_id NULL NULL NULL 6915 Using temporary; Using filesort
1 SIMPLE blogposts eq_ref PRIMARY PRIMARY 4 articles.blogpost_id 1 Using where
Run Code Online (Sandbox Code Playgroud)
为什么它先是文章,然后是博客文章?是因为博客文章有更多条目吗?以及如何改进查询以便文章帖子可以使用索引? …