trace分析优化器执行计划

MySQL5.6提供了对SQL的跟踪trace, 通过trace文件能够进一步了解为什么优化器选择A计划, 而不是选择B计划。

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

SET optimizer_trace="enabled=on",end_markers_in_json=on;
set optimizer_trace_max_mem_size=1000000;

执行SQL语句 :

select * from tb_item where id < 4;

最后, 检查information_schema.optimizer_trace就可以知道MySQL是如何执行SQL的 :

select * from information_schema.optimizer_trace\G;
*************************** 1. row ***************************
QUERY: select * from tb_item where id < 4
TRACE: {"steps": [{"join_preparation": {"select#": 1,"steps": [{"expanded_query": "/* select#1 */ select `tb_item`.`id` AS `id`,`tb_item`.`title` AS `title`,`tb_item`.`price` AS `price`,`tb_item`.`num` AS `num`,`tb_item`.`categoryid` AS `categoryid`,`tb_item`.`status` AS `status`,`tb_item`.`sellerid` AS `sellerid`,`tb_item`.`createtime` AS `createtime`,`tb_item`.`updatetime` AS `updatetime` from `tb_item` where (`tb_item`.`id` < 4)"}] /* steps */} /* join_preparation */},{"join_optimization": {"select#": 1,"steps": [{"condition_processing": {"condition": "WHERE","original_condition": "(`tb_item`.`id` < 4)","steps": [{"transformation": "equality_propagation","resulting_condition": "(`tb_item`.`id` < 4)"},{"transformation": "constant_propagation","resulting_condition": "(`tb_item`.`id` < 4)"},{"transformation": "trivial_condition_removal","resulting_condition": "(`tb_item`.`id` < 4)"}] /* steps */} /* condition_processing */},{"table_dependencies": [{"table": "`tb_item`","row_may_be_null": false,"map_bit": 0,"depends_on_map_bits": [] /* depends_on_map_bits */}] /* table_dependencies */},{"ref_optimizer_key_uses": [] /* ref_optimizer_key_uses */},{"rows_estimation": [{"table": "`tb_item`","range_analysis": {"table_scan": {"rows": 9816098,"cost": 2.04e6} /* table_scan */,"potential_range_indices": [{"index": "PRIMARY","usable": true,"key_parts": ["id"] /* key_parts */}] /* potential_range_indices */,"setup_range_conditions": [] /* setup_range_conditions */,"group_index_range": {"chosen": false,"cause": "not_group_by_or_distinct"} /* group_index_range */,"analyzing_range_alternatives": {"range_scan_alternatives": [{"index": "PRIMARY","ranges": ["id < 4"] /* ranges */,"index_dives_for_eq_ranges": true,"rowid_ordered": true,"using_mrr": false,"index_only": false,"rows": 3,"cost": 1.6154,"chosen": true}] /* range_scan_alternatives */,"analyzing_roworder_intersect": {"usable": false,"cause": "too_few_roworder_scans"} /* analyzing_roworder_intersect */} /* analyzing_range_alternatives */,"chosen_range_access_summary": {"range_access_plan": {"type": "range_scan","index": "PRIMARY","rows": 3,"ranges": ["id < 4"] /* ranges */} /* range_access_plan */,"rows_for_plan": 3,"cost_for_plan": 1.6154,"chosen": true} /* chosen_range_access_summary */} /* range_analysis */}] /* rows_estimation */},{"considered_execution_plans": [{"plan_prefix": [] /* plan_prefix */,"table": "`tb_item`","best_access_path": {"considered_access_paths": [{"access_type": "range","rows": 3,"cost": 2.2154,"chosen": true}] /* considered_access_paths */} /* best_access_path */,"cost_for_plan": 2.2154,"rows_for_plan": 3,"chosen": true}] /* considered_execution_plans */},{"attaching_conditions_to_tables": {"original_condition": "(`tb_item`.`id` < 4)","attached_conditions_computation": [] /* attached_conditions_computation */,"attached_conditions_summary": [{"table": "`tb_item`","attached": "(`tb_item`.`id` < 4)"}] /* attached_conditions_summary */} /* attaching_conditions_to_tables */},{"refine_plan": [{"table": "`tb_item`","access_type": "range"}] /* refine_plan */}] /* steps */} /* join_optimization */},{"join_execution": {"select#": 1,"steps": [] /* steps */} /* join_execution */}] /* steps */
}

