56,678
社区成员
发帖
与我相关
我的任务
分享
mysql> create table tx (
-> id int primary key,
-> col int
-> )engine=myisam;
Query OK, 0 rows affected (0.05 sec)
mysql> insert into tx values
-> (1 ,1),
-> (2 ,1),
-> (3 ,1),
-> (7 ,2),
-> (6 ,2),
-> (5 ,2),
-> (4 ,2),
-> (8 ,3),
-> (11 ,3),
-> (10 ,3),
-> (9 ,3);
Query OK, 11 rows affected (0.00 sec)
Records: 11 Duplicates: 0 Warnings:
-- 物理顺序
mysql> select * from tx;
+----+------+
| id | col |
+----+------+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 7 | 2 |
| 6 | 2 |
| 5 | 2 |
| 4 | 2 |
| 8 | 3 |
| 11 | 3 |
| 10 | 3 |
| 9 | 3 |
+----+------+
11 rows in set (0.00 sec)
-- 物理顺序
mysql> select id from tx where col=3;
+----+
| id |
+----+
| 8 |
| 11 |
| 10 |
| 9 |
+----+
4 rows in set (0.00 sec)
-- 主键顺序
mysql> select id from tx;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
| 11 |
+----+
11 rows in set (0.00 sec)
mysql> create index tx_col on tx(col,id);
Query OK, 11 rows affected (0.08 sec)
Records: 11 Duplicates: 0 Warnings: 0
-- 加索引后为索引顺序
mysql> select * from tx where col=3;
+----+------+
| id | col |
+----+------+
| 8 | 3 |
| 9 | 3 |
| 10 | 3 |
| 11 | 3 |
+----+------+
4 rows in set (0.02 sec)
mysql>