大网数据广告活动
服务器运维问答

How to find joins performed without indexes?

· 52CE 我爱测

I run a WordPress website on Mariadb 10.6, and recently I saw an error Joins performed without indexes in Mysqltuner. Although the number is not very large, Mysqltuner recommends that you keep increasing the Key_buffer_size. Howe…

问题原文

原帖链接 · Junuk · CC BY-SA 4.0

I run a WordPress website on Mariadb 10.6, and recently I saw an error Joins performed without indexes in Mysqltuner.

Although the number is not very large, Mysqltuner recommends that you keep increasing the Key_buffer_size.

However, my VPS doesn't have a lot of free memory, so I'm solving this error with another issue.

Since I have about dozens of plugins active, I want to check which awesome plugin is causing the problem.

So, first of all, I enabled the error log as follows.

log-queries-not-using-indexes = 1
log_error = /var/log/mysql/mysql-error.log
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 3

And after a certain period of time, I ran pt-query-digest to analyze the error log.

pt-query-digest /var/log/mysql/mysql-slow.log

But I can't figure out any other problems.

Among the many queries in the slow log, how can you determine which one is trying to join with a column without an index?

I don't know the database, so I can't figure it out just by looking at the query.

已采纳解答

原帖链接 · Wilson Hauck · CC BY-SA 4.0

To FIND ONLY joins performed without indexes,

From MySQL Command Prompt, determine current values so you can return to normal after 1 hour of recording ONLY JPWI in your slow query log

SELECT @@long_query_time;
SELECT @@min_examined_row_limit;
      write down the above values
  
SET GLOBAL long_query_time=3600;  for a ONE MINUTE slow log trigger
SET GLOBAL min_examined_row_limit=1;   if the query reads one row, consider logging
SET GLOBAL log_queries_not_using_indexes=1;  to get the log you are needing

IN AN HOUR,

SET GLOBAL long_query_time=discovered above;
SET GLOBAL min_examined_row_limit=discovered above; 
SET GLOBAL log_queries_not_using_indexes=0;   # to turn OFF feature

FLUSH LOGS;

go review your last hour of Slow Query Log for the queries involved with no indexes.

View profile for contact info, get in touch, if you need additional advice, please.

Most people DO NOT record slow queries and queries without indexes to avoid separating the spaghetti. GET ONE or the OTHER, only to retain some form of sanity.

(fixed formatting, edit needs 6 characters)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-04-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。