1.开启关闭
optimizer_trace 默认值:enabled=off, one_line=off enabled:是否开启 optimizer_trace;on表示开启,off表示关闭。 one_line:是否开启单行存储。on表示开启;off表示关闭。 end_markers_in_json OFF
2.使用
SET OPTIMIZER_TRACE="enabled=on"; select a.region from itpux_m5 a where exists (select * from itpux_sales b where a.cardid = b.cardid and a.recommend = '风哥'); SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE limit 30 \G; SET OPTIMIZER_TRACE="enabled=off";
3.阅读
#join_optimization展示了优化阶段的执行过程,是分析OPTIMIZER TRACE的重点 #condition_processing该段用来做条件处理,主要对WHERE条件进行优化处理。 #table_dependencies分析表之间的依赖关系 #ref_optimizer_key_uses列出所有可用的ref类型的索引 #rows_estimation用于估算需要扫描的记录数,单表查询重点关注。 #considered_execution_plans,多表关联重点关注 ,负责对比各可行计划的开销,并选择相对最优的执行计划。 #best_access_path:通过对比considered_access_paths,选择一个最优的访问路径 #considered_access_paths:当前考虑的访问路径
