查看优化器状态
show variables like 'optimizer_trace';
会话级别临时开启
set session optimizer_trace="enabled=on",end_markers_in_json=on;
设置优化器追踪的内存大小
set OPTIMIZER_TRACE_MAX_MEM_SIZE=1000000;
执行自己的SQL
select * from user;
information_schema.optimizer_trace表
SELECT trace FROM information_schema.OPTIMIZER_TRACE;
导入到一个命名为test.trace的文件
SELECT TRACE INTO DUMPFILE "D:\\test.trace" FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
不设置优化器最大容量的话,可能会导致优化器返回的结果不全。