MYSQL: Handler_read_%参数说明
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了MYSQL: Handler_read_%参数说明,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5952字,纯文字阅读大概需要9分钟。
内容图文
![MYSQL: Handler_read_%参数说明](/upload/InfoBanner/zyjiaocheng/467/69e5969669034253ab04c366a7dbc543.jpg)
- id select_type table type possible_keys key key_len ref rows Extra
- 1 SIMPLE i ALL \\N \\N \\N \\N 98734
Handler_read_key + 1 : 根据第一个位置的KEY读1行,其他9行是根据叶节点的链表依次读取
Handler_read_rnd_next +10 : 从主键的叶节点(行数据)中顺序读取10行
> 索引扫描
EXPLAIN SELECT * FROM `t_feed_info` AS i ORDER BY feed_id LIMIT 0, 10;
点击(此处)折叠或打开
- id select_type table type possible_keys key key_len ref rows Extra
- 1 SIMPLE i index \\N PRIMARY 8 \\N 10
Handler_read_key + 1 : 根据第一个位置的KEY读1行
Handler_read_next + 9 : 按(主)键顺序依次读取之后的9行
EXPLAIN SELECT * FROM `t_feed_info` AS i ORDER BY feed_id DESC LIMIT 0, 10;
点击(此处)折叠或打开
- id select_type table type possible_keys key key_len ref rows Extra
- 1 SIMPLE i index \\N PRIMARY 8 \\N 10
Handler_read_last + 1 : 从(主)键的最后一个位置开始读取
Handler_read_prev + 9 : 按(主)键顺序依次读取之前的9行
> 索引覆盖扫描
EXPLAIN SELECT feed_id FROM `t_feed_info` AS i ORDER BY feed_id LIMIT 0, 10;
点击(此处)折叠或打开
- id select_type table type possible_keys key key_len ref rows Extra
- 1 SIMPLE i index \\N PRIMARY 8 \\N 10 Using index
Handler_read_key + 1 : 根据第一个位置的KEY读1行
Handler_read_next + 9 : 按(主)键顺序依次读取之后的9行
EXPLAIN SELECT feed_id FROM `t_feed_info` AS i ORDER BY feed_id DESC LIMIT 0, 10;
点击(此处)折叠或打开
- id select_type table type possible_keys key key_len ref rows Extra
- 1 SIMPLE i index \\N PRIMARY 8 \\N 10 Using index
Handler_read_last + 1 : 从(主)键的最后一个位置开始读取
Handler_read_prev + 9 : 按(主)键倒序依次读取之后的9行
############### join
# set @uid := ‘20000001‘;
> WHERE + 排序
# asc
EXPLAIN SELECT * FROM `t_feed_idx` AS i LEFT JOIN `t_feed_info` AS f ON f.`feed_id`=i.`feed_id`
WHERE i.user_id=@uid ORDER BY i.feed_id LIMIT 0, 10;
点击(此处)折叠或打开
- id select_type table type possible_keys key key_len ref rows Extra
- 1 SIMPLE i ref user_id user_id 8 const 200 Using where; Using index
- 1 SIMPLE f eq_ref PRIMARY PRIMARY 8 z3.i.feed_id 1
Handler_read_next + 9 : t_feed_idx按键顺序依次向后读取9个feed_id
# desc
EXPLAIN SELECT * FROM `t_feed_idx` AS i LEFT JOIN `t_feed_info` AS f ON f.`feed_id`=i.`feed_id`
WHERE i.user_id=@uid ORDER BY i.feed_id desc LIMIT 0, 10;
点击(此处)折叠或打开
- id select_type table type possible_keys key key_len ref rows Extra
- 1 SIMPLE i ref user_id user_id 8 const 200 Using where; Using index
- 1 SIMPLE f eq_ref PRIMARY PRIMARY 8 z3.i.feed_id 1
Handler_read_prev + 9 : t_feed_idx按键倒序依次向前读取9个feed_id
# 不好的查询方式:
> 使用被关联表t_feed_info的feed_id列进行排序 EXPLAIN SELECT * FROM `t_feed_idx` AS i LEFT JOIN `t_feed_info` AS f ON f.`feed_id`=i.`feed_id`
WHERE i.user_id=@uid ORDER BY f.feed_id LIMIT 0, 10;
点击(此处)折叠或打开
- id select_type table type possible_keys key key_len ref rows Extra
- 1 SIMPLE i ref user_id user_id 8 const 200 Using index; Using temporary; Using filesort
- 1 SIMPLE f eq_ref PRIMARY PRIMARY 8 z3.i.feed_id 1
Handler_read_next + 200 : t_feed_idx按键顺序依次读取199个feed_id. 额外的1次是??
Handler_read_rnd + 10 : filesort后每行位置都是固定的,limit 10取10行
Handler_read_rnd_next + 201: filesort全表遍历读取temporary表中的200行,进行排序; 额外的1是EOF标志位;
Using temporary; Using filesort 原因: 无法使用t_feed_idx表的索引
1>先查询表t_feed_idx中满足@uid的200行与表t_feed_info进行join,将结果保存在temporary表
Handler_read_key + 201, Handler_read_next + 200
2>然后对临时表排序;
Handler_read_rnd_next + 201
3>取前10个。
Handler_read_rnd + 10
> where条件放在join中 EXPLAIN SELECT * FROM `t_feed_idx` AS i
LEFT JOIN `t_feed_info` AS f ON f.`feed_id`=i.`feed_id` AND i.user_id=@uid
ORDER BY i.`feed_id` DESC LIMIT 0, 10;
点击(此处)折叠或打开
- id select_type table type possible_keys key key_len ref rows Extra
- 1 SIMPLE i index \\N user_id 16 \\N 100396 Using index; Using filesort
- 1 SIMPLE f eq_ref PRIMARY PRIMARY 8 z3.i.feed_id 1
Handler_read_key + 11 : t_feed_idx 根据user_id读1次,t_feed_info根据feed_id读10次
Handler_read_rnd_next + 100001: filesort全表遍历读取表t_feed_idx 中user_id索引的100000行,进行排序; 额外的1是EOF标志位;
没有 Using temporary 是因为先对t_feed_idx的索引user_id进行排序,然后再join
Using filesort 原因:
无法使用t_feed_idx表的索引
1>先对表t_feed_idx排序,取10个feed_id
Handler_read_first + 1, Handler_read_key + 1, Handler_read_rnd_next + 100001
2>然后根据feed_id与表t_feed_info进行join
Handler_read_key + 10
参考: http://www.mysqlperformanceblog.com/2010/06/15/what-does-handler_read_rnd-mean/
MYSQL: Handler_read_%参数说明
标签:
本文系统来源:http://www.cnblogs.com/zengkefu/p/5634830.html
内容总结
以上是互联网集市为您收集整理的MYSQL: Handler_read_%参数说明全部内容,希望文章能够帮你解决MYSQL: Handler_read_%参数说明所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。