【问题标题】:Why does mysql slow log reports these non-slow queries为什么mysql慢日志会报告这些非慢查询
【发布时间】:2012-07-27 22:36:04
【问题描述】:

我的 mysql 服务器配置了 long_query_time = 2,但我仍然在慢查询日志中看到这些查询报告,看起来很快:

# Time: 120730  5:06:41
# User@Host: <user> @ <Host> [<IP>] 
# Query_time: 0.000412  Lock_time: 0.000060 Rows_sent: 5  Rows_examined: 5
SET timestamp=1343639201;
SELECT album_id FROM `TB_albums` where album_id!='res_4fe4333271bda7.42833845' and deleted is NULL order by `created_time` desc limit 5;

如您所见 Query_time: 0.000412 Lock_time: 0.000060 似乎远低于 2 秒

您知道为什么会报告这些“快速”查询吗?

【问题讨论】:

  • 您检查变量 log_queries_not_using_indexes 了吗?
  • @Omesh - 检查,这正是问题所在,我想知道我可以在这里索引什么???

标签: mysql mysql-slow-query-log


【解决方案1】:

MySQL 还记录不使用索引的查询

my.cnf 中的选项log-queries-not-using-indexes 用于控制这一点。从 my.cnf 的这个 sn-p 可以看出,我的已关闭(通过注释掉)


# Here you can see queries with especially long duration
log_slow_queries        = /var/log/mysql/mysql-slow.log
long_query_time = 2
#log-queries-not-using-indexes


如果您无权访问 my.cnf,则可以使用 SQL 进行检查


mysql> show variables like 'log_queries_not_using_indexes';
+-------------------------------+-------+
| Variable_name                 | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | OFF   |
+-------------------------------+-------+
1 row in set (0.00 sec)



希望对您有所帮助!

克里斯

【讨论】:

    【解决方案2】:

    检查变量log-queries-not-using-indexes

    show variables like '%log_queries_not_using_indexes%';
    +-------------------------------+-------+
    | Variable_name                 | Value |
    +-------------------------------+-------+
    | log_queries_not_using_indexes | OFF   | 
    +-------------------------------+-------+
    

    对于您的情况,它必须设置为 OFF,如果为 ON,那么您可以在 my.cnf 文件中设置 log_queries_not_using_indexes = OFF,然后重新启动 MySQL 服务器。

    【讨论】:

      【解决方案3】:

      manual,您需要检查与将查询写入显示查询日志相关的其他配置。

      服务器按以下顺序使用控制参数来确定是否将查询写入慢查询日志:

      1.查询不能是管理语句,或者 --log-slow-admin-statements 必须已指定。

      2.查询必须至少花费 long_query_time 秒,或者必须启用 log_queries_not_using_indexes 并且查询未使用 行查找的索引。

      3.查询必须至少检查了 min_examined_row_limit 行。

      4. 根据 log_throttle_queries_not_using_indexes 设置,查询不能被抑制。

      【讨论】:

        【解决方案4】:

        AFAIK MySQL 测量从查询提交到获取阶段结束的数据获取查询的查询时间。这意味着,类似于

        Start timer
        Start fast SELECT query
        Wait for result 
        Check timer and note time
        sleep 2 seconds
        fetch query results
        Stop timer
        

        会以noted time&lt;2send time&gt;2s告终,并且慢查询日志触发时间更长。

        【讨论】:

          猜你喜欢
          • 2012-06-01
          • 2013-07-09
          • 1970-01-01
          • 1970-01-01
          • 2011-03-07
          • 1970-01-01
          • 1970-01-01
          • 2013-06-28
          • 1970-01-01
          相关资源
          最近更新 更多