我有非常大的数据库表(MySQL innoDB)我正在查询下运行加入并试图以某种方式进行优化我无法做到更多我卡住了..
以下是我的查询
SELECT a.id, a.name, a.defvar, a.description, a.icon, a.thumb, a.average_rating, a.total_rating, c.rating, a.group_access, d.long_name, a.editor_id, e.users_count
FROM dir_cat_item AS b
INNER JOIN dir_item AS a ON a.id = b.item_id
AND a.status = 'O'
LEFT JOIN dir_item_notation_user_map AS c ON a.id = c.item_id
AND c.user_id =%u
LEFT JOIN users AS d ON d.id = a.editor_id
LEFT JOIN (SELECT item_id, COUNT(*) AS users_count
FROM module
GROUP BY item_id) AS e ON e.item_id = b.item_id
WHERE b.category_id=%u
ORDER BY e.users_count DESC
LIMIT 1,10
这里的问题是子查询正在扫描这些记录 383162 (解释查询)
SELECT item_id, COUNT(*) AS users_count
FROM module
GROUP BY item_id
我不知道如何减少号码。记录扫描..根本没有任何线索......如果任何数据库专家可以共享一些非常好的光...(比如使用子查询中的条件和上面查询中选择的列...)
提前谢谢。
此致 莫纳