zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

mysql explain中key_len的作用详解数据库

mysql数据库 详解 作用 Key explain len
2023-06-13 09:20:09 时间

mysql explain中key_len的作用
key_len越小 索引效果越好

name的字段类型是varchar(20),字符编码是utf8,一个字符占用3个字节,那么key_len应该是 20*3=60。


mysql explain select * from `member` where name=fdipzone;
+----+-------------+--------+------+---------------+------+---------+-------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+---------------+------+---------+-------+------+-----------------------+
| 1 | SIMPLE | member | ref | name | name | 63 | const | 1 | Using index condition |

explain的key_len为63,多出了3。

所以需要索引 设置字段长度尽量小 2 用定长char (key_len会少1) 3 用not null(key_len会少1)

如果用int key_len就是4 了 typeint就会更小1

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/4041.html

mysql