MySQL高级 trace工具相关推荐

  1. MySQL - 使用trace工具来窥探MySQL是如何选择执行计划的

    文章目录 生猛干货 Pre 演示Demo trace工具使用 Trace分析 Trace解读 搞定MySQL 生猛干货 带你搞定MySQL实战,轻松对应海量业务处理及高并发需求,从容应对大场面试 Pr ...

  2. MySQL使用trace工具查看执行计划

    文章目录 一.什么是trace工具 二.trace工具的使用 三.结构分析 3.1.SQL准备阶段 3.2.SQL分析.优化阶段 四.重要信息分析 一.什么是trace工具 MySQL5.6版本开始, ...

  3. MySQL高级 - 常用工具 - mysql

    mysql 该mysql不是指mysql服务,而是指mysql的客户端工具. 语法 : mysql [options] [database] 连接选项 参数 : -u, --user=name 指定用 ...

  4. MySQL高级 - 常用工具 - mysqlimport与source

    mysqlimport/source mysqlimport 是客户端数据导入工具,用来导入mysqldump 加 -T 参数后导出的文本文件. 语法: mysqlimport [options] d ...

  5. MySQL高级 - 常用工具 - mysqlshow

    mysqlshow mysqlshow 客户端对象查找工具,用来很快地查找存在哪些数据库.数据库中的表.表中的列或者索引. 语法: mysqlshow [options] [db_name [tabl ...

  6. MySQL高级 - 常用工具 - mysqlbinlog与mysqldump

    由于服务器生成的二进制日志文件以二进制格式保存,所以如果想要检查这些文本的文本格式,就会使用到mysqlbinlog 日志管理工具. 语法 : mysqlbinlog [options] log-fi ...

  7. MySQL高级 - 常用工具 - mysqladmin

    mysqladmin 是一个执行管理操作的客户端程序.可以用它来检查服务器的配置和当前状态.创建并删除数据库等. 可以通过 : mysqladmin --help 指令查看帮助文档 示例 :mysql ...

  8. 强劲的Linux Trace工具:bpftrace (DTrace 2.0) for Linux 2018

    Original:阿里 姜弋内核月谈 译者: 姜弋 译者注:原作者是大名鼎鼎的性能分析专家:Brendan Gregg,现在工作在Netflix,之前工作在Sun,在Sun公司的时候,他就做了大量的性 ...

  9. 从前慢-Mysql高级及实战

    Mysql高级及实战 1 Linux 系统安装MySQL 1.1 下载Linux 安装包 https://dev.mysql.com/downloads/mysql/5.7.html#download ...

最新文章

  1. Android 团队早期员工解释 Android 哪里不如 iOS
  2. 无法嵌入互操作类型 请改用适用的接口。
  3. security with acl
  4. 使用Dropwizard度量标准监视和测量无功应用
  5. C++ 虚函数经典深入解析
  6. [译] Cilium:BPF 和 XDP 参考指南(2021)
  7. Windows系统cmd命令检测dll文件
  8. 算法工程师面试备战笔记7_数据清洗与特征处理
  9. Emmet 简写语法
  10. 计算机显卡怎样安装方法,台式机显卡怎么安装?教您安装方法
  11. earth orientation parameter(EOP)地球指向参数
  12. 罗辑回归,Logistic Regression(or sigmoid function)
  13. 远期外汇交易的交割日
  14. Codeforces Round #727 (Div. 2)_B. Love Song(前缀和)
  15. java caller_【JavaScript】callee 与 caller
  16. 电脑桌面app客户端、微信公众号-小程序测试方法
  17. 常用git 命令备忘
  18. 【React学习】React中ref的用法
  19. 打造高效能团队之测试能力提升
  20. log4j日志文件乱码问题的解决方法

热门文章

  1. Delphi字符串处理函数
  2. [emacs] python代码折叠
  3. C'mon C'mon-Von Bondies
  4. Linux - 简单设置 vim (tab, 行号, 换行)
  5. Codeforces 429B Working out:dp【枚举交点】
  6. Codeforces Round #243 (Div. 1)——Sereja and Squares
  7. 汽车保险解读:解析涉水损失险与自燃险
  8. 获取web.py上面的示例code
  9. OLTP 和OLAP
  10. C语言中的EOF符号常量