当前位置:   article > 正文

MySQL 调优 | OPTIMIZER_TRACE 详解

mysql 8 optimize trace 分析

点击上方 IT牧场 ,选择 置顶或者星标技术干货每日送达!

TIPS

本文基于MySQL 8.0编写,理论支持MySQL 5.6及更高版本。

OPTIMIZER_TRACE是MySQL 5.6引入的一项跟踪功能,它可以跟踪优化器做出的各种决策(比如访问表的方法、各种开销计算、各种转换等),并将跟踪结果记录到 INFORMATION_SCHEMA.OPTIMIZER_TRACE 表中。此功能默认关闭,开启后,可分析如下语句:

•SELECT•INSERT•REPLACE•UPDATE•DELETE•EXPLAIN•SET•DECLARE•CASE•IF•RETURN•CALL

OPTIMIZER_TRACE相关参数

TIPS

参考 https://dev.mysql.com/doc/internals/en/system-variables-controlling-trace.html[1]

optimizer_trace

•optimizer_trace总开关,默认值:enabled=off,one_line=off•enabled:是否开启optimizer_trace;on表示开启,off表示关闭。•one_line:是否开启单行存储。on表示开启;off表示关闭,将会用标准的JSON格式化存储。设置成on将会有良好的格式,设置成off可节省一些空间。

optimizer_trace_features

•控制optimizer_trace跟踪的内容,默认值:greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on ,表示开启所有跟踪项。

greedy_search:是否跟踪贪心搜索,有关贪心算法详见 https://blog.csdn.net/weixin_42813521/article/details/105563103[2]

•range_optimizer:是否跟踪范围优化器

dynamic_range:是否跟踪动态范围优化

•repeated_subselect:是否跟踪子查询,如果设置成off,只跟踪第一条Item_subselect的执行

详见 https://dev.mysql.com/doc/internals/en/optimizer-features-to-trace.html[3]

optimizer_trace_limit:控制optimizer_trace展示多少条结果,默认1

optimizer_trace_max_mem_size:optimizer_trace堆栈信息允许的最大内存,默认1048576

optimizer_trace_offset:第一个要展示的optimizer trace的偏移量,默认-1。

end_markers_in_json:如果JSON结构很大,则很难将右括号和左括号配对。为了帮助读者阅读,可将其设置成on,这样会在右括号附近加上注释,默认off。

参考: https://dev.mysql.com/doc/internals/en/end-markers-in-json-system-variable.html[4]

TIPS

以上参数可用SET语句操作,例如,用如下命令即可打开OPTIMIZER TRACE

SET OPTIMIZER_TRACE="enabled=on",END_MARKERS_IN_JSON=on;

也可用SET GLOBAL全局开启。但即使全局开启OPTIMIZER_TRACE,每个Session也只能跟踪它自己执行的语句:

SET GLOBAL OPTIMIZER_TRACE="enabled=on",END_MARKERS_IN_JSON=on;

optimizer_trace_limit和optimizer_trace_offset这两个参数经常配合使用,例如:

SET optimizer_trace_offset=<OFFSET>, optimizer_trace_limit=<LIMIT>

这两个参数配合使用,有点类似MySQL里面的 limit语句。

默认情况下,由于optimizer_trace_offset=-1,optimizer_trace_limit=1,记录最近的一条SQL语句,展示时,每次展示1条数据;

如果改成 SET optimizer_trace_offset=-2, optimizer_trace_limit=1 ,则会记录倒数第二条SQL语句;

有关 optimizer_trace_offset 、optimizer_trace_limit更多细节,可参考 https://dev.mysql.com/doc/internals/en/tuning-trace-purging.html[5]

OPTIMIZER_TRACE使用

开启OPTIMIZER_TRACE功能,并设置要展示的数据条目数:

  1. SET OPTIMIZER_TRACE="enabled=on",END_MARKERS_IN_JSON=on;
  2. SET optimizer_trace_offset=-30, optimizer_trace_limit=30;

发送你想要分析的SQL语句,例如:

  1. select *
  2. from salaries
  3. where from_date = '1986-06-26'
  4. and to_date = '1987-06-26';

