Percona-Tookit工具包之pt-visual-explain
pt-visual-explain [OPTIONS] [FILES]
--clustered-pk -- For innodb,it allows primary key index access not to use bookmark lookup.
--format -- Set the type of output(default "tree",others "dump").
--connect -- Specify a followed file which contains a query and output result of explain on the query.
--database -- Specify which database to connect.
--host -- Specify connection hostname.
--port -- Specify connection port.
--user -- Specify connection user.
--password -- Specify connection password.
--socket -- Specify connection socket.
root@localhost:mysql3306.sock [zlm]>show create table customer\G
*************************** . row ***************************
Table: customer
Create Table: CREATE TABLE `customer` (
`id` int() unsigned NOT NULL AUTO_INCREMENT,
`order_id` int() unsigned NOT NULL DEFAULT '',
`name` varchar() NOT NULL DEFAULT '',
`gender` enum('male','female') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT= DEFAULT CHARSET=utf8mb4
row in set (0.00 sec) root@localhost:mysql3306.sock [zlm]>show create table goods\G
*************************** . row ***************************
Table: goods
Create Table: CREATE TABLE `goods` (
`id` int() unsigned NOT NULL AUTO_INCREMENT,
`order_id` int() unsigned NOT NULL,
`goodsname` varchar() NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT= DEFAULT CHARSET=utf8mb4
row in set (0.00 sec)
[root@zlm1 :: ~]
#echo "select count(*) from customer join goods using(order_id);" > query1.sql [root@zlm1 :: ~]
#pt-visual-explain -h192.168.56. -P3306 -urepl -prepl4slave -Dzlm --connect query1.sql
JOIN
+- Join buffer
| +- Filter with WHERE
| +- Table scan -- It means "customer" is a drived table,do full table scan.
| rows
| +- Table
| table customer
+- Table scan -- It means "goods" is a drive table,do full table scan,too.
rows
+- Table
table goods [root@zlm1 :: ~]
#
root@localhost:mysql3306.sock [zlm]>explain select count(*) from customer join goods using(order_id);
+----+-------------+----------+------------+------+---------------+------+---------+------+-------+----------+----------------------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+----------+------------+------+---------------+------+---------+------+-------+----------+----------------------------------------------------+
| | SIMPLE | goods | NULL | ALL | NULL | NULL | NULL | NULL | | 100.00 | NULL |
| | SIMPLE | customer | NULL | ALL | NULL | NULL | NULL | NULL | | 10.00 | Using where; Using join buffer (Block Nested Loop) |
+----+-------------+----------+------------+------+---------------+------+---------+------+-------+----------+----------------------------------------------------+
rows in set, warning (0.00 sec) ###The output of explain is compatiable with the output of tree above.###
[root@zlm1 :: ~]
#mysql -e "use zlm;explain select count(*) from customer join goods where goods.goodsname='cellphone';" > explain1.log [root@zlm1 :: ~]
#pt-visual-explain -h192.168.56. -P3306 -urepl -prepl4slave explain1.log
JOIN
+- Join buffer
| +- Index scan -- It means "customer" is a drive table,do index scan with primary.
| key customer->PRIMARY
| key_len
| rows
+- Filter with WHERE
+- Table scan -- It means "goods" is a drive table,do full table scan,too.
rows
+- Table
table goods [root@zlm1 :: ~]
#
root@localhost:mysql3306.sock [zlm]>explain select count(*) from customer join goods where goods.goodsname='cellphone';
+----+-------------+----------+------------+-------+---------------+---------+---------+------+-------+----------+----------------------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+----------+------------+-------+---------------+---------+---------+------+-------+----------+----------------------------------------------------+
| | SIMPLE | goods | NULL | ALL | NULL | NULL | NULL | NULL | | 10.00 | Using where |
| | SIMPLE | customer | NULL | index | NULL | PRIMARY | | NULL | | 100.00 | Using index; Using join buffer (Block Nested Loop) |
+----+-------------+----------+------------+-------+---------------+---------+---------+------+-------+----------+----------------------------------------------------+
rows in set, warning (0.00 sec)
[root@zlm1 :: ~]
#mysql -e "use zlm;explain select c.name,c.gender,g.goodsname from goods g,customer c where c.order_id=g.order_id and c.id<=5;" | pt-visual-explain
JOIN
+- Join buffer
| +- Filter with WHERE
| +- Table scan
| rows
| +- Table
| table g -- Show table with alias "g" and it's a dirved table,do full table scan.
+- Filter with WHERE
+- Bookmark lookup -- If you're using only innodb table,this kind of lookup will lead to bad performance.
+- Table
| table c -- Show table with alias "c" and it's a drive table,do index range scan.
| possible_keys PRIMARY
+- Index range scan
key c->PRIMARY
possible_keys PRIMARY
key_len
rows [root@zlm1 :: ~]
#select c.name,c.gender,g.goodsname from goods g,customer c where c.order_id=g.order_id and c.id<=;
+------+--------+-----------+
| name | gender | goodsname |
+------+--------+-----------+
| zlm | male | tv |
| zlm | male | tv |
| zlm | male | tv |
| zlm | male | tv |
| zlm | male | tv |
| zlm | male | cd |
| zlm | male | cd |
| zlm | male | cd |
| zlm | male | cd |
| zlm | male | cd |
| zlm | male | dvd |
| zlm | male | dvd |
| zlm | male | dvd |
| zlm | male | dvd |
| zlm | male | dvd |
| zlm | male | cellphone |
| zlm | male | cellphone |
| zlm | male | cellphone |
| zlm | male | cellphone |
| zlm | male | cellphone |
| zlm | male | computer |
| zlm | male | computer |
| zlm | male | computer |
| zlm | male | computer |
| zlm | male | computer |
+------+--------+-----------+
rows in set (0.00 sec)
root@localhost:mysql3306.sock [zlm]>explain select c.name,c.gender,g.goodsname from goods g,customer c where c.order_id=g.order_id and c.id<=;
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+----------------------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+----------------------------------------------------+
| | SIMPLE | c | NULL | range | PRIMARY | PRIMARY | | NULL | | 100.00 | Using where |
| | SIMPLE | g | NULL | ALL | NULL | NULL | NULL | NULL | | 10.00 | Using where; Using join buffer (Block Nested Loop) |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+----------------------------------------------------+
rows in set, warning (0.00 sec)
[root@zlm1 :: ~]
#mysql -e "use zlm;explain select c.name,c.gender,g.goodsname from goods g,customer c where c.order_id=g.order_id and c.id<=5;" | pt-visual-explain --clustered-pk
JOIN
+- Join buffer
| +- Filter with WHERE
| +- Table scan
| rows
| +- Table
| table g
+- Filter with WHERE
+- Index range scan -- This time the "bookmark lookup" is missing.It will lookup by pk directly what is more efficient way.
key c->PRIMARY
possible_keys PRIMARY
key_len
rows
- The "--clustered-pk" is only for innodb case to avoid bookmark lookup.
- If you specify the "--connect" option, a file contains SQL query need to be used,too.
- pt-visual-explain depends on explain of MySQL and provides several ways to generate trees.
- The information of pt-visual-explain is limited,if you want to get more details such as "cost_info","query_cost",etc.You'd better use json format of original MySQL explain.
Percona-Tookit工具包之pt-visual-explain的更多相关文章
- [转]细说MySQL Explain和Optimizer Trace简介
在开发过程中,对每个上线的SQL查询指纹(query figerprint)的质量都应有估算:而估算DB查询质量最直接的方法,就是分析其查询执行计划( Query Execution Plan ,即Q ...
- 016:Explain
一. Explain EXPLAIN 官方文档 1.explain说明 explain是解释SQL语句的执行计划,即显示该SQL语句怎么执行的 使用explain的时候,也可以使用desc 5.6 版 ...
- 索引及explain
索引好比书的目录.通过索引能快速的定位到一条数据. 在MySQL中除了B+树索引之外,还有一些其他的索引类型.比如:全文索引.(DB和DD索引叫R树索引).在MySQL cluster中是P树索引,m ...
- Linux后台开发工具箱
https://files-cdn.cnblogs.com/files/aquester/Linux后台开发工具箱.pdf 目录 目录 1 1. 前言 3 2. 脚本类工具 3 2.1. sed命令- ...
- Mysql: pt-table-checksum 和 pt-table-sync 检查主从一致性,实验过程
一.安装 percona 包 1.安装仓库的包 https://www.percona.com/doc/percona-repo-config/yum-repo.html sudo yum insta ...
- Linux后台开发工具箱-葵花宝典
Linux后台开发工具箱-葵花宝典 一见 2016/11/4 目录 目录 1 1. 前言 4 2. 脚本类工具 4 2.1. 双引号和单引号 4 2.2. 取脚本完整文件路径 5 2.3. 环境变量和 ...
- [知识库分享系列] 二、.NET(ASP.NET)
最近时间又有了新的想法,当我用新的眼光在整理一些很老的知识库时,发现很多东西都已经过时,或者是很基础很零碎的知识点.如果分享出去大家不看倒好,更担心的是会误人子弟,但为了保证此系列的完整,还是选择分享 ...
- 使用Apache Spark 对 mysql 调优 查询速度提升10倍以上
在这篇文章中我们将讨论如何利用 Apache Spark 来提升 MySQL 的查询性能. 介绍 在我的前一篇文章Apache Spark with MySQL 中介绍了如何利用 Apache Spa ...
- 推荐几款MySQL相关工具
前言: 随着互联网技术的不断发展, MySQL 相关生态也越来越完善,越来越多的工具涌现出来.一些公司或个人纷纷开源出一些不错的工具,本篇文章主要介绍几款 MySQL 相关实用工具.提醒下,这里并不介 ...
- db2基础
DB2知识文档 一.db2 基础 基本语法 注释:"--"(两个减号) 字符串连接:"||" 如set msg='aaaa'||'bbbb',则msg为'aaa ...
随机推荐
- axios 发 post 请求,后端接收不到参数的解决方案
问题场景 场景很简单,就是一个正常 axios post 请求: axios({ headers: { 'deviceCode': 'A95ZEF1-47B5-AC90BF3' }, method: ...
- es6变量解构赋值的用途
这里是我觉得es6解构赋值,在平时我们写js的时候非常有用,而且经常用到的地方,能简化我们的代码,让写代码简介优雅易读; 用途 1.交换变量的值,太方便了这逼,写法不仅简介而且一看就明白 let [x ...
- Linux自有服务
Linux自有服务 Linux自带的功能:运行模式.用户和用户组管理.网络配置.ssh服务 1.运行模式 Linux下的初始化进程:init,进程id为1 该进程的配置文件:/etc/inittab ...
- iDempiere 使用指南 windows下eclipse开发环境配置及打包下载
Created by 蓝色布鲁斯,QQ32876341,blog http://www.cnblogs.com/zzyan/ iDempiere官方中文wiki主页 http://wiki.idemp ...
- UITableViewCell 分割线如何满屏
在iOS7中,UITableViewCell左侧会有默认15像素的空白.设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉. 但是在iOS8中,设置setSepar ...
- arcengine自己做一个工具Tool放到工具箱中
// Copyright 2010 ESRI // // All rights reserved under the copyright laws of the United States // an ...
- 【起航计划 031】2015 起航计划 Android APIDemo的魔鬼步伐 30 App->Preferences->Advanced preferences 自定义preference OnPreferenceChangeListener
前篇文章Android ApiDemo示例解析(31):App->Preferences->Launching preferences 中用到了Advanced preferences 中 ...
- Matlab GUI选项卡
1.在这个网址下载一个工具包,里面应该有四个文件:tabselectionfcp.p.tabselectionfcn.m.tabpanel.p和tabpanel.m,显然代码用.p格式进行加密了. 2 ...
- day014-反射、注解
1. Junit 1.1什么是Junit Junit是Java语言编写的第三方单元测试框架(工具). 1.2单元测试 在Java中,一个类就是一个单元. 单元测试:开发中编写的一小段代码,用来检测类中 ...
- nginx封IP脚本
#!/bin/bash max= confdir=/etc/nginx/conf.d/blockips.conf logdir=/var/log/nginx/access.log echo " ...