I have a table T like this
Create Table: CREATE TABLE `T` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`a` int(11) NOT NULL DEFAULT '0',
`b` int(11) NOT NULL DEFAULT '0',
`c` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `idx_ab` (`a`,`b`)
) ENGINE=InnoDB AUTO_INCREMENT=2048 DEFAULT CHARSET=latin1
I perform this SQL:
explain select * from T force index (idx_ab) where a >= 100 and b = 200;
I guess this sql can use index on a, and the key_len would be 4, but in fact the output key_len is 8, why?
mysql> explain select * from T force index (idx_ab) where a >= 100 and b = 200;
+----+-------------+-------+-------+---------------+--------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+--------+---------+------+------+-----------------------+
| 1 | SIMPLE | T | range | idx_ab | idx_ab | 8 | NULL | 1003 | Using index condition |
+----+-------------+-------+-------+---------------+--------+---------+------+------+-----------------------+
1 row in set (0.00 sec)
I thought mysql can't use index after range condition.
Create Table: CREATE TABLE `T` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`a` int(11) NOT NULL DEFAULT '0',
`b` int(11) NOT NULL DEFAULT '0',
`c` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `idx_ab` (`a`,`b`)
) ENGINE=InnoDB AUTO_INCREMENT=2048 DEFAULT CHARSET=latin1
I perform this SQL:
explain select * from T force index (idx_ab) where a >= 100 and b = 200;
I guess this sql can use index on a, and the key_len would be 4, but in fact the output key_len is 8, why?
mysql> explain select * from T force index (idx_ab) where a >= 100 and b = 200;
+----+-------------+-------+-------+---------------+--------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+--------+---------+------+------+-----------------------+
| 1 | SIMPLE | T | range | idx_ab | idx_ab | 8 | NULL | 1003 | Using index condition |
+----+-------------+-------+-------+---------------+--------+---------+------+------+-----------------------+
1 row in set (0.00 sec)
I thought mysql can't use index after range condition.