码迷,mamicode.com
首页 > 其他好文 > 详细

通过trace分析优化器如何选择执行计划

时间:2019-02-14 11:41:14      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:解析   form   sch   tar   pre   startup   variable   variables   fse   

1.

mysql> show variables like "optimizer_trace%"\G;
*************************** 1. row ***************************
Variable_name: optimizer_trace
Value: enabled=off,one_line=off
*************************** 2. row ***************************
Variable_name: optimizer_trace_features
Value: greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on
*************************** 3. row ***************************
Variable_name: optimizer_trace_limit
Value: 1
*************************** 4. row ***************************
Variable_name: optimizer_trace_max_mem_size
Value: 16384
*************************** 5. row ***************************
Variable_name: optimizer_trace_offset
Value: -1
5 rows in set (0.01 sec)

2.打开trace,设置格式为json,设置trace最大能够使用的内存大小,避免解析过程中因为默认内存过小而不能够完整显示。

mysql> use sakila
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select rental_id from rental where 1=1 and rental_date >=‘2005-05-25 04:00:00‘ and rental_date <=‘2005-05-25 05:00:00‘ and inventory_id=4466;
+-----------+
| rental_id |
+-----------+
| 39 |
+-----------+
1 row in set (0.00 sec)

3.检查MySQL是如何执行SQL的。

mysql> use information_schema 

mysql> select * from OPTIMIZER_TRACE\G;
*************************** 1. row ***************************
QUERY: SELECT DATABASE()
TRACE: {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select database() AS `DATABASE()`"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
] /* steps */
} /* join_optimization */
},
{
"join_execution": {
"select#": 1,
"steps": [
] /* steps */
} /* join_execution */
}
] /* steps */
}
MISSING_BYTES_BEYOND_MAX_MEM_SIZE: 0
INSUFFICIENT_PRIVILEGES: 0
1 row in set (0.00 sec)

通过trace分析优化器如何选择执行计划

标签:解析   form   sch   tar   pre   startup   variable   variables   fse   

原文地址:https://www.cnblogs.com/chinaops/p/10373687.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!