我有以下 3 个表:
出版物(主键 =文章)
article | title | pubType
作者(主键 = *author_name*)
author_name | author_somethingelse
pub_author_map
article | author_name
给定 的值pubType
,我需要选择有关文章的信息,包括作者。为此,我有
SELECT p.article, p.title, p.dateTime, pam.author_name FROM publications p
LEFT JOIN pub_author_map pam ON pam.article = p.article
LEFT JOIN authors a ON a.author_name = pam.author_name
WHERE p.pubType = '$pubType' ORDER BY p.article LIMIT 10
即使使用LIMIT 10
,此查询也大约在 29 秒内完成。中有 1500 行publications
和 3000 行pub_author_map
。
如何优化上述查询?