创建测试表
create table t (
id int(11) not null,
b int(11) default null,
c int(11) default null,
primary key (id),
key b (b)
);
insert into t (id, b, c) values ('1', '1', '0');
insert into t (id, b, c) values ('3', '6', '1');
insert into t (id, b, c) values ('5', '4', '2');
insert into t (id, b, c) values ('7', '8', '3');
insert into t (id, b, c) values ('8', '10', '4');
此时索引 (b) 的结构如图所示
执行 SQL1 时会将数据插入至叶节点 5 与叶节点 3 之间
insert into t (id, b, c) values ('6', '4', '0'); -- SQL1
执行 SQL2 时会将数据插入至叶节点 1 与叶节点 5 之间
insert into t (id, b, c) values ('4', '4', '0'); -- SQL2
为什么执行 SQL1 时不会将数据插入至节点 1 至节点 5 之间呢 ? 插入数据时确保索引 (b) 的顺序仍为 1、4、4、6、8、10 不就可以了吗 ? 为什么还会限制聚簇索引 ID 的插入位置 ? 请问这是遵循什么规则呢 ?