About year ago Peter wrote about redundant indexes and mentioned sometimes it is good to leave two indexes, even one is first part of another. I'm speaking about BTREE indexes, for example, KEY (A), and KEY (A,B). From SQL point of view KEY(A) is not needed, as for queries like WHERE A=5 the index (A,B) also can be used.
But there is case when for performance it would be good to have both
Let we have the table
PLAIN TEXT SQL:
- CREATE TABLE `userinfo` (
- `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
- `name` varchar(64) NOT NULL DEFAULT '',
- `email` varchar(64) NOT NULL DEFAULT '',
- `password` varchar(64) NOT NULL DEFAULT '',
- `dob` date DEFAULT NULL,
- `address` …