【问题标题】:Unable to duplicate slow query log rows_examined无法复制慢查询日志 rows_examined
【发布时间】:2011-05-06 19:15:54
【问题描述】:

我有一个查询,根据我的慢查询日志,它有点慢....

Query_time: 8.408943  Lock_time: 0.000119 Rows_sent: 1  Rows_examined: 2911766

但是,当我在其前面使用 EXPLAIN 运行查询时,我没有得到相同的结果...

id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY forum range PRIMARY PRIMARY 4 NULL 3 Using where; Using temporary; Using filesort
1 PRIMARY category ref PRIMARY,forum_id forum_id 4 source_forum.forum.id 2  
1 PRIMARY board ref PRIMARY,category_id category_id 4 source_forum.category.id 4 Using where
1 PRIMARY topic ref PRIMARY,board_id board_id 4 source_forum.board.id 58  
1 PRIMARY post ref PRIMARY,topic_id,trash topic_id 4 source_forum.topic.id 16 Using where
3 DEPENDENT SUBQUERY post index topic_id created 4 NULL 1 Using where
2 DEPENDENT SUBQUERY group_assoc ref board_id,group_id board_id 4 source_forum.board.id 4 Using where

使用的最高行数是 56...

更新

我的查询:

SELECT
   COUNT(id) AS num
FROM (
    SELECT topic.*,
      (SELECT created FROM post WHERE topic_id = topic.id ORDER BY created DESC LIMIT 1) AS lastpost
    FROM topic
    WHERE board_id = 6 AND
    NOT EXISTS( SELECT id FROM topic_read_assoc WHERE topic_id = topic.id AND member_id = 489 )            
    ) tab
WHERE last_post_time > 1288032259;

解释扩展

id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 440 100.00 Using where
2 DERIVED topic ref board_id board_id 4   429 100.00 Using where
4 DEPENDENT SUBQUERY topic_read_assoc ref topic_id,member_id topic_id 4 source_forum.topic.id 6 100.00 Using where
3 DEPENDENT SUBQUERY post index topic_id created 4 NULL 1 1600.00 Using where

过滤是什么意思?

【问题讨论】:

    标签: mysql optimization sql-execution-plan


    【解决方案1】:

    您也可以发布查询和SHOW CREATE TABLE 语句吗?

    58 确实不高,但是您使用的是临时表和文件排序。而且由于您的所有类型都是 ref 而不是 eq_ref,因此您必须将这些值相乘:3*2*4*58*16*1*4 = 89k 行加入(请参阅检查的行 - 某些表可能已被完全扫描 - 请参阅USING WHERE评论)

    你能发一个EXPLAIN EXTENDEDSHOW WARNINGS吗?

    【讨论】:

    • refeq_ref 有什么区别?
    猜你喜欢
    • 1970-01-01
    • 2014-05-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 2016-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多