简体   繁体   English

如何在没有索引的情况下记录 mySQL 查询?

[英]How to log mySQL queries without indexes?

I see there is a nice option how to enable log slow queries and queries without indexes:我看到有一个很好的选择如何启用日志慢查询和没有索引的查询:

  SET GLOBAL log_queries_not_using_indexes=1;
  SET GLOBAL log_slow_queries=1;

OK, OK, but it seems both write in the same log file I have specified at my.cnf configuration file:好的,好的,但似乎都写入了我在 my.cnf 配置文件中指定的同一个日志文件:

  [mysqld]
  long_query_time         = 1
  log-slow-queries        = /var/log/mysql/mysql-slow.log

I use mysqldumpslow to see the slowest queries, but what I need to do to see separately that queries without indexes?我使用 mysqldumpslow 查看最慢的查询,但是我需要做什么才能单独查看没有索引的查询?

You can't.你不能。 The log file is a text file and you can't infer from it whether a query used an index at that time of execution.日志文件是一个文本文件,您无法从中推断查询在执行时是否使用了索引。 Also, the option log-queries-not-using-indexes doesn't necessarily log queries who aren't using an index, see :此外,选项log-queries-not-using-indexes不一定记录不使用索引的查询, 请参阅

If you are using this option with the slow query log enabled, queries that are expected to retrieve all rows are logged.如果您在启用慢查询日志的情况下使用此选项,则会记录预期检索所有行的查询。 See Section 5.2.5, “The Slow Query Log”.请参阅第 5.2.5 节,“慢查询日志”。 This option does not necessarily mean that no index is used.此选项不一定意味着不使用索引。 For example, a query that uses a full index scan uses an index but would be logged because the index would not limit the number of rows.例如,使用全索引扫描的查询使用索引但会被记录,因为索引不会限制行数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM