千家信息网

MySQL8.0倒序索引数据的数据排列方式是什么

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,本篇内容主要讲解"MySQL8.0倒序索引数据的数据排列方式是什么",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"MySQL8.0倒序索引数据的数据排列方式
千家信息网最后更新 2026年10月31日MySQL8.0倒序索引数据的数据排列方式是什么

本篇内容主要讲解"MySQL8.0倒序索引数据的数据排列方式是什么",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"MySQL8.0倒序索引数据的数据排列方式是什么"吧!

一、准备数据

mysql> create table tab_desc    -> (id1 int,    ->  id2 int,    ->  key(id1),    ->  key(id2 desc));Query OK, 0 rows affected (1.29 sec)mysql> select * from tab_desc;+------+------+| id1  | id2  |+------+------+|    1 |    1 ||    2 |    2 ||    3 |    3 ||    4 |    4 ||    5 |    5 ||    6 |    6 ||    7 |    7 |+------+------+

二、通过执行计划证明

这个比较简单我们使用using index type index 来访问索引发现他们确实是相反

mysql> desc select id2 from tab_desc;+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+| id | select_type | table    | partitions | type  | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+|  1 | SIMPLE      | tab_desc | NULL       | index | NULL          | id2  | 5       | NULL |    7 |   100.00 | Using index |+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+1 row in set, 1 warning (0.11 sec)mysql> select id2 from tab_desc;+------+| id2  |+------+|    7 ||    6 ||    5 ||    4 ||    3 ||    2 ||    1 |+------+7 rows in set (0.00 sec)mysql> desc select id1 from tab_desc;+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+| id | select_type | table    | partitions | type  | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+|  1 | SIMPLE      | tab_desc | NULL       | index | NULL          | id1  | 5       | NULL |    7 |   100.00 | Using index |+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+1 row in set, 1 warning (0.00 sec)mysql> select id1 from tab_desc;+------+| id1  |+------+|    1 ||    2 ||    3 ||    4 ||    5 ||    6 ||    7 |+------+7 rows in set (0.00 sec)

三、通过工具证明

执行 ./innblock tab_desc.ibd scan 16得到结果
===INDEX_ID:136level0 total block is (1)block_no:         4,level:   0|*|===INDEX_ID:137level0 total block is (1)block_no:         5,level:   0|*|===INDEX_ID:138level0 total block is (1)block_no:         6,level:   0|*|
通过INNODB_INDEXES可以看到这两个索引对应的ID确实是137/138
|      136 | GEN_CLUST_INDEX |     1059 |    1 |        5 |       4 |     2 |              50 ||      137 | id1             |     1059 |    0 |        2 |       5 |     2 |              50 ||      138 | id2             |     1059 |    0 |        2 |       6 |     2 |              50 |
通过命令 ./innblock tab_desc.ibd 5 16和 ./innblock tab_desc.ibd 6 16可以获得他们的逻辑链表信息如下:
id1==== Block list info ====-----Total used rows:9 used rows list(logic):(1) INFIMUM record offset:99 heapno:0 n_owned 1,delflag:N minflag:0 rectype:2(2) normal record offset:126 heapno:2 n_owned 0,delflag:N minflag:0 rectype:0 (3) normal record offset:142 heapno:3 n_owned 0,delflag:N minflag:0 rectype:0(4) normal record offset:158 heapno:4 n_owned 0,delflag:N minflag:0 rectype:0(5) normal record offset:174 heapno:5 n_owned 0,delflag:N minflag:0 rectype:0(6) normal record offset:190 heapno:6 n_owned 0,delflag:N minflag:0 rectype:0(7) normal record offset:206 heapno:7 n_owned 0,delflag:N minflag:0 rectype:0(8) normal record offset:222 heapno:8 n_owned 0,delflag:N minflag:0 rectype:0 (9) SUPREMUM record offset:112 heapno:1 n_owned 8,delflag:N minflag:0 rectype:3id2==== Block list info ====-----Total used rows:9 used rows list(logic):(1) INFIMUM record offset:99 heapno:0 n_owned 1,delflag:N minflag:0 rectype:2(2) normal record offset:222 heapno:8 n_owned 0,delflag:N minflag:0 rectype:0 (3) normal record offset:206 heapno:7 n_owned 0,delflag:N minflag:0 rectype:0(4) normal record offset:190 heapno:6 n_owned 0,delflag:N minflag:0 rectype:0(5) normal record offset:174 heapno:5 n_owned 0,delflag:N minflag:0 rectype:0(6) normal record offset:158 heapno:4 n_owned 0,delflag:N minflag:0 rectype:0(7) normal record offset:142 heapno:3 n_owned 0,delflag:N minflag:0 rectype:0(8) normal record offset:126 heapno:2 n_owned 0,delflag:N minflag:0 rectype:0  (9) SUPREMUM record offset:112 heapno:1 n_owned 8,delflag:N minflag:0 rectype:3

我们可以看到ID1普通索引逻辑链表信息为:
INFIMUM ->126 ->142 ->158 .....->SUPREMUM
而我们的反向索引逻辑链表信息为:
INFIMUM ->222->206 ->190 .....->SUPREMUM

那么我们分别来解读下数据因为普通索引的数据域排列方式就是:数据+主键 而int代表的是4字节那么
id1的数据就是 (这里用到了一个自己的工具bcview方便观察,当然非要肉眼撸也是也可以的用hexdump):

  • 第一行 126字节后的4字节为:80000001
    current block:00000005--Offset:00126--cnt bytes:04--data is:80000001

  • 第二行 142字节后的4个字节:80000002
    current block:00000005--Offset:00142--cnt bytes:04--data is:80000002

  • 第三行 158字节后的4个字节:80000003
    current block:00000005--Offset:00158--cnt bytes:04--data is:80000003

  • 第四行 174字节后的4个字节:80000004
    current block:00000005--Offset:00174--cnt bytes:04--data is:80000004

后面的我就不查询了可以看到是从小到大的。

接下来我们分解下倒序索引的数据:

  • 第一行 222字节后的4字节为: 80000007
    current block:00000006--Offset:00222--cnt bytes:04--data is:80000007

  • 第二行 206字节后的4个字节: 80000006
    current block:00000006--Offset:00206--cnt bytes:04--data is:80000006

  • 第三行 190字节后的4个字节: 80000005
    current block:00000006--Offset:00190--cnt bytes:04--data is:80000005

  • 第四行 174字节后的4个字节: 80000004
    current block:00000006--Offset:00174--cnt bytes:04--data is:80000004

因此我们得到验证,对于倒序索引而言其数据是在INFIMUM和SUPREMUM降序排列的。

到此,相信大家对"MySQL8.0倒序索引数据的数据排列方式是什么"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

字节 数据 索引 倒序 方式 信息 逻辑 普通 一行 内容 就是 工具 三行 四行 学习 查询 实用 更深 从小到大 接下来 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 智网互联网科技 深圳齐家互联网科技 北京禾田雨橡互联网科技 多迪互联网科技有限公司 互联网科技类展会 海南科技产业互联网平台 中国互联网有什么科技含量 广州恒生互联网科技有限 互联网公司科技股 宝灵互联网科技有限公司 玉溪互联网科技怎么选 允成互联网科技有限公司融资 互联网科技大赛获奖感言 世界互联网领先科技成果获奖 科技赋能视角下互联网保险发展 上海科技产业互联网平台 南通创西澳互联网科技有限公司 互联网安防科技感 兰石爱特工业互联网科技分公司 伍佰万互联网科技是干嘛的 重生之互联网科技帝国 北京互联网络科技有限公司 华中科技大学互联网 江苏南京365互联网科技 互联网企业和科技型企业 语蝶互联网科技有限公司 互联网科技产业特征 深圳艾果互联网通讯科技 伊宁互联网科技做什么的 互联网科技年终奖
0