使用如下语句分析,即可获得类似如下的结果:

  1. mysql> SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE limit 30 \G;
  2. *************************** 1. row ***************************
  3. QUERY: select *
  4. from salaries
  5. where from_date = '1986-06-26'
  6. and to_date = '1987-06-26'
  7. TRACE: {
  8. "steps": [
  9. {
  10. "join_preparation": {
  11. "select#": 1,
  12. "steps": [
  13. {
  14. "expanded_query": "/* select#1 */ select `salaries`.`emp_no` AS `emp_no`,`salaries`.`salary` AS `salary`,`salaries`.`from_date` AS `from_date`,`salaries`.`to_date` AS `to_date` from `salaries` where ((`salaries`.`from_date` = '1986-06-26') and (`salaries`.`to_date` = '1987-06-26'))"
  15. }
  16. ] /* steps */
  17. } /* join_preparation */
  18. },
  19. {
  20. "join_optimization": {
  21. "select#": 1,
  22. "steps": [
  23. {
  24. "condition_processing": {
  25. "condition": "WHERE",
  26. "original_condition": "((`salaries`.`from_date` = '1986-06-26') and (`salaries`.`to_date` = '1987-06-26'))",
  27. "steps": [
  28. {
  29. "transformation": "equality_propagation",
  30. "resulting_condition": "(multiple equal('1986-06-26', `salaries`.`from_date`) and multiple equal('1987-06-26', `salaries`.`to_date`))"
  31. },
  32. {
  33. "transformation": "constant_propagation",
  34. "resulting_condition": "(multiple equal('1986-06-26', `salaries`.`from_date`) and multiple equal('1987-06-26', `salaries`.`to_date`))"
  35. },
  36. {
  37. "transformation": "trivial_condition_removal",
  38. "resulting_condition": "(multiple equal(DATE'1986-06-26', `salaries`.`from_date`) and multiple equal(DATE'1987-06-26', `salaries`.`to_date`))"
  39. }
  40. ] /* steps */
  41. } /* condition_processing */
  42. },
  43. {
  44. "substitute_generated_columns": {
  45. } /* substitute_generated_columns */
  46. },
  47. {
  48. "table_dependencies": [
  49. {
  50. "table": "`salaries`",
  51. "row_may_be_null": false,
  52. "map_bit": 0,
  53. "depends_on_map_bits": [
  54. ] /* depends_on_map_bits */
  55. }
  56. ] /* table_dependencies */
  57. },
  58. {
  59. "ref_optimizer_key_uses": [
  60. {
  61. "table": "`salaries`",
  62. "field": "from_date",
  63. "equals": "DATE'1986-06-26'",
  64. "null_rejecting": false
  65. },
  66. {
  67. "table": "`salaries`",
  68. "field": "to_date",
  69. "equals": "DATE'1987-06-26'",
  70. "null_rejecting": false
  71. }
  72. ] /* ref_optimizer_key_uses */
  73. },
  74. {
  75. "rows_estimation": [
  76. {
  77. "table": "`salaries`",
  78. "range_analysis": {
  79. "table_scan": {
  80. "rows": 2838216,
  81. "cost": 286799
  82. } /* table_scan */,
  83. "potential_range_indexes": [
  84. {
  85. "index": "PRIMARY",
  86. "usable": false,
  87. "cause": "not_applicable"
  88. },
  89. {
  90. "index": "salaries_from_date_to_date_index",
  91. "usable": true,
  92. "key_parts": [
  93. "from_date",
  94. "to_date",
  95. "emp_no"
  96. ] /* key_parts */
  97. }
  98. ] /* potential_range_indexes */,
  99. "setup_range_conditions": [
  100. ] /* setup_range_conditions */,
  101. "group_index_range": {
  102. "chosen": false,
  103. "cause": "not_group_by_or_distinct"
  104. } /* group_index_range */,
  105. "skip_scan_range": {
  106. "potential_skip_scan_indexes": [
  107. {
  108. "index": "salaries_from_date_to_date_index",
  109. "usable": false,
  110. "cause": "query_references_nonkey_column"
  111. }
  112. ] /* potential_skip_scan_indexes */
  113. } /* skip_scan_range */,
  114. "analyzing_range_alternatives": {
  115. "range_scan_alternatives": [
  116. {
  117. "index": "salaries_from_date_to_date_index",
  118. "ranges": [
  119. "0xda840f <= from_date <= 0xda840f AND 0xda860f <= to_date <= 0xda860f"
  120. ] /* ranges */,
  121. "index_dives_for_eq_ranges": true,
  122. "rowid_ordered": true,
  123. "using_mrr": false,
  124. "index_only": false,
  125. "rows": 86,
  126. "cost": 50.909,
  127. "chosen": true
  128. }
  129. ] /* range_scan_alternatives */,
  130. "analyzing_roworder_intersect": {
  131. "usable": false,
  132. "cause": "too_few_roworder_scans"
  133. } /* analyzing_roworder_intersect */
  134. } /* analyzing_range_alternatives */,
  135. "chosen_range_access_summary": {
  136. "range_access_plan": {
  137. "type": "range_scan",
  138. "index": "salaries_from_date_to_date_index",
  139. "rows": 86,
  140. "ranges": [
  141. "0xda840f <= from_date <= 0xda840f AND 0xda860f <= to_date <= 0xda860f"
  142. ] /* ranges */
  143. } /* range_access_plan */,
  144. "rows_for_plan": 86,
  145. "cost_for_plan": 50.909,
  146. "chosen": true
  147. } /* chosen_range_access_summary */
  148. } /* range_analysis */
  149. }
  150. ] /* rows_estimation */
  151. },
  152. {
  153. "considered_execution_plans": [
  154. {
  155. "plan_prefix": [
  156. ] /* plan_prefix */,
  157. "table": "`salaries`",
  158. "best_access_path": {
  159. "considered_access_paths": [
  160. {
  161. "access_type": "ref",
  162. "index": "salaries_from_date_to_date_index",
  163. "rows": 86,
  164. "cost": 50.412,
  165. "chosen": true
  166. },
  167. {
  168. "access_type": "range",
  169. "range_details": {
  170. "used_index": "salaries_from_date_to_date_index"
  171. } /* range_details */,
  172. "chosen": false,
  173. "cause": "heuristic_index_cheaper"
  174. }
  175. ] /* considered_access_paths */
  176. } /* best_access_path */,
  177. "condition_filtering_pct": 100,
  178. "rows_for_plan": 86,
  179. "cost_for_plan": 50.412,
  180. "chosen": true
  181. }
  182. ] /* considered_execution_plans */
  183. },
  184. {
  185. "attaching_conditions_to_tables": {
  186. "original_condition": "((`salaries`.`to_date` = DATE'1987-06-26') and (`salaries`.`from_date` = DATE'1986-06-26'))",
  187. "attached_conditions_computation": [
  188. ] /* attached_conditions_computation */,
  189. "attached_conditions_summary": [
  190. {
  191. "table": "`salaries`",
  192. "attached": "((`salaries`.`to_date` = DATE'1987-06-26') and (`salaries`.`from_date` = DATE'1986-06-26'))"
  193. }
  194. ] /* attached_conditions_summary */
  195. } /* attaching_conditions_to_tables */
  196. },
  197. {
  198. "finalizing_table_conditions": [
  199. {
  200. "table": "`salaries`",
  201. "original_table_condition": "((`salaries`.`to_date` = DATE'1987-06-26') and (`salaries`.`from_date` = DATE'1986-06-26'))",
  202. "final_table_condition ": null
  203. }
  204. ] /* finalizing_table_conditions */
  205. },
  206. {
  207. "refine_plan": [
  208. {
  209. "table": "`salaries`"
  210. }
  211. ] /* refine_plan */
  212. }
  213. ] /* steps */
  214. } /* join_optimization */
  215. },
  216. {
  217. "join_execution": {
  218. "select#": 1,
  219. "steps": [
  220. ] /* steps */
  221. } /* join_execution */
  222. }
  223. ] /* steps */
  224. }
  225. MISSING_BYTES_BEYOND_MAX_MEM_SIZE: 0
  226. INSUFFICIENT_PRIVILEGES: 0
  227. 1 row in set (0.00 sec)

分析完成,关闭OPTIMIZER_TRACE

SET optimizer_trace="enabled=off";

OPTIMIZER_TRACE结果分析

由上面的结果可知,OPTIMIZER_TRACE有四个字段:

•QUERY:查询语句•TRACE:QUERY字段对应语句的跟踪信息•MISSING_BYTES_BEYOND_MAX_MEM_SIZE:跟踪信息过长时,被截断的跟踪信息的字节数。•INSUFFICIENT_PRIVILEGES:执行跟踪语句的用户是否有查看对象的权限。当不具有权限时,该列信息为1且TRACE字段为空,一般在调用带有SQL SECURITY DEFINER的视图或者是存储过程的情况下,会出现此问题。

TIPS

参考: https://dev.mysql.com/doc/refman/8.0/en/optimizer-trace-table.html[6]

最核心的是TRACE字段的内容。我们逐段分析:

join_preparation

join_preparation段落展示了准备阶段的执行过程。

  1. {
  2. "join_preparation": {
  3. "select#": 1,
  4. "steps": [
  5. {
  6. -- 对比下原始语句,可以知道,这一步做了个格式化。
  7. "expanded_query": "/* select#1 */ select `salaries`.`emp_no` AS `emp_no`,`salaries`.`salary` AS `salary`,`salaries`.`from_date` AS `from_date`,`salaries`.`to_date` AS `to_date` from `salaries` where ((`salaries`.`from_date` = '1986-06-26') and (`salaries`.`to_date` = '1987-06-26'))"
  8. }
  9. ]
  10. /* steps */
  11. }
  12. /* join_preparation */
  13. }

join_optimization

join_optimization展示了优化阶段的执行过程,是分析OPTIMIZER TRACE的重点。这段内容超级长,而且分了好多步骤,不妨按照步骤逐段分析:

condition_processing

该段用来做条件处理,主要对WHERE条件进行优化处理。

  1. "condition_processing": {
  2. "condition": "WHERE",
  3. "original_condition": "((`salaries`.`from_date` = '1986-06-26') and (`salaries`.`to_date` = '1987-06-26'))",
  4. "steps": [
  5. {
  6. "transformation": "equality_propagation",
  7. "resulting_condition": "(multiple equal('1986-06-26', `salaries`.`from_date`) and multiple equal('1987-06-26', `salaries`.`to_date`))"
  8. },
  9. {
  10. "transformation": "constant_propagation",
  11. "resulting_condition": "(multiple equal('1986-06-26', `salaries`.`from_date`) and multiple equal('1987-06-26', `salaries`.`to_date`))"
  12. },
  13. {
  14. "transformation": "trivial_condition_removal",
  15. "resulting_condition": "(multiple equal(DATE'1986-06-26', `salaries`.`from_date`) and multiple equal(DATE'1987-06-26', `salaries`.`to_date`))"
  16. }
  17. ] /* steps */
  18. } /* condition_processing */

其中:

•condition:优化对象类型。WHERE条件句或者是HAVING条件句•original_condition:优化前的原始语句•steps:主要包括三步,分别是quality_propagation(等值条件句转换),constant_propagation(常量条件句转换),trivial_condition_removal(无效条件移除的转换)

•transformation:转换类型句•resulting_condition:转换之后的结果输出

substitute_generated_columns

substitute_generated_columns用于替换虚拟生成列

  1. "substitute_generated_columns": {
  2. } /* substitute_generated_columns */

table_dependencies

分析表之间的依赖关系

  1. {
  2. "table_dependencies": [
  3. {
  4. "table": "`salaries`",
  5. "row_may_be_null": false,
  6. "map_bit": 0,
  7. "depends_on_map_bits": [
  8. ] /* depends_on_map_bits */
  9. }
  10. ] /* table_dependencies */
  11. }

其中:

•table:涉及的表名,如果有别名,也会展示出来•row_may_be_null:行是否可能为NULL,这里是指JOIN操作之后,这张表里的数据是不是可能为NULL。如果语句中使用了LEFT JOIN,则后一张表的row_may_be_null会显示为true•map_bit:表的映射编号,从0开始递增•depends_on_map_bits:依赖的映射表。主要是当使用STRAIGHT_JOIN强行控制连接顺序或者LEFT JOIN/RIGHT JOIN有顺序差别时,会在depends_on_map_bits中展示前置表的map_bit值。

ref_optimizer_key_uses

列出所有可用的ref类型的索引。如果使用了组合索引的多个部分(例如本例,用到了index(from_date, to_date) 的多列索引),则会在ref_optimizer_key_uses下列出多个元素,每个元素中会列出ref使用的索引及对应值。

  1. {
  2. "ref_optimizer_key_uses": [
  3. {
  4. "table": "`salaries`",
  5. "field": "from_date",
  6. "equals": "DATE'1986-06-26'",
  7. "null_rejecting": false
  8. },
  9. {
  10. "table": "`salaries`",
  11. "field": "to_date",
  12. "equals": "DATE'1987-06-26'",
  13. "null_rejecting": false
  14. }
  15. ] /* ref_optimizer_key_uses */
  16. }

rows_estimation

顾名思义,用于估算需要扫描的记录数。

  1. {
  2. "rows_estimation": [
  3. {
  4. "table": "`salaries`",
  5. "range_analysis": {
  6. "table_scan": {
  7. "rows": 2838216,
  8. "cost": 286799
  9. } /* table_scan */,
  10. "potential_range_indexes": [
  11. {
  12. "index": "PRIMARY",
  13. "usable": false,
  14. "cause": "not_applicable"
  15. },
  16. {
  17. "index": "salaries_from_date_to_date_index",
  18. "usable": true,
  19. "key_parts": [
  20. "from_date",
  21. "to_date",
  22. "emp_no"
  23. ] /* key_parts */
  24. }
  25. ] /* potential_range_indexes */,
  26. "setup_range_conditions": [
  27. ] /* setup_range_conditions */,
  28. "group_index_range": {
  29. "chosen": false,
  30. "cause": "not_group_by_or_distinct"
  31. } /* group_index_range */,
  32. "skip_scan_range": {
  33. "potential_skip_scan_indexes": [
  34. {
  35. "index": "salaries_from_date_to_date_index",
  36. "usable": false,
  37. "cause": "query_references_nonkey_column"
  38. }
  39. ] /* potential_skip_scan_indexes */
  40. } /* skip_scan_range */,
  41. "analyzing_range_alternatives": {
  42. "range_scan_alternatives": [
  43. {
  44. "index": "salaries_from_date_to_date_index",
  45. "ranges": [
  46. "0xda840f <= from_date <= 0xda840f AND 0xda860f <= to_date <= 0xda860f"
  47. ] /* ranges */,
  48. "index_dives_for_eq_ranges": true,
  49. "rowid_ordered": true,
  50. "using_mrr": false,
  51. "index_only": false,
  52. "rows": 86,
  53. "cost": 50.909,
  54. "chosen": true
  55. }
  56. ] /* range_scan_alternatives */,
  57. "analyzing_roworder_intersect": {
  58. "usable": false,
  59. "cause": "too_few_roworder_scans"
  60. } /* analyzing_roworder_intersect */
  61. } /* analyzing_range_alternatives */,
  62. "chosen_range_access_summary": {
  63. "range_access_plan": {
  64. "type": "range_scan",
  65. "index": "salaries_from_date_to_date_index",
  66. "rows": 86,
  67. "ranges": [
  68. "0xda840f <= from_date <= 0xda840f AND 0xda860f <= to_date <= 0xda860f"
  69. ] /* ranges */
  70. } /* range_access_plan */,
  71. "rows_for_plan": 86,
  72. "cost_for_plan": 50.909,
  73. "chosen": true
  74. } /* chosen_range_access_summary */
  75. } /* range_analysis */
  76. }
  77. ] /* rows_estimation */
  78. }

其中:

table:表名

range_analysis:

table_scan:如果全表扫描的话,需要扫描多少行(row,2838216),以及需要的代价(cost,286799)

potential_range_indexes:列出表中所有的索引并分析其是否可用。如果不可用的话,会列出不可用的原因是什么;如果可用会列出索引中可用的字段;

setup_range_conditions:如果有可下推的条件,则带条件考虑范围查询

