Skip to content

Instantly share code, notes, and snippets.

@michaelcontento
Created June 20, 2011 08:33
Show Gist options
  • Save michaelcontento/1035307 to your computer and use it in GitHub Desktop.
Save michaelcontento/1035307 to your computer and use it in GitHub Desktop.
Shows combined primary keys on innodb
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