Q1.myisam,自动增长列是索引组合的第二列,自动增长列是按照组合索引的第一列排序后递增?
下面的例子怎么解释?
mysql> create table auto_demo
-> (id smallint not null auto_increment,
-> aid smallint not null,
-> name varchar(10),
-> index(aid,id))engine = myisam;
Query OK, 0 rows affected (0.08 sec)
mysql> insert into auto_demo (aid,name) values(2,'c'),(3,'w'),(1,'s'),(5,'r'),(4,'m');
Query OK, 5 rows affected (0.03 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from auto_demo;
+----+-----+------+
| id | aid | name |
+----+-----+------+
| 1 | 2 | c |
| 1 | 3 | w |
| 1 | 1 | s |
| 1 | 5 | r |
| 1 | 4 | m |
+----+-----+------+
5 rows in set (0.01 sec)
mysql> insert into auto_demo (aid,name) values(2,'c'),(3,'w'),(1,'s'),(5,'r'),(4,'m');
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from auto_demo;
+----+-----+------+
| id | aid | name |
+----+-----+------+
| 1 | 2 | c |
| 1 | 3 | w |
| 1 | 1 | s |
| 1 | 5 | r |
| 1 | 4 | m |
| 2 | 2 | c |
| 2 | 3 | w |
| 2 | 1 | s |
| 2 | 5 | r |
| 2 | 4 | m |
+----+-----+------+
10 rows in set (0.00 sec)
mysql> insert into auto_demo (aid,name) values(2,'c');
Query OK, 1 row affected (0.00 sec)
mysql> select * from auto_demo;
+----+-----+------+
| id | aid | name |
+----+-----+------+
| 1 | 2 | c |
| 1 | 3 | w |
| 1 | 1 | s |
| 1 | 5 | r |
| 1 | 4 | m |
| 2 | 2 | c |
| 2 | 3 | w |
| 2 | 1 | s |
| 2 | 5 | r |
| 2 | 4 | m |
| 3 | 2 | c |
+----+-----+------+
11 rows in set (0.00 sec)
mysql> insert into auto_demo (aid,name) values(2,'c'),(3,'w');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from auto_demo;
+----+-----+------+
| id | aid | name |
+----+-----+------+
| 1 | 2 | c |
| 1 | 3 | w |
| 1 | 1 | s |
| 1 | 5 | r |
| 1 | 4 | m |
| 2 | 2 | c |
| 2 | 3 | w |
| 2 | 1 | s |
| 2 | 5 | r |
| 2 | 4 | m |
| 3 | 2 | c |
| 4 | 2 | c |
| 3 | 3 | w |
+----+-----+------+
13 rows in set (0.00 sec)