group_index_range:当使用了GROUP BY或DISTINCT时,是否有合适的索引可用。当未使用GROUP BY或DISTINCT时,会显示chosen=false, cause=not_group_by_or_distinct;如使用了GROUP BY或DISTINCT,但是多表查询时,会显示chosen=false,cause =not_single_table。其他情况下会尝试分析可用的索引(potential_group_range_indexes)并计算对应的扫描行数及其所需代价

skip_scan_range:是否使用了skip scan

TIPS

skip_scan_range是MySQL 8.0的新特性,感兴趣的可详见 https://blog.csdn.net/weixin_43970890/article/details/89494915[7]

analyzing_range_alternatives:分析各个索引的使用成本

•range_scan_alternatives:range扫描分析

•index:索引名•ranges:range扫描的条件范围•index_dives_for_eq_ranges:是否使用了index dive,该值会被参数eq_range_index_dive_limit变量值影响。•rowid_ordered:该range扫描的结果集是否根据PK值进行排序•using_mrr:是否使用了mrr•index_only:表示是否使用了覆盖索引•rows:扫描的行数•cost:索引的使用成本•chosen:表示是否使用了该索引

•analyzing_roworder_intersect:分析是否使用了索引合并(index merge),如果未使用,会在cause中展示原因;如果使用了索引合并,会在该部分展示索引合并的代价。

chosen_range_access_summary:在前一个步骤中分析了各类索引使用的方法及代价,得出了一定的中间结果之后,在summary阶段汇总前一阶段的中间结果确认最后的方案

•range_access_plan:range扫描最终选择的执行计划。

•type:展示执行计划的type,如果使用了索引合并,则会显示index_roworder_intersect•index:索引名•rows:扫描的行数•ranges:range扫描的条件范围

•rows_for_plan:该执行计划的扫描行数•cost_for_plan:该执行计划的执行代价•chosen:是否选择该执行计划

considered_execution_plans

负责对比各可行计划的开销,并选择相对最优的执行计划。

  1. {
  2. "considered_execution_plans": [
  3. {
  4. "plan_prefix": [
  5. ] /* plan_prefix */,
  6. "table": "`salaries`",
  7. "best_access_path": {
  8. "considered_access_paths": [
  9. {
  10. "access_type": "ref",
  11. "index": "salaries_from_date_to_date_index",
  12. "rows": 86,
  13. "cost": 50.412,
  14. "chosen": true
  15. },
  16. {
  17. "access_type": "range",
  18. "range_details": {
  19. "used_index": "salaries_from_date_to_date_index"
  20. } /* range_details */,
  21. "chosen": false,
  22. "cause": "heuristic_index_cheaper"
  23. }
  24. ] /* considered_access_paths */
  25. } /* best_access_path */,
  26. "condition_filtering_pct": 100,
  27. "rows_for_plan": 86,
  28. "cost_for_plan": 50.412,
  29. "chosen": true
  30. }
  31. ] /* considered_execution_plans */
  32. }

其中:

•plan_prefix:当前计划的前置执行计划。•table:涉及的表名,如果有别名,也会展示出来•best_access_path:通过对比considered_access_paths,选择一个最优的访问路径

•considered_access_paths:当前考虑的访问路径

•access_type:使用索引的方式,可参考explain中的type字段•index:索引•rows:行数•cost:开销•chosen:是否选用这种执行路径

•condition_filtering_pct:类似于explain的filtered列,是一个估算值•rows_for_plan:执行计划最终的扫描行数,由considered_access_paths.rows X condition_filtering_pct计算获得。•cost_for_plan:执行计划的代价,由considered_access_paths.cost相加获得•chosen:是否选择了该执行计划

attaching_conditions_to_tables

基于considered_execution_plans中选择的执行计划,改造原有where条件,并针对表增加适当的附加条件,以便于单表数据的筛选。

TIPS

