/* 打开 optimizer_trace,只对本线程有效 */ 0: SET optimizer_trace="enabled=on"; /* @a 保存 Innodb_rows_read 的初始值 */ 1: SELECT VARIABLE_VALUE into @a from performance_schema.session_status where variable_name = 'Innodb_rows_read'; /* 执行语句 */ 2:SELECT * from titem where fname > 0 ORDER BY fname ; /* 查看 OPTIMIZER_TRACE 输出 此处有json*/ 3:SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; /* @b 保存 Innodb_rows_read 的当前值 */ 4:select VARIABLE_VALUE into @b from performance_schema.session_status where variable_name = 'Innodb_rows_read'; /* 计算 Innodb_rows_read 差值 */ 5:select @b-@a; SET optimizer_trace="enabled=off";
可以使用上面一段话来查询json
查出json后搜索关键字
number_of_tmp_files
如果有值
那便是使用了临时文件