博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Deep into MySQL QEP with optimizer_trace
阅读量:5251 次
发布时间:2019-06-14

本文共 6416 字,大约阅读时间需要 21 分钟。

 

Deep into MySQL QEP with optimizer_trace

Louis Hust

 

0  Preface

MySQL5.6 add a new option to show QEP more deeply-optimizer_trace. This option is very different from EXPLAIN which just showes the table access method, index using, table join order and so on. But optimizer_trace output every steps of how the Optimizer processes query, such as join prepare, join optimizer and join exec. Each of the three steps contains many substeps such as expanded_query, equality_propagation, trivial_condition_removal, etc.

 

0  Show QEP in deep

# Turn tracing on (it's off by default):SET optimizer_trace="enabled=on";SELECT * FROM t1 WHERE c1=1 or c1=100;# your query hereSELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;# possibly more queries...# When done with tracing, disable it:SET optimizer_trace="enabled=off";
 

An example below:

 
{  "steps": [    {      "join_preparation": {        "select#": 1,        "steps": [          {            "expanded_query": "/* select#1 */ select `t1`.`c1` AS `c1`,`t1`.`c2` AS `c2` from `t1` where ((`t1`.`c1` = 1) or (`t1`.`c1` = 100))"          }        ]      }    },    {      "join_optimization": {        "select#": 1,        "steps": [          {            "condition_processing": {              "condition": "WHERE",              "original_condition": "((`t1`.`c1` = 1) or (`t1`.`c1` = 100))",              "steps": [                {                  "transformation": "equality_propagation",                  "resulting_condition": "(multiple equal(1, `t1`.`c1`) or multiple equal(100, `t1`.`c1`))"                },                {                  "transformation": "constant_propagation",                  "resulting_condition": "(multiple equal(1, `t1`.`c1`) or multiple equal(100, `t1`.`c1`))"                },                {                  "transformation": "trivial_condition_removal",                  "resulting_condition": "(multiple equal(1, `t1`.`c1`) or multiple equal(100, `t1`.`c1`))"                }              ]            }          },          {            "table_dependencies": [              {                "table": "`t1`",                "row_may_be_null": false,                "map_bit": 0,                "depends_on_map_bits": [                ]              }            ]          },          {            "ref_optimizer_key_uses": [            ]          },          {            "rows_estimation": [              {                "table": "`t1`",                "range_analysis": {                  "table_scan": {                    "rows": 10157,                    "cost": 2057.5                  },                  "potential_range_indices": [                    {                      "index": "c1",                      "usable": true,                      "key_parts": [                        "c1"                      ]                    }                  ],                  "setup_range_conditions": [                  ],                  "group_index_range": {                    "chosen": false,                    "cause": "not_group_by_or_distinct"                  },                  "analyzing_range_alternatives": {                    "range_scan_alternatives": [                      {                        "index": "c1",                        "ranges": [                          "1 <= c1 <= 1",                          "100 <= c1 <= 100"                        ],                        "index_dives_for_eq_ranges": true,                        "rowid_ordered": false,                        "using_mrr": false,                        "index_only": false,                        "rows": 2,                        "cost": 4.41,                        "chosen": true                      }                    ],                    "analyzing_roworder_intersect": {                      "usable": false,                      "cause": "too_few_roworder_scans"                    }                  },                  "chosen_range_access_summary": {                    "range_access_plan": {                      "type": "range_scan",                      "index": "c1",                      "rows": 2,                      "ranges": [                        "1 <= c1 <= 1",                        "100 <= c1 <= 100"                      ]                    },                    "rows_for_plan": 2,                    "cost_for_plan": 4.41,                    "chosen": true                  }                }              }            ]          },          {            "considered_execution_plans": [              {                "plan_prefix": [                ],                "table": "`t1`",                "best_access_path": {                  "considered_access_paths": [                    {                      "access_type": "range",                      "rows": 2,                      "cost": 4.81,                      "chosen": true                    }                  ]                },                "cost_for_plan": 4.81,                "rows_for_plan": 2,                "chosen": true              }            ]          },          {            "attaching_conditions_to_tables": {              "original_condition": "((`t1`.`c1` = 1) or (`t1`.`c1` = 100))",              "attached_conditions_computation": [              ],              "attached_conditions_summary": [                {                  "table": "`t1`",                  "attached": "((`t1`.`c1` = 1) or (`t1`.`c1` = 100))"                }              ]            }          },          {            "refine_plan": [              {                "table": "`t1`",                "pushed_index_condition": "((`t1`.`c1` = 1) or (`t1`.`c1` = 100))",                "table_condition_attached": null,                "access_type": "range"              }            ]          }        ]      }    },    {      "join_explain": {        "select#": 1,        "steps": [        ]      }    }  ]}
 

As seen above, we can get almost every step in Optimizer processing, from setup conditions to plan choosing. The result is output according to order of the code executing, but EXPLAIN is just a print of JOIN_TAB. I can not explain every step, cause I do not know every steps.

 

Actually the Optimizer code of MySQL is hard to read, with the trace, we can read the code more easily.

 

References


File translated from TEX by , version 4.03.

On 5 Jan 2013, 19:30.

转载于:https://www.cnblogs.com/nocode/archive/2013/01/05/2846592.html

你可能感兴趣的文章
几道面试题
查看>>
Factory Design Pattern
查看>>
python中贪婪与非贪婪
查看>>
guava API整理
查看>>
无锁编程笔记
查看>>
jquery mobile
查看>>
如何在vue单页应用中使用百度地图
查看>>
P1192-台阶问题
查看>>
一、使用pip安装Python包
查看>>
spring与quartz整合
查看>>
Kattis之旅——Eight Queens
查看>>
3.PHP 教程_PHP 语法
查看>>
Duilib扩展《01》— 双击、右键消息扩展
查看>>
利用Fiddler拦截接口请求并篡改数据
查看>>
python习题:unittest参数化-数据从文件或excel中读取
查看>>
在工程中要加入新的错误弹出方法
查看>>
PS 滤镜— — sparkle 效果
查看>>
网站产品设计
查看>>
代理ARP
查看>>
go 学习笔记(4) ---项目结构
查看>>