mysql handler read_MySQL 状态变量Handler_read_next

MySQL有很多状态变量,每个状态变量都有其背后所代表的意义,本文介绍状态变量Handler_read_next及在哪些场景中,这个状态变量的值会显著增长。

一、Handler_read_next官方文档描述:

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.

翻译成中文,大概意思是按照索引顺序读取行记录的数量,这是一个累计值,如果按范围查询一个索引或者做一个索引扫描,就会导致这个值增长。

二、Handler_read_next场景测试:

下面做几个实验,观察一下Handler_read_next值的增长情况。

MySQL版本:5.7.19

表t1,3个字段分别为id,name,age,其中id为自增主键,表中一共有记录12289。

全表扫描:

flush status; 重置所有状态变量为0。

执行 select count(*) from t1 where age = 21;

age列没有索引,SQL走全表扫描,等值查询,Handler_read_next 为0。

全表扫描,范围查询:

select count(*) from t1 where age >5 and age < 20;

Handler_read_next 为0。

主键索引或者唯一索引:

flush status; 重置所有状态变量为0。

执行 select count(*) from t1 where id = 21;

走主键索引或者唯一索引,Handler_read_next 为0。

范围查询:

select count(*) from t1 where id >5 and id < 20;

Handler_read_next 为 13,与满足条件的记录数一致。

非唯一索引:

在age字段上添加非唯一索引。

flush status; 重置所有状态变量为0。

select count(*) from t1 where age =12;

Handler_read_next 为 2049,与满足条件的记录数一致。

范围查询:

select count(*) from t1 where age >5 and age < 20;

Handler_read_next 为 12289,与满足条件的记录数一致。

三、总结:

MySQL 的 Handler_read_next 状态变量记录下列场景下的索引扫描记录数。

主键索引的范围查询。

唯一索引的范围查询

非唯一索引的等值查询

非唯一索引的范围查询

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值