失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > mysql什么是覆盖索引 MySQL中的覆盖索引

mysql什么是覆盖索引 MySQL中的覆盖索引

时间:2020-01-08 11:45:02

相关推荐

mysql什么是覆盖索引 MySQL中的覆盖索引

索引覆盖

Extra字段显示Using index,索引处取得的数据即是要求的数据,则不会再回数据文件再查询,直接返回了。

explain select id from account where id = 1;

输出:

mysql> explain select id from account where id = 1;

+----+-------------+---------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+

| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |

+----+-------------+---------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+

| 1 | SIMPLE | account | NULL | const | PRIMARY | PRIMARY | 4 | const | 1 | 100.00 | Using index |

+----+-------------+---------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+

1 row in set, 1 warning (0.00 sec)

回表查询

取得索引上保存的数据,再回数据文件中查询所要求的的全部的属性值。

explain select * from account where id = 1;

输出:

mysql> explain select * from account where id = 1;

+----+-------------+---------+------------+-------+---------------+---------+---------+-------+------+----------+-------+

| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |

+----+-------------+---------+------------+-------+---------------+---------+---------+-------+------+----------+-------+

| 1 | SIMPLE | account | NULL | const | PRIMARY | PRIMARY | 4 | const | 1 | 100.00 | NULL |

+----+-------------+---------+------------+-------+---------------+---------+---------+-------+------+----------+-------+

1 row in set, 1 warning (0.00 sec)

原理

B+树在叶子节点保存节点索引和节点数据,这里的节点数据保存的只是创建索引时指定的字段,其他字段在数据文件中。

如果觉得《mysql什么是覆盖索引 MySQL中的覆盖索引》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。