Ken_len represents the number of bytes used by the index, based on this value, it is possible to determine the index usage, especially when combining indexes, to determine whether all the indexed fields are queried.
Key_len shows the index length required by the conditional retrieval clause, but the index used by the ORDER by and the GROUP by clause does not count toward the key_len statistic value;
About the calculation rules for Key_len:
• When the index field is a fixed-length data type, such as: char,int,datetime, whether it needs to have an empty tag, this tag needs to occupy 1 bytes;
• When the index field is a variable-length data type, such as: varchar, besides whether it is an empty tag, it also needs to have length information, which takes up to 2 bytes;
• If the field is defined as non-empty, the mark will not occupy bytes;
• Also need to consider the differences in the character set used in the table, Latin1 encodes a character of 1 bytes, GBK encodes a character 2 bytes, UTF8 encodes a character 3 bytes;
Calculation formula of Key_len length
VARCHR (10) Variable length field and allow null:10* (Character set:utf8=3,gbk=2,latin1=1) +1 (null tag bit) +2 (variable-length field)
VARCHR (10) Variable-length field and do not allow null:10* (Character set:utf8=3,gbk=2,latin1=1) +2 (variable-length field)
char (10) Fixed field and allow null:10* (Character set:utf8=3,gbk=2,latin1=1) +1 (null tag bit)
char (10) Fixed field and does not allow null:10* (Character set:utf8=3,gbk=2,latin1=1)
Calculation of Key_len in MySQL explain