In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you how the explain implementation plan key_len calculation rules are, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
Its rules are as follows:
1. All index fields, if not null is not set, need to be added by one byte.
two。 Fixed-length fields, four bytes for int, three bytes for date, and n characters for char (n).
3. For the field varchar (n), there are n characters + two bytes.
4. The number of bytes occupied by a character varies with different character sets. Latin1-encoded, one character occupies one byte, gbk-encoded, one character takes two bytes, utf8-encoded, one character takes three bytes.
Examples are as follows:
Mysql > desc person
+-+ +
| | Field | Type | Null | Key | Default | Extra | |
+-+ +
| | id | varchar | NO | PRI | |
| | name | varchar | YES | MUL | NULL |
| | age | int (10) | YES | | NULL |
+-+ +
3 rows in set (0.00 sec)
Check the index:
Mysql > show index from person
+ -+
| | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+ -+
| | person | 0 | PRIMARY | 1 | id | A | 2 | NULL | NULL | | BTREE |
| | person | 1 | idx_name | 1 | name | A | 2 | NULL | NULL | YES | BTREE |
+ -+
2 rows in set (0.00 sec)
Mysql > explain select name from person
+-- +
| | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+-- +
| | 1 | SIMPLE | person | index | NULL | idx_name | 103 | NULL | 2 | Using index |
+-- +
1 row in set (0.00 sec)
According to the above calculation rules:
All index fields, if not null is not set, need to be added by one byte
For the field varchar (n), there are n characters + two bytes
Therefore: key_len=100+2+1=103
These are all the contents of this article entitled "what are the key_len calculation rules in the explain implementation Plan?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.