MySQL Forums
Forum List  »  InnoDB

the where condition field after ">=" can use index? is this true?
Posted by: Bing Wu
Date: August 13, 2015 09:49PM

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.

Options: ReplyQuote


Subject
Views
Written By
Posted
the where condition field after ">=" can use index? is this true?
1558
August 13, 2015 09:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.