一 简单的命令
1 查看优化器状态
show variable like ‘optimizer_trace’;
2 会话级别临时开启
set session optimizer_trace=“enable=on”,end_markers_in_json=on;
3. 设置优化器追踪的内存大小
set OPTIMIZER_TRACE_MAX_MEM_SIZE=1000000;
4. 执行自己的SQL
select host,user,plugin from user;
5. information_schema.optimizer_trace表
SELECT trace FROM information_schema.OPTIMIZER_TRACE;
6. 导入到一个命名为xx.trace的文件,然后用JSON阅读器来查看
SELECT TRACE INTO DUMPFILE “/tmp/test.trace” FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;