MySQL Handler变量解析
2016-07-19 14:21
756 查看
http://blog.itpub.net/29254281/viewspace-1159014/
To see the effect of a query do the following steps:
FLUSH STATUS;
Execute the query
SHOW SESSION STATUS LIKE 'handler_read%';
Do an EXPLAIN of the query
[b]
实验数据初始化:
[/b]
CREATE TABLE test (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
, data VARCHAR(32)
, ts TIMESTAMP
, INDEX (data)
);
INSERT INTO test
VALUES (NULL, 'abc', NOW()), (NULL, 'abc', NOW()), (NULL, 'abd', NOW())
, (NULL, 'acd', NOW()), (NULL, 'def', NOW()), (NULL, 'pqr', NOW())
, (NULL, 'stu', NOW()), (NULL, 'vwx', NOW()), (NULL, 'yza', NOW())
, (NULL, 'def', NOW())
;
SELECT * FROM test;
+----+------+---------------------+
| id | data | ts |
+----+------+---------------------+
| 1 | abc | 2008-01-18 16:28:40 |
| 2 | abc | 2008-01-18 16:28:40 |
| 3 | abd | 2008-01-18 16:28:40 |
| 4 | acd | 2008-01-18 16:28:40 |
| 5 | def | 2008-01-18 16:28:40 |
| 6 | pqr | 2008-01-18 16:28:40 |
| 7 | stu | 2008-01-18 16:28:40 |
| 8 | vwx | 2008-01-18 16:28:40 |
| 9 | yza | 2008-01-18 16:28:40 |
| 10 | def | 2008-01-18 16:28:40 |
+----+------+---------------------+
Handler_read_first[b]
全索引扫描的次数
The number of times the first entry was read from an index.
If this value is high, it suggests that the server is doing a lot of full index scans.
Handler_read_key
走索引的次数
The number of requests to read a row based on a key.
If this value is high, it is a good indication that your tables are properly indexed for your queries.
[/b]
HANDLER_READ_NEXT
The number of requests to read the next row in key order.
This value is incremented if you are querying an index column
with a range constraint or if you are doing an index scan.
[b]
Handler_read_prev
The number of requests to read the previous row in key order.
This read method is mainly used to optimize ORDER BY ... DESC.
Handler_read_rnd
文件排序或者没有使用索引
The number of requests to read a row based on a fixed position.
This value is high if you are doing a lot of queries that require sorting of the result.
You probably have a lot of queries that require MySQL to scan entire tables or you have joins that don't use keys properly.
Handler_read_rnd_next
此选项表明在进行数据文件扫描时,从数据文件里取数据的次数。
The number of requests to read the next row in the data file.
This value is high if you are doing a lot of table scans.
Generally this suggests that your tables are not properly indexed
or that your queries are not written to take advantage of the indexes you have.
[/b]
可以看到全表扫描其实也是走了key,可能是因为索引组织表的原因。因为limit 2 所以rnd_next为2.这个Stop Key在执行计划中是看不出来的。
使用索引消除排序,因为是升序,所以read first为1,由于limit 4,所以read_next为3.通过这个也可以看出Stop Key.
也是使用索引消除排序,因为是倒序,所以read_last为1,read_prev为2.因为往回读了两个key.
ALTER TABLE test ADD COLUMN file_sort text;
UPDATE test SET file_sort = 'abcdefghijklmnopqrstuvwxyz' WHERE id = 1;
UPDATE test SET file_sort = 'bcdefghijklmnopqrstuvwxyza' WHERE id = 2;
UPDATE test SET file_sort = 'cdefghijklmnopqrstuvwxyzab' WHERE id = 3;
UPDATE test SET file_sort = 'defghijklmnopqrstuvwxyzabc' WHERE id = 4;
UPDATE test SET file_sort = 'efghijklmnopqrstuvwxyzabcd' WHERE id = 5;
UPDATE test SET file_sort = 'fghijklmnopqrstuvwxyzabcde' WHERE id = 6;
UPDATE test SET file_sort = 'ghijklmnopqrstuvwxyzabcdef' WHERE id = 7;
UPDATE test SET file_sort = 'hijklmnopqrstuvwxyzabcdefg' WHERE id = 8;
UPDATE test SET file_sort = 'ijklmnopqrstuvwxyzabcdefgh' WHERE id = 9;
UPDATE test SET file_sort = 'jklmnopqrstuvwxyzabcdefghi' WHERE id = 10;
Handler_read_rnd为4 说明没有使用索引
rnd_next为11说明扫描了所有的数据
但是read first和read key的数据,不能解释.不知道为什么会是这个数据
read key总是read_rnd+1
参考: http://www.fromdual.com/mysql-handler-read-status-variables http://hi.baidu.com/thinkinginlamp/item/8d038333c6b0674a3075a1d3
To see the effect of a query do the following steps:
FLUSH STATUS;
Execute the query
SHOW SESSION STATUS LIKE 'handler_read%';
Do an EXPLAIN of the query
[b]
实验数据初始化:
[/b]
CREATE TABLE test (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
, data VARCHAR(32)
, ts TIMESTAMP
, INDEX (data)
);
INSERT INTO test
VALUES (NULL, 'abc', NOW()), (NULL, 'abc', NOW()), (NULL, 'abd', NOW())
, (NULL, 'acd', NOW()), (NULL, 'def', NOW()), (NULL, 'pqr', NOW())
, (NULL, 'stu', NOW()), (NULL, 'vwx', NOW()), (NULL, 'yza', NOW())
, (NULL, 'def', NOW())
;
SELECT * FROM test;
+----+------+---------------------+
| id | data | ts |
+----+------+---------------------+
| 1 | abc | 2008-01-18 16:28:40 |
| 2 | abc | 2008-01-18 16:28:40 |
| 3 | abd | 2008-01-18 16:28:40 |
| 4 | acd | 2008-01-18 16:28:40 |
| 5 | def | 2008-01-18 16:28:40 |
| 6 | pqr | 2008-01-18 16:28:40 |
| 7 | stu | 2008-01-18 16:28:40 |
| 8 | vwx | 2008-01-18 16:28:40 |
| 9 | yza | 2008-01-18 16:28:40 |
| 10 | def | 2008-01-18 16:28:40 |
+----+------+---------------------+
Handler_read_first[b]
全索引扫描的次数
The number of times the first entry was read from an index.
If this value is high, it suggests that the server is doing a lot of full index scans.
Handler_read_key
走索引的次数
The number of requests to read a row based on a key.
If this value is high, it is a good indication that your tables are properly indexed for your queries.
[/b]
HANDLER_READ_NEXT
The number of requests to read the next row in key order.
This value is incremented if you are querying an index column
with a range constraint or if you are doing an index scan.
[b]
Handler_read_prev
The number of requests to read the previous row in key order.
This read method is mainly used to optimize ORDER BY ... DESC.
Handler_read_rnd
文件排序或者没有使用索引
The number of requests to read a row based on a fixed position.
This value is high if you are doing a lot of queries that require sorting of the result.
You probably have a lot of queries that require MySQL to scan entire tables or you have joins that don't use keys properly.
Handler_read_rnd_next
此选项表明在进行数据文件扫描时,从数据文件里取数据的次数。
The number of requests to read the next row in the data file.
This value is high if you are doing a lot of table scans.
Generally this suggests that your tables are not properly indexed
or that your queries are not written to take advantage of the indexes you have.
[/b]
可以看到全表扫描其实也是走了key,可能是因为索引组织表的原因。因为limit 2 所以rnd_next为2.这个Stop Key在执行计划中是看不出来的。
使用索引消除排序,因为是升序,所以read first为1,由于limit 4,所以read_next为3.通过这个也可以看出Stop Key.
也是使用索引消除排序,因为是倒序,所以read_last为1,read_prev为2.因为往回读了两个key.
ALTER TABLE test ADD COLUMN file_sort text;
UPDATE test SET file_sort = 'abcdefghijklmnopqrstuvwxyz' WHERE id = 1;
UPDATE test SET file_sort = 'bcdefghijklmnopqrstuvwxyza' WHERE id = 2;
UPDATE test SET file_sort = 'cdefghijklmnopqrstuvwxyzab' WHERE id = 3;
UPDATE test SET file_sort = 'defghijklmnopqrstuvwxyzabc' WHERE id = 4;
UPDATE test SET file_sort = 'efghijklmnopqrstuvwxyzabcd' WHERE id = 5;
UPDATE test SET file_sort = 'fghijklmnopqrstuvwxyzabcde' WHERE id = 6;
UPDATE test SET file_sort = 'ghijklmnopqrstuvwxyzabcdef' WHERE id = 7;
UPDATE test SET file_sort = 'hijklmnopqrstuvwxyzabcdefg' WHERE id = 8;
UPDATE test SET file_sort = 'ijklmnopqrstuvwxyzabcdefgh' WHERE id = 9;
UPDATE test SET file_sort = 'jklmnopqrstuvwxyzabcdefghi' WHERE id = 10;
Handler_read_rnd为4 说明没有使用索引
rnd_next为11说明扫描了所有的数据
但是read first和read key的数据,不能解释.不知道为什么会是这个数据
read key总是read_rnd+1
参考: http://www.fromdual.com/mysql-handler-read-status-variables http://hi.baidu.com/thinkinginlamp/item/8d038333c6b0674a3075a1d3
相关文章推荐
- session入mysql
- mysql错误总结
- MySQL基础操作——转
- mysql设置编码
- Mysql 多实例安装
- 数据库优化之mysql系统的优化方式
- 数据库优化之mysql系统的优化方式
- ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
- mysql导入sql文件,乱码,一个例子
- MYSQL数据同步、复制、分发
- 远程连接mysql 授权方法教程
- mysql字段类型的选择原则
- MySQL Spatial Extensions 地理信息
- mysql-5.7.13-winx64.zip 安装
- MySQL--索引条件下推优化
- mysql 5.6 设置慢查询
- mysql解决中文乱码问题
- mysql主键insert into
- MySQL数据库优化技术之索引使用技巧总结
- MySQL优化---DBA对MySQL优化的一些总结