•这部分条件的增加主要是为了便于ICP(索引条件下推),但ICP是否开启并不影响这部分内容的构造。•ICP参考文档:https://www.cnblogs.com/Terry-Wu/p/9273177.html[8]

  1. {
  2. "attaching_conditions_to_tables": {
  3. "original_condition": "((`salaries`.`to_date` = DATE'1987-06-26') and (`salaries`.`from_date` = DATE'1986-06-26'))",
  4. "attached_conditions_computation": [
  5. ] /* attached_conditions_computation */,
  6. "attached_conditions_summary": [
  7. {
  8. "table": "`salaries`",
  9. "attached": "((`salaries`.`to_date` = DATE'1987-06-26') and (`salaries`.`from_date` = DATE'1986-06-26'))"
  10. }
  11. ] /* attached_conditions_summary */
  12. } /* attaching_conditions_to_tables */
  13. }

其中:

•original_condition:原始的条件语句•attached_conditions_computation:使用启发式算法计算已使用的索引,如果已使用的索引的访问类型是ref,则计算用range能否使用组合索引中更多的列,如果可以,则用range的方式替换ref。•attached_conditions_summary:附加之后的情况汇总

•table:表名•attached:附加的条件或原语句中能直接下推给单表筛选的条件。

finalizing_table_conditions

最终的、经过优化后的表条件。

  1. {
  2. "finalizing_table_conditions": [
  3. {
  4. "table": "`salaries`",
  5. "original_table_condition": "((`salaries`.`to_date` = DATE'1987-06-26') and (`salaries`.`from_date` = DATE'1986-06-26'))",
  6. "final_table_condition ": null
  7. }
  8. ] /* finalizing_table_conditions */
  9. }

refine_plan

改善执行计划:

  1. {
  2. "refine_plan": [
  3. {
  4. "table": "`salaries`"
  5. }
  6. ] /* refine_plan */
  7. }

其中:

•table:表名及别名

join_execution

join_execution段落展示了执行阶段的执行过程。

  1. "join_execution": {
  2. "select#": 1,
  3. "steps": [
  4. ] /* steps */
  5. }

参考文档

•Tracing the Optimizer[9]•手把手教你认识OPTIMIZER_TRACE[10]•MYSQL sql执行过程的一些跟踪分析(二.mysql优化器追踪分析)[11]•使用 Trace 进行执行计划分析[12]

干货分享

最近将个人学习笔记整理成册,使用PDF分享。关注我,回复如下代码,即可获得百度盘地址,无套路领取!

•001:《Java并发与高并发解决方案》学习笔记;•002:《深入JVM内核——原理、诊断与优化》学习笔记;•003:《Java面试宝典》•004:《Docker开源书》•005:《Kubernetes开源书》•006:《DDD速成(领域驱动设计速成)》•007:全部•008:加技术群讨论

近期热文

LinkedBlockingQueue vs ConcurrentLinkedQueue解读Java 8 中为并发而生的 ConcurrentHashMapRedis性能监控指标汇总最全的DevOps工具集合,再也不怕选型了!微服务架构下,解决数据库跨库查询的一些思路聊聊大厂面试官必问的 MySQL 锁机制

关注我

References

[1]https://dev.mysql.com/doc/internals/en/system-variables-controlling-trace.html
[2]https://blog.csdn.net/weixin_42813521/article/details/105563103
[3]https://dev.mysql.com/doc/internals/en/optimizer-features-to-trace.html
[4]https://dev.mysql.com/doc/internals/en/end-markers-in-json-system-variable.html
[5]https://dev.mysql.com/doc/internals/en/tuning-trace-purging.html
[6]https://dev.mysql.com/doc/refman/8.0/en/optimizer-trace-table.html
[7]https://blog.csdn.net/weixin_43970890/article/details/89494915
[8]https://www.cnblogs.com/Terry-Wu/p/9273177.html
[9] Tracing the Optimizer: https://dev.mysql.com/doc/internals/en/optimizer-tracing.html
[10] 手把手教你认识OPTIMIZER_TRACE: http://blog.itpub.net/28218939/viewspace-2658978/
[11] MYSQL sql执行过程的一些跟踪分析(二.mysql优化器追踪分析): http://blog.itpub.net/29863023/viewspace-2565095/
[12] 使用 Trace 进行执行计划分析: https://www.cnblogs.com/hbbbs/articles/12737077.html

喜欢就点个"在看"呗^_^

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/608250
推荐阅读
相关标签
  

闽ICP备14008679号