我想了解我正在做的事情的副作用。
我想创建一个随机整数的大型(200万)测试表,所以我运行了以下内容:
CREATE TABLE `block_tests` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `num` int(11)) ENGINE=InnoDB;
INSERT INTO `block_tests` (`num`) VALUES(ROUND(RAND() * 1E6));
-- every repeat of this line doubles number of rows;
INSERT INTO block_tests (num) SELECT ROUND(RAND() * 1E6) FROM block_tests;
INSERT INTO block_tests (num) SELECT ROUND(RAND() * 1E6) FROM block_tests;
INSERT INTO block_tests (num) SELECT ROUND(RAND() * 1E6) FROM block_tests;
-- etc
表格大小每次迭代都会正确加倍。有些奇怪的是已经添加的行的ID:
mysql> select * from block_tests limit 17;
+----+--------+
| id | num |
+----+--------+
| 1 | 814789 |
| 2 | 84489 |
| 3 | 978078 |
| 4 | 636924 |
| 6 | 250384 |
| 7 | 341151 |
| 8 | 954604 |
| 9 | 749565 |
| 13 | 884014 |
| 14 | 171375 |
| 15 | 204833 |
| 16 | 510040 |
| 17 | 935701 |
| 18 | 148383 |
| 19 | 934814 |
| 20 | 228923 |
| 28 | 340170 |
+----+--------+
17 rows in set (0.00 sec)
出于某种原因,ids中有跳过。跳过有一种模式:
4 skip to 6 - skip 1
9 skip to 13 - skip 4
20 skip to 28 - skip 8
43 skip to 59 - skip 16
发生了什么事?