Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  [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?

like image 313
Jakub Mach Avatar asked Aug 17 '11 14:08

Jakub Mach


People also ask

How do I find unindexed queries in MySQL without log?

In addition to a1ex07's answer you can use the shell command mk-query-digest to output a report of your running queries without using the log. Useful to fast detect unindexed queries.

What is Log_queries_not_using_indexes?

log_queries_not_using_indexes tells MySQL to additionally log all queries that do not use an index to limit the number of rows scanned.

What is MySQL slow query log?

The slow query log consists of SQL statements that take more than long_query_time seconds to execute and require at least min_examined_row_limit rows to be examined. The slow query log can be used to find queries that take a long time to execute and are therefore candidates for optimization.


1 Answers

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:

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”. 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.

like image 187
Dor Avatar answered Oct 11 '22 08:10

Dor