0

我有非常大的数据库表(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

我不知道如何减少数字。记录扫描..根本没有任何线索......如果任何数据库专家可以分享一些很棒的光线......(就像在子查询中使用 where 条件和上面查询中选择的列......)

先感谢您。

问候,莫娜

4

0 回答 0