整形數字和字串數字的索引使用情況
阿新 • • 發佈:2019-01-29
http://imysqldba.blog.51cto.com/1222376/1277307
1 2 3 4 5 |
DROP TABLE ix_test;
CREATE TABLE ix_test
(id_1 varchar (20) NOT NULL ,
PRIMARY KEY (id_1));
INSERT INTO ix_test VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
mysql>
explain select * from ix_test where id_1=1;
+ ----+-------------+---------+-------+---------------+---------+---------+------+------+--------------------------+ |
id | select_type | table |
type | possible_keys | key |
key_len | ref | rows |
Extra |
+ ----+-------------+---------+-------+---------------+---------+---------+------+------+--------------------------+
|
1 | SIMPLE | ix_test | index | PRIMARY | PRIMARY |
302 | NULL |
11 | Using where ;
Using index |
+ ----+-------------+---------+-------+---------------+---------+---------+------+------+--------------------------+
1
row in set (0.00
sec)
mysql>
explain select * from ix_test where id_1= '1' ;
+ ----+-------------+---------+-------+---------------+---------+---------+-------+------+-------------+
|
id | select_type | table |
type | possible_keys | key |
key_len | ref | rows |
Extra |
+ ----+-------------+---------+-------+---------------+---------+---------+-------+------+-------------+
|
1 | SIMPLE | ix_test | const | PRIMARY | PRIMARY |
302 | const | 1 | Using index |
+ ----+-------------+---------+-------+---------------+---------+---------+-------+------+-------------+
1
row in set (0.01
sec)
|