Innodb primary key is special in many senses and I was always wondering how well MySQL is integrated with Innodb to take advantage of these special features.
Lets see which things work and which things do not:
I used the following simple table for tests:
PLAIN TEXT SQL:
- CREATE TABLE `innodb` (
- `id` int(10) UNSIGNED NOT NULL,
- `a` int(11) DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `a` (`a`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
"myisam" is same table created with MyISAM storage engine used to show difference:
MySQL Optimizer correctly knows Innodb tables is clustered by primary key in the sense it would not be faster to do external filesort than to do lookups in primary key order:
PLAIN TEXT SQL:
- mysql> EXPLAIN SELECT * FROM …