Description:
Previously in MySQL 5.1, using the binary operator on a string value in the where clause allowed a case sensitive search whilst still utilizing any available indexes.
Testing in MySQL 5.5, the same statement now causes a full table scan. There's nothing in the documentation to suggest the functionality has changed, so I assuming this must be a bug?
How to repeat:
MySQL 5.1:
show create table testbin\G
*************************** 1. row ***************************
Table: testbin
Create Table: CREATE TABLE `testbin` (
`c1` int(11) NOT NULL AUTO_INCREMENT,
`c2` varchar(12) DEFAULT NULL,
`c3` int(11) DEFAULT NULL,
`c4` int(11) DEFAULT NULL,
PRIMARY KEY (`c1`),
KEY `c2` (`c2`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
INSERT INTO testbin (c2, c3, c4) VALUES ('Adam',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('adaM',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('Ben',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('bEn',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('chris',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('CHRIS',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('dAvE',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('DaVe',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('eric',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('eRiC',1,2);
explain SELECT * FROM testbin WHERE (c2 like binary 'eRiC') LIMIT 1;
+----+-------------+---------+-------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | testbin | range | c2 | c2 | 15 | NULL | 1 | Using where |
+----+-------------+---------+-------+---------------+------+---------+------+------+-------------+
MySQL 5.5:
show create table testbin\G
*************************** 1. row ***************************
Table: testbin
Create Table: CREATE TABLE `testbin` (
`c1` int(11) NOT NULL AUTO_INCREMENT,
`c2` varchar(12) DEFAULT NULL,
`c3` int(11) DEFAULT NULL,
`c4` int(11) DEFAULT NULL,
PRIMARY KEY (`c1`),
KEY `c2` (`c2`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
INSERT INTO testbin (c2, c3, c4) VALUES ('Adam',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('adaM',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('Ben',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('bEn',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('chris',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('CHRIS',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('dAvE',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('DaVe',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('eric',1,2);
INSERT INTO testbin (c2, c3, c4) VALUES ('eRiC',1,2);
explain SELECT * FROM testbin WHERE (c2 like binary 'eRiC') LIMIT 1;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | testbin | ALL | c2 | NULL | NULL | NULL | 10 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+