Created
June 20, 2011 08:33
-
-
Save michaelcontento/1035307 to your computer and use it in GitHub Desktop.
Shows combined primary keys on innodb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table bla( | |
b int, | |
id int not null auto_increment, | |
primary key (b, id), | |
unique key (id) | |
) engine=innodb; | |
insert into bla (b) values (1), (2), (1), (2); | |
/* this looks like "order by id, b" because with small tables mysql doesn't use the primary key */ | |
select * from bla; | |
/* | |
+---+----+ | |
| b | id | | |
+---+----+ | |
| 1 | 1 | | |
| 2 | 2 | | |
| 1 | 3 | | |
| 2 | 4 | | |
+---+----+ | |
*/ | |
/* force primary to see insertion/on disk order */ | |
select * from bla force index (PRIMARY); | |
/* | |
+---+----+ | |
| b | id | | |
+---+----+ | |
| 1 | 1 | | |
| 1 | 3 | | |
| 2 | 2 | | |
| 2 | 4 | | |
+---+----+ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment